I'm trying to use the new participantbodies feature from the update on an Join Extrusion, but it throws a weird error.
Here is my code.
def buildBolt( parentComp, diameter, length, withHead = False): sketches = parentComp.sketches xZPlane = parentComp.xZConstructionPlane center = parentComp.originConstructionPoint.geometry extrudes = parentComp.features.extrudeFeatures bodies = [] if withHead: sketch = sketches.add(xZPlane) sketch.sketchCurves.sketchCircles.addByCenterRadius(center, (diameter+.3)/2) prof = sketch.profiles[0] extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) distanceExtent = adsk.fusion.DistanceExtentDefinition.create(adsk.core.ValueInput.createByReal(.2)) extInput.setOneSideExtent(distanceExtent, adsk.fusion.ExtentDirections.NegativeExtentDirection) extrude = extrudes.add(extInput) for body in extrude.bodies: Globals.ui.messageBox(str(body.classType())) bodies.append(bodies) try: bodySketch = sketches.add(xZPlane) bodySketch.sketchCurves.sketchCircles.addByCenterRadius(center, diameter/2) prof = bodySketch.profiles[0] extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.JoinFeatureOperation) distanceExtent = adsk.fusion.DistanceExtentDefinition.create(adsk.core.ValueInput.createByReal(length)) extInput.setOneSideExtent(distanceExtent, adsk.fusion.ExtentDirections.PositiveExtentDirection) extInput.participantBodies = bodies extrude = extrudes.add(extInput) except: Globals.ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
The resulting error is thrown at "extInput.particpantBodies = bodies"
TypeError: in method 'extrudeFeatureInput__set_participantBodies', argument 2 of type 'std::vector<adsk::core::Ptr<adsk::fusion::BRepBody >?, std::allocator<adsk::core::Ptr< adsk::fusion::BRepBody > > > const &'
Since this feature is so new could this be a bug? I can work around it, but I would really like to know what I'm doing wrong.
Hopefully you found the error already but if not, look a little closer at the loop where you're adding the bodies to the array. You have:
for body in extrude.bodies: bodies.append(bodies)
Notice what you're adding to the list. it's the list "bodies" instead of the variable "body" which is the body you want.
Don't feel bad. I don't know how many times I've made similar simple mistakes.