Get parent of a selected component/design

Get parent of a selected component/design

oyvindTMNSU
Advocate Advocate
121 Views
2 Replies
Message 1 of 3

Get parent of a selected component/design

oyvindTMNSU
Advocate
Advocate

If I have a referenced design in an assembly, is there a way to(with API) get the parent component/design/occurrence of a selection which is nested below the referenced design?

 

I guess what I’m asking is how to get the whole design three from the component I select up to the first referenced design over this selection? 

 @BrianEkins @kandennti ?

0 Likes
122 Views
2 Replies
  • API
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor

Hi @oyvindTMNSU -San.

I overlooked that. My apologies.

 

The add-in published here only has Japanese documentation, but this command might be useful.

https://github.com/kantoku-code/Fusion360_GOKOTAI/tree/main 

kandennti_0-1762093226167.png

 

Clicking here will take a moment, but it displays a tree view of the files related to the active document.

For example, “caster” is the active document here, but it will trace all the way up to the top-level “RollStand_Assy”.

kandennti_1-1762093294067.png

 



0 Likes
Message 3 of 3

BrianEkins
Mentor
Mentor

You mentioned that you're starting with a selection. There are many different things that can be selected, but in the end, they're either in the root component or in another component (either external or local). If it's in another component, that means there is an occurrence of that component in the current assembly. Here's some untested code that determines whether the selection is in the root component or an occurrence. If it's in an occurrence it displays the occurrence, component, and document names.

 

ent = ui.activeSelections[0].entity

if ent.assemblyContext:
    occ = end.assemblyContext
    result = f'Occurrence: {occ.name}\n'
    comp = occ.component
    result += f'Component: {comp.name}\n'
    doc = comp.parentDesign.parentDocument
    result += f'Document: {doc.name}'
    ui.messageBox(result)
else:
    ui.messageBox('The selected entity is in the root Component.')

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com