Demonstrates creating a sheet metal unfold feature, including selecting bend faces via BRepBody.getBendFaces and using UnfoldFeatures / UnfoldFeatureInput.
Before running: Open a sheet metal design that already contains a valid unfold target (for example the test model Neutron/Test/APITest/APISampleSheetMetalUnFold.f3d, or your own sheet metal part with bends). Run in the DESIGN workspace. The automation test harness opens that file automatically; when running manually, open the design first.
"""Unfold Feature API sample — creates an unfold feature on a sheet metal body.
Requires a design with a sheet metal body that has at least one bend.
Sample data: Neutron/Test/APITest/APISampleSheetMetalUnFold.f3d
"""
import traceback
import adsk.core
import adsk.fusion
app = adsk.core.Application.get()
STATIONARY_FACE_IDX = 34
def run(_context):
"""Documentation sample: Create an unfold feature on a sheet metal body."""
try:
design = adsk.fusion.Design.cast(app.activeProduct)
root_comp = design.rootComponent
Get the first body — assumes it's sheet metal with bend faces
body = root_comp.bRepBodies.item(0)
if body is None or not body.isSheetMetal:
app.log("UnfoldSample: No sheet metal body found.")
return
Retrieve bend faces from the sheet metal body
found, inner_bends, outer_bends = body.getBendFaces()
if not found or not inner_bends or not outer_bends:
app.log("UnfoldSample: No bend faces on sheet metal body.")
return
Select the stationary face — the face that will not move during unfold
stationary_face = body.faces.item(STATIONARY_FACE_IDX)
if stationary_face is None:
app.log(f"UnfoldSample: No face at index {STATIONARY_FACE_IDX}.")
return
Create an unfold feature that unfolds specific bend faces
unfold_features = root_comp.features.unfoldFeatures
inp = unfold_features.createInput(stationary_face)
inp.isUnfoldAllBends = False
Collect all bend faces to unfold
all_bends = []
for inner, outer in zip(inner_bends, outer_bends):
all_bends.append(inner)
all_bends.append(outer)
inp.bendFaces = all_bends
Add the unfold feature
feature = unfold_features.add(inp)
app.log(f"UnfoldSample completed: unfold '{feature.name}'.")
except Exception:
app.log(f"UnfoldSample failed:\n{traceback.format_exc()}")
// Unfold Feature API sample — creates an unfold feature on a sheet metal body. // // Requires a design with a sheet metal body that has at least one bend. // Sample data: Neutron/Test/APITest/APISampleSheetMetalUnFold.f3d #include <Core/CoreAll.h> #include <Fusion/FusionAll.h> #include <vector> using namespace adsk::core; using namespace adsk::fusion; namespace { Ptr<Application> app; const size_t STATIONARY_FACE_IDX = 34; #define CHECK(expr) \ if (!(expr)) \ { \ app->log("FAIL: " #expr); \ return false; \ } #define CHECK_PTR(ptr) CHECK((ptr) != nullptr) } // namespace extern "C" XI_EXPORT bool run(const char* context) { (void)context; app = Application::get(); if (!app) return false; auto product = app->activeProduct(); CHECK_PTR(product); auto design = product->cast<Design>(); CHECK_PTR(design); auto rootComp = design->rootComponent(); CHECK_PTR(rootComp); auto bodies = rootComp->bRepBodies(); CHECK_PTR(bodies); auto body = bodies->item(0); CHECK_PTR(body); CHECK(body->isSheetMetal()); std::vector<Ptr<BRepFace>> innerBends; std::vector<Ptr<BRepFace>> outerBends; if (!body->getBendFaces(innerBends, outerBends)) { app->log("UnfoldSample skipped: no bend faces on sheet metal body."); return true; } auto faces = body->faces(); CHECK_PTR(faces); auto stationaryFace = faces->item(STATIONARY_FACE_IDX); CHECK_PTR(stationaryFace); auto features = rootComp->features(); CHECK_PTR(features); auto unfoldFeatures = features->unfoldFeatures(); CHECK_PTR(unfoldFeatures); auto inp = unfoldFeatures->createInput(stationaryFace); CHECK_PTR(inp); CHECK(inp->isUnfoldAllBends(false)); std::vector<Ptr<BRepFace>> allBends; allBends.reserve(innerBends.size() + outerBends.size()); for (size_t i = 0; i < innerBends.size(); ++i) { allBends.push_back(innerBends[i]); allBends.push_back(outerBends[i]); } CHECK(inp->bendFaces(allBends)); auto feature = unfoldFeatures->add(inp); CHECK_PTR(feature); app->log("UnfoldSample completed: unfold '" + feature->name() + "'."); return true; }