Capture Position after transforming Occurance Origin

Capture Position after transforming Occurance Origin

Anonymous
Not applicable
1,189 Views
2 Replies
Message 1 of 3

Capture Position after transforming Occurance Origin

Anonymous
Not applicable

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?

Capture.PNG

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
0 Likes
Accepted solutions (1)
1,190 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni
Accepted solution

Just add this call after you've transformed the occurrence.

 

design.snapshots.add()

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3

scottmoyse
Mentor
Mentor

@BrianEkins is there a technique which can be used to transform the matrix on a component occurrence while Capturing History without needing to capture a snapshot. I'm working on something which may end up creating a heap of snapshots which would be less than ideal. 


Scott Moyse
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature


RevOps Strategy Manager at Toolpath. New Zealand based.

Co-founder of the Grumpy Sloth full aluminium billet mechanical keyboard project

0 Likes