Get the name of the Component that owns the selected face, programatically.

Get the name of the Component that owns the selected face, programatically.

ebunn3
Advocate Advocate
748 Views
4 Replies
Message 1 of 5

Get the name of the Component that owns the selected face, programatically.

ebunn3
Advocate
Advocate

Hi,

 

See screen shot below.  I am selecting a face and I want to get the name of the component that owns the face.  My problem is that the face may be owned by a component that is buried in the assembly, in this case it is in a component that is within a linked component.  But anything goes depending on who built the assembly.  Any help would be greatly appreciated.

 

Eric

ebunn3_1-1637364264164.png

 

 

 

Accepted solutions (2)
749 Views
4 Replies
Replies (4)
Message 2 of 5

BrianEkins
Mentor
Mentor
Accepted solution

I believe the code below will do it.

if selectedFace.nativeObject:
    # The face exists in a leaf part of an assembly.
    comp = selectedFace.nativeObject.body.parentComponent
else:
    # The faces exists in the root component.
    comp = selectedFace.body.parentComponent
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 5

ebunn3
Advocate
Advocate

Brian

 

This worked out very well thank you.  Another question.  Once I have the component that owns the face is there a way to work upwards to find the top level component that is not the root component.   Just in case the component is within another higher level component.  

Eric

 

0 Likes
Message 4 of 5

BrianEkins
Mentor
Mentor
Accepted solution

The assemblyContext property of the face returns its parent Occurrence.  Calling the assemblyContext property on the returned Occurrence will return its parent occurrence. When the assemblyContext property returns null, you'll know you've reached the root component.

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

ebunn3
Advocate
Advocate

Thank you again!

0 Likes