python api: translate component/occurrence with UI visible

python api: translate component/occurrence with UI visible

extrakwextra
Explorer Explorer
439 Views
1 Reply
Message 1 of 2

python api: translate component/occurrence with UI visible

extrakwextra
Explorer
Explorer

Hello,

 

Forgive me for using the wrong nomenclature, I'm fairly new to fusion360.

 

I have written a tool for the bloke doing our documentation that mimics display layers/render layers in Autodesk:maya in fusion.

While the ui is open, he can change the visibility of the components/occurrences in the ui and save those as a display layer. changing between the display layers in the ui, show him what is saved to each and then he can render/ save out the layer to a png file.

 

Now for more complex diagrams, we need to transform (x,y,z) some of the bolts to show how they would go inside the holes, i can record this info with :

xform = obj.transform
object_names[obj.name] = [xform.translation.x,xform.translation.y,xform.translation.z]

When i try to reapply the translation from the gui it does nothing.

xf_vector = adsk.core.Vector3D.create(stored_xform[0],stored_xform[1],stored_xform[2])

# this doesnt do anything, while the gui is running
#obj.transform.translation = xf_vector

Am i doing something wrong or is this a limitation of the api?

 

I should mention as well, im keeping a record of the original home translation of each of the meshes , so that after a translation, they can reset to the original location.


The other problem im running into, and im wondering if there is a workaround, when the ui is open you can change the visibility (light bulb) , but you cant select the components and move them around, is there a way to tell the ui to be non blocking ?

 

Edit: im doing this in the design context/menu.

 

Cheers

Kym

0 Likes
Accepted solutions (1)
440 Views
1 Reply
Reply (1)
Message 2 of 2

BrianEkins
Mentor
Mentor
Accepted solution

The problem is with this line:

 

obj.transform.translation = xf_vector

 

When you call any property that returns geometry or any of the math-related objects (Matrix, Vector, etc.) the object returned is independent and is not related to the object you got it from. One term for this is a "tear-off". In this specific case, you're calling the transform property which returns a Matrix3D. The matrix is independent and is not associated with the Occurrence you got it from. It defines a "snapshot" of the state of the Occurrence at the time you called the transform property.

 

To get this to work you can do this instead. Also, notice that I'm calling the transform2 property because there are some issues with the transform property. That's not the cause of your problem here but better to avoid any other possible problems. This is getting the matrix, adjusting it to be correct, and then assigning it back to the Occurrence.

 

trans = obj.transform2
trans.translation = xf_vector
obj.transform2 = trans

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com