Message 1 of 1
extrudeFeatures.add should return null if the creation failed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
A simple code that obviously failed because the profile is "outside" the B-Rep body to cut:
#Author- #Description- import adsk.core, adsk.fusion, adsk.cam, traceback def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface design = adsk.fusion.Design.cast(app.activeProduct) rootComponent = design.rootComponent sketches = rootComponent.sketches sketchesPlane = rootComponent.xYConstructionPlane sketch1 = sketches.add(sketchesPlane) sketch1.name = 'Square' lines = sketch1.sketchCurves.sketchLines; lines.addTwoPointRectangle(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(2, 2, 0)) sketch2 = sketches.add(sketchesPlane) sketch2.name = 'Hole' circles = sketch2.sketchCurves.sketchCircles circles.addByCenterRadius(adsk.core.Point3D.create(3, 1, 0), 0.5) extrudes = rootComponent.features.extrudeFeatures extrudeInput1 = extrudes.createInput(sketch1.profiles.item(0), adsk.fusion.FeatureOperations.NewBodyFeatureOperation) distance = adsk.core.ValueInput.createByReal(2.0) extrudeInput1.setSymmetricExtent(distance, True) extrude1 = extrudes.add(extrudeInput1) extrudeInput2 = extrudes.createInput(sketch2.profiles.item(0), adsk.fusion.FeatureOperations.CutFeatureOperation) extrudeInput2.participantBodies = [extrude1.bodies.item(0)] distance = adsk.core.ValueInput.createByReal(1.0) extrudeInput2.setSymmetricExtent(distance, True) extrude2 = extrudes.add(extrudeInput2) if extrude2 is None: ui.messageBox('Extrude Failed') sketch1.isVisible = True sketch2.isVisible = True except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
The documentation says that extrudes.add should return null but in fact, it returns an error: No target body found to cut or intersect!
More, the code runs with success when the line with participantBodies is uncommented.
The only workaround to the error message I found is:
try: extrude = extrudes.add(extrudeInput) except: ui.messageBox('Extrude Failed')
According to the documentation, in both cases it should be:
extrude = extrudes.add(extrudeInput) if extrude is None: ui.messageBox('Extrude Failed')
Thanks
Jérôme Briot, Freelance engineer - Mechanical design and prototyping
3D Print Plus / Pro | IDF Import | GitHub To Fusion 360 | Tube Bending Data Exchanger | Slice Data Export
Memory Used | Basic Calculator | Check Computer Specifications | Import spline from any CSV file