Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Participant Bodies after 01/2017 update

1 REPLY 1
Reply
Message 1 of 2
Anonymous
252 Views, 1 Reply

Participant Bodies after 01/2017 update

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.

 

1 REPLY 1
Message 2 of 2
ekinsb
in reply to: Anonymous

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.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report