Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In a script want to use a temporary BRepBody for cutting. This works fine if the temporary body was created with something like createCylinderOrCone but fails when the body is created with the copy function of TemporaryBRepManager. For some reason the base feature adding the temporary object to the document contains no bodies in case of using the copy, Although the copied body shows up in the document afterwards.
The following script shows the problem. If I comment in line 37, the script breaks.
import adsk.core, adsk.fusion, adsk.cam, traceback
import math
def createCylinder(x, y, r, h):
app = adsk.core.Application.get()
des = adsk.fusion.Design.cast(app.activeProduct)
root = des.rootComponent
sk = root.sketches.add(root.xYConstructionPlane)
circs = sk.sketchCurves.sketchCircles
circs.addByCenterRadius(adsk.core.Point3D.create(x,y,0), r)
prof = sk.profiles.item(0)
ext = root.features.extrudeFeatures.addSimple(
prof, adsk.core.ValueInput.createByReal(h),
adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
return ext.bodies.item(0)
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
des = adsk.fusion.Design.cast(app.activeProduct)
root = des.rootComponent
c1 = createCylinder(0, 0, 2, 5)
c2 = createCylinder(1, 1, 2, 3)
c2.isLightBulbOn = False
tempBRep = adsk.fusion.TemporaryBRepManager.get()
# Works
tempToolBody = tempBRep.createCylinderOrCone(
adsk.core.Point3D.create(1, 1, 0), 2,
adsk.core.Point3D.create(1, 1, 3), 2)
# Fails with "RuntimeError: 3 : Bad index parameter" in the line below that uses baseFeat.bodies.item(0)
# tempToolBody = tempBRep.copy(c2)
baseFeat = root.features.baseFeatures.add()
baseFeat.startEdit()
toolBody = root.bRepBodies.add(tempToolBody, baseFeat)
baseFeat.finishEdit()
toolBodies = adsk.core.ObjectCollection.create()
toolBodies.add(baseFeat.bodies.item(0))
combineInput = root.features.combineFeatures.createInput(c1, toolBodies)
combineInput.operation = adsk.fusion.FeatureOperations.CutFeatureOperation
root.features.combineFeatures.add(combineInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.