I was able to get the children names by using the "DB_PART_NAME" attribute in my code. However I want to be able to get the parent of each component so I can write that into the column next to the children names. This way when sorting through data in excel you don't lose the Parent/Child relationship.
I am currently looping through the assembly by using a for loop. What code could I use to get the Parent of each component in the assembly? (in VB.NET please).
Solved! Go to Solution.
A component object has a .Parent property that you might find useful. It returns a component that is the parent of the given component (or a null reference if you are at the top of the assembly).
As Cowski mentioned, you can use Parent. Another option is OwningPart() which avoids the null reference for immediate components of the top of the tree.
How exacty do I use OwningPart()?
I have been trying to use:
It has been giving me an error.
The .OwningPart property will give you a reference to a Part object. You will need to use the part object's properties and methods to get the information you need then write it to your Excel file.
If you attempt to set the Excel cell .Value equal to an arbitrary object (such as a Part), it will likely result in an error or it will use the object's default property which may not be what you want. You will need to use the object's properties and methods to get the information that you want (e.g. the value of the part's DB_PART_NAME attribute) and write that to Excel.
Something like this should work, assuming your Component is stored in "comp":
Dim OwningPart As BasePart = comp.OwningPart()
Echo(" Is owned by: " & OwningPart.Leaf())
Okay, I tried your code and it worked. However it is giving me the top level part name for each component. I was hoping to get the parent for each component, not the tope level part. I also tried using attributes and it gives me an error saying that
NXOPEN.BASEPART cannot be indexed because it has no default property.
you may be able to shorten this to temp.Parent.Prototype.OwningPart