selectionCommandInput runtime error when addSelection JointOrigin

selectionCommandInput runtime error when addSelection JointOrigin

simon.trendel
Participant Participant
594 Views
2 Replies
Message 1 of 3

selectionCommandInput runtime error when addSelection JointOrigin

simon.trendel
Participant
Participant

Hi,

 

I have a script that needs to load selections saved in a yaml file. The selectionCommandInputs are created in the CommandCreateHandler. After the commands are created a custom event is fired that selects the saved selections.

It works fine for Occurences and Joints, but fails with runtime error 3 when trying to add a JointOrigin. 

The origin_input has a selectionFilter for 'JointOrigins' and number of selections is limited to 1.

Am I doing something wrong here?

 

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

john.kirchner
Autodesk
Autodesk
Accepted solution

One thing I would try out is to get the JointOrigin with assembly context and return it from your findJointOrigin function. That way the selection has the information for which exact JointOrigin you are specifying.

Not entirely sure what your findJointOrigin function looks like but it seems you are iterating through Occurrences, so when you find the JointOrigin

return foundJointOrigin.createForAssmeblyContext(occurrenceInList)

 
Here's some more info with regards to this at the bottom in the "Proxies" section https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A 



0 Likes
Message 3 of 3

simon.trendel
Participant
Participant

awesome, many thanks. I'm starting to wrap my head around these proxies...

 

like you suggested I modified the findJointOrigin recursive function to also return the occurrence the found joint origin lives in, that way I can create the proxy and successfully add it to the selection. Here are the respective code snippets for anybody interested:

def findJointOrigin(name, occurrences, currentLevel, joint_origin, occ):
    print("currentLevel: %d"%currentLevel)
    for occurrence in occurrences:
        print(occurrence.name)
        for jo in occurrence.component.jointOrigins:
            if jo.name == name:
                joint_origin.append(jo)
                occ.append(occurrence)
                return True
        if occurrence.childOccurrences:
            findJointOrigin(name,occurrence.childOccurrences,currentLevel+1, joint_origin, occ)
origin_input = adsk.core.SelectionCommandInput.cast(_robot_configuration_inputs.itemById('origin'))

origin = []
occ = []
findJointOrigin(_robot_config['robot']['origin'], _rootComp.occurrences.asList, 0, origin, occ)
if len(origin)>0:
    origin_proxy = origin[0].createForAssemblyContext(occ[0])
    origin_input.addSelection(origin_proxy)
0 Likes