Demonstrates creating a new sheet metal rip feature.
Before running: Open or create a sheet metal design in the DESIGN workspace, unless the script builds its own sheet metal body.
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
ripFeatures = features.ripFeatures
# get geometry from body to create a rip
brepBodies = rootComp.bRepBodies
body = brepBodies.item(0)
edges = body.edges
vertices = body.vertices
# create a between points rip
gapDistance = adsk.core.ValueInput.createByReal(1.23)
offset1 = adsk.core.ValueInput.createByReal(2.34)
ripFeatureInput = ripFeatures.createRipFeatureInput()
edge = edges.item(40)
vertex = vertices.item(9)
ripFeatureInput.setBetweenPoints(edge, vertex, gapDistance, offset1)
ripFeature = ripFeatures.add(ripFeatureInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
#include <Core/Application/Application.h>
#include <Core/Application/Document.h>
#include <Core/Application/ValueInput.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/BRep/BRepFace.h>
#include <Fusion/BRep/BRepFaces.h>
#include <Fusion/BRep/BRepVertex.h>
#include <Fusion/BRep/BRepVertices.h>
#include <Fusion/Features/Features.h>
#include <Fusion/SheetMetal/RipFeature.h>
#include <Fusion/SheetMetal/RipFeatureInput.h>
#include <Fusion/SheetMetal/RipFeatures.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;
// Get rip features
Ptr<Features> features = rootComp->features();
if (!features)
return false;
Ptr<RipFeatures> ripFeatures = features->ripFeatures();
if (!ripFeatures)
return false;
Ptr<BRepBodies> bodies = rootComp->bRepBodies();
Ptr<BRepBody> body = bodies->item(0);
Ptr<BRepEdges> edges = body->edges();
Ptr<BRepVertices> vertices = body->vertices();
// Create a between points rip
Ptr<ValueInput> gapDistance = ValueInput::createByReal(1.23);
Ptr<ValueInput> offset1 = ValueInput::createByReal(2.34);
Ptr<RipFeatureInput> ripFeatureInput = ripFeatures->createRipFeatureInput();
Ptr<BRepEdge> edge = edges->item(40);
Ptr<BRepVertex> vertex = vertices->item(9);
// Create the feature
Ptr<RipFeature> ripFeature = ripFeatures->add(ripFeatureInput);
return true;
}
/** * Rip Feature Sample * Demonstrates creating a new sheet metal rip feature. * * Requires APISampleRipFeatureCreation.f3d to be open. Edge and vertex 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 rip features const features = rootComp.features; if (!features) throw Error("No features."); const ripFeatures = features.ripFeatures; if (!ripFeatures) throw Error("No rip features."); // Get geometry from body to create a rip const brepBodies = rootComp.bRepBodies; const body = brepBodies.item(0); if (!body) throw Error("No body."); const edges = body.edges; const vertices = body.vertices; // Create a between points rip const gapDistance = adsk.core.ValueInput.createByReal(1.23); const offset1 = adsk.core.ValueInput.createByReal(2.34); const ripFeatureInput = ripFeatures.createRipFeatureInput(); const edge = edges.item(40); const vertex = vertices.item(9); ripFeatureInput.setBetweenPoints(edge, vertex, gapDistance, offset1); // Create the feature ripFeatures.add(ripFeatureInput); } run();