Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

rootComponent.allAsBuiltJoints returns an error

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
david.rips
237 Views, 8 Replies

rootComponent.allAsBuiltJoints returns an error

I'm pretty new to the Fusion 360 API and python. I've been trying to manipulate various joints in a very complex model. In order to do that, I have to find the joints (regular and As-Built). I've been struggling. To simplify the analysis of my problems, I've created a simple script to just find all the As-Built joints. It fails.

 

I've read everything I can from the forum and haven't been able to solve this issue. This is the code:

 

 

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

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        rootComp = design.rootComponent
        aj = rootComp.allAsBuiltJoints
        ui.messageBox('Number of Joints: ' + str(aj.count))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

This is the error message:

 

Failed:

Traceback (most recent call last):

File "C:/Users/DWR/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/FindJoint2/FindJoint2.py", line 14, in run

aj = rootComp.allAsBuiltJoints

^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users/DWR/AppData/Local/Autodesk/webdeploy/production/3167d85f5fd4280287d8295f20592fa13b977617/Api/Python/packages\adsk\fusion.py", line 55135, in _get_allAsBuiltJoints

return _fusion.Component__get_allAsBuiltJoints(self)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

RuntimeError: 3 : object does not belong to the occurrence's component

 

 

I also can't figure out how to count the number of items in the returned list, but that is another problem.

 

Thanks, in advance for any help you can provide.

8 REPLIES 8
Message 2 of 9

Hi,

 

I couldn't reproduce the error in my environment.

 

Some points to check here:

1. Are you in the Design workspace? (otherwise design variable gets a None value)

2. The error message say it crashes on line 14, but in you code line 14 is something else.  They don't match. It look's like you're running a variant of the code snippet you shared.

3. Component's allAsBuiltJoints property returns list[AsBuiltJoint], so you have to check for len(rootComp.allAsBuiltJoints) to get number of joints, instead of count property.

 

Regards,

Jorge Jaramillo

Software Engineer

 

Message 3 of 9

Thank you Jorge.

 

1. Yes, I am running the script from the Design workspace.

2. Apparently, the line numbers change when you paste a code sample, renumbering from the top of the sample. Here's the revised code, with everything (including the changes you suggest in your #3):

 

 

#Author-
#Description-

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

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        rootComp = design.rootComponent
        aj = rootComp.allAsBuiltJoints
        numJoints = str(len(rootComp.allAsBuiltJoints))
        ui.messageBox('Number of Joints: ' + numJoints)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

 3. I've made the change you suggested, but obviously it can't yet work until I resolve #2. BTW, when I run this script using rootComp.asBuiltJoints (and aj.count) I get the results I expect. No error message.

 

Here's the new error message (using allAsBuiltJoints). Same as the old one.

 

Failed:

Traceback (most recent call last):

File "C:/Users/DWR/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/FindJoint2/FindJoint2.py", line 14, in run

aj = rootComp.allAsBuiltJoints

^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users/DWR/AppData/Local/Autodesk/webdeploy/production/3167d85f5fd4280287d8295f20592fa13b977617/Api/Python/packages\adsk\fusion.py", line 55135, in _get_allAsBuiltJoints

return _fusion.Component__get_allAsBuiltJoints(self)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

RuntimeError: 3 : object does not belong to the occurrence's component

 

Thanks again!

 

Message 4 of 9

Hi,
Could you share the model you're working with?
Message 5 of 9

I could, but the F3Z file is very large: 740MB. Are there limits, before I break something?

Message 6 of 9

Hi,
Could you try your code snippet with a simpler model o even with an empty model?
Just to check if your problem is due to the model or your environment?
Message 7 of 9

Good idea. I ran the script on several smaller files, even ones with joints in subcomponents. All were successful. It must be a problem with my large model. Any suggestions?

Message 8 of 9

Somehow you broke the model.
I'd suggest make a copy, delete all joints, save it, and start adding them one by one while you check with the script it isn't braked again.
Message 9 of 9

Will do. Thanks for your help.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report