Message 1 of 3

Not applicable
03-25-2016
09:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to move an object by multiple angles, around all 3 axes (the design ones, not the axes of an other component). I have the code below but I get weird results because it keeps turning around the axes of the component not the RootComponent. This feature exists in the UI but is it available from the python API?
def rotateBody(design, ui, x,y, z, body, parentComponent): occurenceOfComp = design.rootComponent.allOccurrencesByComponent(parentComponent).item(0) actualOrigin = parentComponent.originConstructionPoint.createForAssemblyContext(occurenceOfComp).geometry features = parentComponent.features moveBody = body if x<0.000009 and x>-0.000009: moveBody = body else: ui.messageBox("Moving X") entities1 = adsk.core.ObjectCollection.create() entities1.add(moveBody) transform = adsk.core.Matrix3D.create() transform.setToRotation(x,design.rootComponent.xConstructionAxis.geometry.getData()[2], actualOrigin) #Create a move feature moveFeats = features.moveFeatures moveFeatureInput = moveFeats.createInput(entities1, transform) move =moveFeats.add(moveFeatureInput) moveBody = move.bodies.item(0) if design.snapshots.hasPendingSnapshot: design.snapshots.add() if y<0.000009 and y>-0.000009: moveBody = body else: ui.messageBox("Moving Y") entities1 = adsk.core.ObjectCollection.create() entities1.add(moveBody) transform = adsk.core.Matrix3D.create() transform.setToRotation(y,design.rootComponent.yConstructionAxis.geometry.getData()[2], actualOrigin) #Create a move feature moveFeats = features.moveFeatures moveFeatureInput = moveFeats.createInput(entities1, transform) move =moveFeats.add(moveFeatureInput) moveBody = move.bodies.item(0) if design.snapshots.hasPendingSnapshot: design.snapshots.add() if z<0.000009 and z>-0.000009: moveBody = body else: ui.messageBox("Moving Z") entities1 = adsk.core.ObjectCollection.create() entities1.add(moveBody) transform = adsk.core.Matrix3D.create() transform.setToRotation(z,design.rootComponent.zConstructionAxis.geometry.getData()[2], actualOrigin) #Create a move feature moveFeats = features.moveFeatures moveFeatureInput = moveFeats.createInput(entities1, transform) move =moveFeats.add(moveFeatureInput) moveBody = move.bodies.item(0) if design.snapshots.hasPendingSnapshot: design.snapshots.add()
Solved! Go to Solution.