- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have modified a sample that goes through all bodies and moves them, first all bodies in the rootComponent and then all bodies in the other occurences and compnents. When I apply the MoveFeature in the rootComponent it works without problems but when I apply the MoveFeature in the components I get this error:
Failed:
Traceback (most recent call last):
File "C:/Users/Admin/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/NewScript6/NewScript6.py", line 109, in run
moveFeats.add(moveFeatureInput)
File "C:\Users/Admin/AppData/Local/Autodesk/webdeploy/production/540c9578410bc15ff261605667cfced82aa9ac6d/Api/Python/packages\adsk\fusion.py", line 27957, in add
return _fusion.MoveFeatures_add(self, input)
RuntimeError: 3 : object is not in the assembly context of this component
Can someone please explain to me why and what I should do differently?
I have the feeling that the movefeature only works with bodies in the rootComponent but I am not sure. Does anyone know how to address a body in a component to move it?
Also, how can I use the MoveFeaturePointToPosition to move a body?
I am grateful for any helpful hints and especially for a small sample code.
Greetings 🙂
@BrianEkins I have often come across your posts and have also seen and read your course on
Customizing Fusion 360 Using its Programming Interface at Autodesk University but apparently didn't understand something 😄 If you would have the time and kindness to help me with my problem I would be very honoured!
try:
app = adsk.core.Application.get()
ui = app.userInterface
ui.messageBox(str(bodiesDict))
design = app.activeProduct
if not design:
ui.messageBox('No active Fusion design', 'No Design')
return
# Get the root component of the active design.
rootComp = design.rootComponent
# Iterate over any bodies in the root component.
for j in range(0, rootComp.bRepBodies.count):
body = rootComp.bRepBodies.item(j)
bodies = adsk.core.ObjectCollection.create()
bodies.add(body)
features = rootComp.features
vector = adsk.core.Vector3D.create(50,50, 0)
transform = adsk.core.Matrix3D.create()
transform.translation = vector
# Create a move feature
moveFeats = features.moveFeatures
moveFeatureInput = moveFeats.createInput(bodies, transform)
moveFeats.add(moveFeatureInput)
# here starts the second part-----------------------------------
# Iterate through all of the occurrences in the assembly.
for i in range(0, rootComp.allOccurrences.count):
occ = rootComp.allOccurrences.item(i)
# Get the associated component.
comp = occ.component
# Iterate over all of the bodies within the component.
for j in range(0, comp.bRepBodies.count):
body = comp.bRepBodies.item(j)
thisBody = body.name
features = rootComp.features
vector = adsk.core.Vector3D.create(50,50, 0)
transform = adsk.core.Matrix3D.create()
transform.translation = vector
bodies = adsk.core.ObjectCollection.create()
bodies.add(body)
# Create a move feature
moveFeats = features.moveFeatures
moveFeatureInput = moveFeats.createInput(bodies, transform)
moveFeats.add(moveFeatureInput) # <--- this line fails, i think because bodies in the line above is a adsk.core.ObjectCollection.create() filled with body = comp.bRepBodies.item(j) and not like in the rootComponent body = rootComp.bRepBodies.item(j).
Solved! Go to Solution.