Message 1 of 3

Not applicable
03-01-2016
11:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need to move a component from a python script by translating its origin. I'm using the function below to do this. Unfortunatly If I try to do any other edits to the design from that script the component returns to the same position because I did not "capture" the position. Is there a way to access this command from the api? The position option is only visable if I stop the code from proceeding after the transformation? Is there a better way to move a component (not just its bodies, it must include the origin like a move compoonent command) that does not require this capture position command?
def translateComponentOrigin(design, component, newOrigin, plane): occurrence = design.rootComponent.allOccurrencesByComponent(component).item(0) # Get the current transform of the occurrence transform = occurrence.transform (origin, x,y,z) = transform.getAsCoordinateSystem() geom = plane.geometry evaluat = geom.evaluator normal = evaluat.getNormalAtPoint(origin)[1] transformer = adsk.core.Matrix3D.create() transformer.translation = origin.vectorTo(newOrigin) transform.setToRotateTo(y,normal) transform.transformBy(transformer) design.rootComponent.allOccurrencesByComponent(component).item(0).transform = transform
Solved! Go to Solution.