Strange behavior on Occurrence.moveToComponent() with Occurrence.transform

Strange behavior on Occurrence.moveToComponent() with Occurrence.transform

hajime2MRG3
Enthusiast Enthusiast
961 Views
4 Replies
Message 1 of 5

Strange behavior on Occurrence.moveToComponent() with Occurrence.transform

hajime2MRG3
Enthusiast
Enthusiast
import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root_comp = des.rootComponent

        EYE = adsk.core.Matrix3D.create()
        o1 = root_comp.occurrences.addNewComponent(EYE)
        o2 = root_comp.occurrences.addNewComponent(EYE)
        o1_1 = o1.component.occurrences.addNewComponent(EYE)
        o1_2 = o1.component.occurrences.addNewComponent(EYE)

        ROT = adsk.core.Matrix3D.create()
        ROT.setToRotation(1., adsk.core.Vector3D.create(0, 0, 1), adsk.core.Point3D.create(0, 0, 0))

        o2_1 = o1_1.moveToComponent(o2)
        o2_1.transform = ROT
        print('Before:')
        print('o2_1.transform.asArray():')
        print(o2_1.transform.asArray())

        _ = o1_2.moveToComponent(o2)
        print('After:')
        print('o2_1.transform.asArray():')
        print(o2_1.transform.asArray())
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

The test code above results:

Before:
o2_1.transform.asArray():
(0.5403023058681398, -0.8414709848078965, 0.0, 0.0, 0.8414709848078965, 0.5403023058681398, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0)
After:
o2_1.transform.asArray():
(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0)

Why does o1_2.moveToComponent(o2) affects on o2_1.transform?

0 Likes
Accepted solutions (1)
962 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor
Accepted solution

Hi @hajime2MRG3 .

 

I used to have trouble getting the correct position.
Here's the cause.
 
1.png
In the case of Occurrence, the conversion will not complete. So, you need to determine the position.
 
・・・
        o2_1 = o1_1.moveToComponent(o2)
        o2_1.transform = ROT
        des.snapshots.add() # <-Here
        print('Before:')
        print('o2_1.transform.asArray():')
        print(o2_1.transform.asArray())
・・・

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/transformation-on-occurrence-getting-reset... 

 

Also, I strongly recommend using the isPositionDependent property when invoking the command.
0 Likes
Message 3 of 5

hajime2MRG3
Enthusiast
Enthusiast

Thank you kandennti,

I feel hard to distinguish which operation resets position. In GUI, a dialog pops up, but no warning or exception in scripts. Any good way to find unwanted resets?

0 Likes
Message 4 of 5

kandennti
Mentor
Mentor

@hajime2MRG3 .

 

I don't have any better ideas.

It is very difficult to create an add-in that involves occurrence.

0 Likes
Message 5 of 5

hajime2MRG3
Enthusiast
Enthusiast
Thank you again.
0 Likes