FInd the Parent Component of a Component

FInd the Parent Component of a Component

Anonymous
Not applicable
1,415 Views
2 Replies
Message 1 of 3

FInd the Parent Component of a Component

Anonymous
Not applicable

I need to find the parents component of a component (usually the root but sometimes components are nested). Is there a method to find this given a reference to the component? I don't quite understand the language around Occurrences to know if you can find the parent occurrence using methods like comp.allOccurrencesByComponent() to access parent occurrences and then their components. 

 

I could do this using breadth first search, getting the children of the root component and searching its children and their children untill I find my component then go up a level, but I wonder if there is a constant time method for doing this?

1,416 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni

Have you read the article that discusses components and occurrences in the API help?  What you're traversing in the assembly is occurrences and not components.  Hopefully that article is helpful but if not, feel free to ask additional questions here.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 3

p.seem
Advocate
Advocate

I've used occurrence.assemblyContext and occurrence.sourceComponent to find the parent occurrence/component, depending on whether or not the occurrence in question is the native object.

 

I'm sure it's wrong in any number of important respects, but my mental shortcut for understanding component vs occurrence is that the component is the class definition, and occurrence is the instance. If you imaging a screw (component) which is used in many different sub-assemblies within the model (many occurrences), you can see that the 'parent' occurrence (the sub-assembly in which the screw is a top-level occurrence) is different for difference occurrences, which is why you aren't finding a method to directly access the parent of a component. You need to get to a particular occurrence before you can directly access the parent.

 

Hope that helps.

 

Pete