Join By Bend Sample

Description

Demonstrates creating a new sheet metal join by bend feature.

Before running: Open or create a sheet metal design in the DESIGN workspace, unless the script builds its own sheet metal body.

Code Samples

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        # get active design
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        # get the root component
        rootComp = design.rootComponent

        # get features
        features = rootComp.features
        joinByBendFeatures = features.joinByBendFeatures

        # get geometry from bodies to create a join by bend feature.
        # body is the existing joined sheet metal body; body2 is the unconnected flange.
        brepBodies = rootComp.bRepBodies
        body  = brepBodies.item(0)
        body2 = brepBodies.item(1)

        # pick the open edge from each body that will be joined by the bend
        edgeOne = body.edges.item(0)
        edgeTwo = body2.edges.item(4)

        # create the input — isUseSheetMetalRuleBendRadius defaults to True,
        # so the active sheet metal rule controls the bend radius
        jbbInput = joinByBendFeatures.createInput(edgeOne, edgeTwo)

        # add the feature; bendRadius returns None when the rule controls it
        jbbFeature = joinByBendFeatures.add(jbbInput)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
#include <Core/Application/Application.h>
#include <Core/Application/Document.h>
#include <Core/UserInterface/UserInterface.h>

#include <Fusion/Components/Component.h>
#include <Fusion/BRep/BRepBodies.h>
#include <Fusion/BRep/BRepBody.h>
#include <Fusion/BRep/BRepEdge.h>
#include <Fusion/BRep/BRepEdges.h>
#include <Fusion/Features/Features.h>
#include <Fusion/SheetMetal/JoinByBendFeature.h>
#include <Fusion/SheetMetal/JoinByBendFeatureInput.h>
#include <Fusion/SheetMetal/JoinByBendFeatures.h>
#include <Fusion/Fusion/Design.h>

using namespace adsk::core;
using namespace adsk::fusion;

Ptr<UserInterface> ui;

extern "C" XI_EXPORT bool run(const char* context)
{
    Ptr<Application> app = Application::get();
    if (!app)
        return false;

    ui = app->userInterface();
    if (!ui)
        return false;


    // Get active design
    Ptr<Product> product = app->activeProduct();
    if (!product)
        return false;

    Ptr<Design> design = product;
    if (!design)
        return false;

    // Get root component in this design
    Ptr<Component> rootComp = design->rootComponent();
    if (!rootComp)
        return false;

    Ptr<Features> features = rootComp->features();
    if (!features)
        return false;

    // get join by bend features collection
    Ptr<JoinByBendFeatures> joinByBendFeatures = features->joinByBendFeatures();
    if (!joinByBendFeatures)
        return false;

    Ptr<BRepBodies> bodies = rootComp->bRepBodies();

    // body is the existing joined sheet metal body; body2 is the unconnected flange.
    Ptr<BRepBody> body = bodies->item(0);

    Ptr<BRepBody> body2 = bodies->item(1);

    Ptr<BRepEdges> edges = body->edges();

    Ptr<BRepEdges> edges2 = body2->edges();

    // pick the open edge from each body that will be joined by the bend
    Ptr<BRepEdge> edgeOne = edges->item(0);

    Ptr<BRepEdge> edgeTwo = edges2->item(4);

    // create the input — isUseSheetMetalRuleBendRadius defaults to true,
    // so the active sheet metal rule controls the bend radius
    Ptr<JoinByBendFeatureInput> jbbInput = joinByBendFeatures->createInput(edgeOne, edgeTwo);

    // add the feature; bendRadius() returns null because the rule controls it
    Ptr<JoinByBendFeature> jbbFeature = joinByBendFeatures->add(jbbInput);


    return true;
}
/**
 * Join By Bend Feature Sample
 * Demonstrates joining two sheet metal bodies together with a bend.
 *
 * Requires APISampleSheetMetalJoinByBend.f3d to be open. Body and edge
 * indices are specific to that document.
 */

import { adsk } from '@adsk/fusion';

function run() {

  // Get the Fusion API's application object
  const app = adsk.core.Application.get();
  if (!app) throw Error("No adsk.core.Application.");

  // Get active design (the document is opened by the test harness)
  const product = app.activeProduct;
  if (!product) throw Error("No active product.");

  const design = product as adsk.fusion.Design;
  if (!design) throw Error("No active design.");

  // Get the root component
  const rootComp = design.rootComponent;
  if (!rootComp) throw Error("No root component.");

  // Get join by bend features
  const features = rootComp.features;
  if (!features) throw Error("No features.");
  const joinByBendFeatures = features.joinByBendFeatures;
  if (!joinByBendFeatures) throw Error("No join by bend features.");

  // Get geometry from bodies to create a join by bend feature.
  // body is the existing joined sheet metal body; body2 is the unconnected flange.
  const brepBodies = rootComp.bRepBodies;
  const body = brepBodies.item(0);
  const body2 = brepBodies.item(1);

  // Pick the open edge from each body that will be joined by the bend
  const edgeOne = body.edges.item(0);
  const edgeTwo = body2.edges.item(4);

  // Create the input - isUseSheetMetalRuleBendRadius defaults to true,
  // so the active sheet metal rule controls the bend radius
  const jbbInput = joinByBendFeatures.createInput(edgeOne, edgeTwo);

  // Add the feature; bendRadius returns null when the rule controls it
  joinByBendFeatures.add(jbbInput);
}

run();