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;
}