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.
It's hard to find what's not there.
The ability to move a body is not yet supported by the API. Sorry about that.
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
---------------------------
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.
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()