Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello I am making a script to move a component from a selected point to another selected point but I am getting an error at the end. It works if I move a body but not a component. Here is the code below:
# Get a body by having the user select one.
body: adsk.fusion.Components = ui.selectEntity('Select a component.', 'Occurrences').entity
# Have an entity selected that represents a point.
# This can be a Vertex, Sketch Point, or Construction Point.
pointEnt = ui.selectEntity('Select a point entity', 'ConstructionPoints, SketchPoints, Vertices').entity
# Get the XYZ position of the point in model space.
pnt1: adsk.core.Point3D = None
if pointEnt.objectType == adsk.fusion.SketchPoint.classType():
skPoint: adsk.fusion.SketchPoint = pointEnt
pnt1 = skPoint.worldGeometry
else:
pnt1 = pointEnt.geometry
# Select a Second Point
pointEnt2 = ui.selectEntity('Select a point entity', 'ConstructionPoints, SketchPoints, Vertices').entity
# Get the XYZ position of the point in model space.
pnt2: adsk.core.Point3D = None
if pointEnt2.objectType == adsk.fusion.SketchPoint.classType():
skPoint2: adsk.fusion.SketchPoint = pointEnt2
pnt2 = skPoint2.worldGeometry
else:
pnt2 = pointEnt2.geometry
# Create a matrix that defines the translation from point 1 to point
trans: adsk.core.Matrix3D = adsk.core.Matrix3D.create()
trans.translation = pnt1.vectorTo(pnt2)
# Create a move feature using the matrix.
moveFeatures = design.rootComponent.features.moveFeatures
inputEnts = adsk.core.ObjectCollection.create()
inputEnts.add(body)
moveInput = moveFeatures.createInput(inputEnts, trans)
moveFeatures.add(moveInput)
Solved! Go to Solution.