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: 

List of all subcomponents in a component similar to design.allComponents

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
paulallan.osborne
1034 Views, 2 Replies

List of all subcomponents in a component similar to design.allComponents

Is there a command to get a list of all subcomponents of a component in a design, similar to design.allComponents, but for components instead?

2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: paulallan.osborne

There's a subtlety first in that a component is distinct from an occurrence which is, essentially, a component instance. They are used interchangeably sometimes!

 

Anyway. If you start with the rootComponent say (or any component but root is most obvious), and look at its occurrences property - this is a collection of the Occurrences associated with that component (yes, it's mildly headwrecking initially). You will see it has a "asList" property which yields the collection as a list - with the usual count property and item() method. If you traverse that list that will give you a component tree:

 

for i in range(occurrencelist.count):
        occ = occurrencelist.item(i)

 

So each occ.component is the component that occurrence references. If occ.childOccurrences is non Null, the occurrence has a subtree of occurrences which gives you another list of occurrences and so on down the tree. You can do a classic recursive action to traverse the tree:

 

def traverse(occurrences):
    for i in range(occurrences.count):
        occ = occurrences.item(i)

.... do stuff with occ like look at occ.component ....
if occ.childOccurrences: traverse(occ.childOccurrences)

 

Something like that anyway 🙂

 

Conor.

Message 3 of 3
ekinsb
in reply to: paulallan.osborne

I just want to add a couple of more things to this discussion.  First, I agree that the term "Component" is overused within Fusion.  The user-interface only uses the term "Component" and uses it for both components and occurrences but they are very different.  The API has to differentiate between the two.  I recommend reading the topic below in the API help.  Hopefully it will make it much clearer in your mind.

 

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A

 

Second, here's an existing sample program that uses the ability that Conor mentioned and traverses an entire assembly.

 

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-5a4fa3a6-fa21-11e4-b610-f8b156d7cd97


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog

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