Using transformOccurences

Using transformOccurences

Anonymous
Not applicable
415 Views
2 Replies
Message 1 of 3

Using transformOccurences

Anonymous
Not applicable

Dear all,

 

I have been trying to use the Component.transformOccurences function as it seems to be able to do exactly what I am trying to achieve: move/rotate a component while keeping the joint constraints.

 

However I have not been able to make it work properly, as I am unsure about which format should the function's input arguments be in. 

 

If someone has by any chance used this function before, could you provide a quick/easy example to give me a starting point ? 

 

Cheers,

Thomas

0 Likes
Accepted solutions (1)
416 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

I just wrote a simple test case and it appears that the ignoreJoints argument doesn't function correctly when set to False because in my test the joints are always ignored.

 

I created a new design with two components (occurrences) and created one joint between them.  I then ran the code below, changing the value for the ignoreJoints argument but I got the same result regardless of the argument value.

 

def transformOccurrences():
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        occ1 = root.occurrences.item(0)
        occ2 = root.occurrences.item(1)
        
        occs = [occ1, occ2]
        matrices = []
        matrix = adsk.core.Matrix3D.create()
        matrix.translation = adsk.core.Vector3D.create(5,0,0)
        matrices.append(matrix)
        matrix = adsk.core.Matrix3D.create()
        matrix.translation = adsk.core.Vector3D.create(15,2,0)
        matrices.append(matrix)
              
        root.transformOccurrences(occs, matrices, True)
    except:
        app = adsk.core.Application.get()
        ui = app.userInterface
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you for providing this example, it's working perfectly. 

 

Too bad however that the "keep joints" option is not functional, that was for me the main reason to use this tool. 

0 Likes