Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I made a copy of a body and now I want to move it, but I get an error:
Failed:
Traceback (most recent call last):
File "...copyAndMove.py", line 46, in run
moveFeats.add(moveFeatureInput)
File ".../Library/Application Support/Autodesk/webdeploy/production/cdedd4b05efae2d277df7be3d315d4ccce03a01d/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/fusion.py", line 21834, in add
return _fusion.MoveFeatures_add(self, input)
RuntimeError: 2 : InternalValidationError : Utils::getObjectPath(entity.get(), objPath, nullptr, compPath)
Here is the code:
import adsk.core, adsk.fusion, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
if not design:
ui.messageBox('No active Fusion design', 'No Design')
return
# Get the root component of the active design.
rootComp = design.rootComponent
features = rootComp.features
# Get the first sub component
occs = rootComp.occurrences
subComp1 = occs.item(0).component
# Get the first body in sub component 1
baseBody = subComp1.bRepBodies.item(0)
baseBody.name = "Stick_1"
# Copy/paste bodies
subComp1.features.copyPasteBodies.add(baseBody)
# Rename Body
baseBodyCopy = subComp1.bRepBodies.item(1)
baseBodyCopy.name = "Stick_2"
# Create a collection of entities for move
bodies = adsk.core.ObjectCollection.create()
bodies.add(baseBodyCopy)
# Create a transform to do move
vector = adsk.core.Vector3D.create(5.0, 10.0, 6.0)
transform = adsk.core.Matrix3D.create()
transform.translation = vector
# Create a move feature
moveFeats = features.moveFeatures
moveFeatureInput = moveFeats.createInput(bodies, transform)
moveFeats.add(moveFeatureInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.