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: 

How to move bRepBodies from the root component to new component?

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
1242 Views, 4 Replies

How to move bRepBodies from the root component to new component?

I can create a new component and get/iterate over the bodies in the root component, but there isn't any obvious way to move them to another component.  How can I move a body from the root component to a new component? 

I have tried:

Looking in the API reference for an api call that looks like it corresponds to "create components from bodies", or moving bodies between components

Looking at the source of class BRepBodies(Base) - there is no .add or similar method

 

A list/chart mapping all user interface actions to API calls would be very helpful.

4 REPLIES 4
Message 2 of 5
ekinsb
in reply to: Anonymous

It's hard to find what's not there. Smiley Happy

 

The ability to move a body is not yet supported by the API.  Sorry about that.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 5
Anonymous
in reply to: ekinsb

Thanks for the quick reply.  I'm trying to modify the spur gear example to make a series of gears, each in their own component, but ran in to issues with adding the circular pattern features when using a new component.  I get the error below.  The script I am using is attached.  I would expect the operations to work the same whether or not the root component is used, but I may be missing something.

---------------------------
Fusion 360
---------------------------
Failed:
Traceback (most recent call last):
  File "<string>", line 62, in notify
  File "<string>", line 291, in buildGear
  File "C:/Users/_/AppData/Local/Autodesk/webdeploy/production/e632192e503167f8b2d132ee3b9551eb4400409e/Api/Python/packages\adsk\fusion.py", line 3209, in add
    return _fusion.CircularPatternFeatures_add(self, *args)
RuntimeError: 2 : InternalValidationError : Utils::getObjectPath(inputObject.get(), objPath)

---------------------------
Ok   
---------------------------

Message 4 of 5
Anonymous
in reply to: Anonymous

I got the message "The contents of the attachment doesn't match its file type." when trying to attach the script with just a .py extension so I named it a .py.txt.

Message 5 of 5
ekinsb
in reply to: Anonymous

There is a bug in when using the API to create a circular pattern feature within a component besides the root component.  It has been fixed for the next release but the problem exists in the released version.  There is a way to work around the problem in the current release, which is to create the pattern in the context of the root component.  This is actually how everything is done in Fusion when using it interactively.  Below is a small Python script that demonstrates the workaround.  The key to this is understand the "context" of the geometry and where you're working.  If I create the pattern in the context of the root, the goemetry also needs to exist in the root context.  In the program below, when it first gets the cylindrical face, which is used as the pattern axis, and the body that will be patterned, they're in the context of the sub component.  If there were two instances of this component then there would be two cylinders and two bodies from the context of the assembly (the root component) and to create the pattern you need to uniquely specify one of them.  This is done using the createForAssemblyContext method.  This creates objects that represent the face and body in the context of the assembly.  This new object contains the path of which occurrence the geometry is with respect to.  These objects are also referred to as "proxy" objects because they represent an object.

 

import adsk.core, adsk.fusion, traceback

def main():
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = app.activeProduct

        rootComp = design.rootComponent

        newOcc = design.rootComponent.occurrences.addNewComponent(adsk.core.Matrix3D.create()) 
        comp = newOcc.component

        baseSketch = comp.sketches.add(comp.xYConstructionPlane)
        baseSketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 2) 
        baseSketch.sketchCurves.sketchLines.addCenterPointRectangle(adsk.core.Point3D.create(-0,3.5,0), adsk.core.Point3D.create(1,4.5,0)) 

        if baseSketch.profiles.item(0).profileLoops.item(0).profileCurves.count == 1:
            circleProfile = baseSketch.profiles.item(0)
            rectangleProfile = baseSketch.profiles.item(1)
        else:
            circleProfile = baseSketch.profiles.item(1)
            rectangleProfile = baseSketch.profiles.item(0)

        extrudes = comp.features.extrudeFeatures
        extInput = extrudes.createInput(circleProfile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        distance = adsk.core.ValueInput.createByReal(10)
        extInput.setDistanceExtent(False, distance)
        cylinderExtrude = extrudes.add(extInput)

        extInput = extrudes.createInput(rectangleProfile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        distance = adsk.core.ValueInput.createByReal(5)
        extInput.setDistanceExtent(False, distance)
        rectangleExtrude = extrudes.add(extInput)

        cylFace = cylinderExtrude.sideFaces.item(0)
        cylFace = cylFace.createForAssemblyContext(newOcc)
        boxBody = rectangleExtrude.faces.item(0).body
        boxBody = boxBody.createForAssemblyContext(newOcc)

        circularPatterns = rootComp.features.circularPatternFeatures
        entities = adsk.core.ObjectCollection.create()
        entities.add(boxBody)
        patternInput = circularPatterns.createInput(entities, cylFace)
        numInstances = adsk.core.ValueInput.createByString("6")
        patternInput.quantity = numInstances
        pattern = circularPatterns.add(patternInput) 
    except Exception:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

main()

 


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