Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Write Parent of each component

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).

9 REPLIES

Re: Write Parent of each component

[ Edited ]

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).

Re: Write Parent of each component

 

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.

 

 

Re: Write Parent of each component

How exacty do I use OwningPart()?

 

I have been trying to use:

 

 temp.Component.OwningPart()

 

It has been giving me an error.

Re: Write Parent of each component

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.

Re: Write Parent of each component

So when you say the parts properties and methods you mean to reference things like it's attributes? 

Re: Write Parent of each component

Yes.

 

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.

Re: Write Parent of each component

 

Something like this should work, assuming your Component is stored in "comp":

 

       Dim OwningPart As BasePart = comp.OwningPart()

        Echo("   Is owned by:  " & OwningPart.Leaf())

Re: Write Parent of each component

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.

Solution
Solution
Accepted by topic author junfan
‎08-26-2015 04:32 AM

Re: Write Parent of each component

I'd try:

temp.Component.Parent.Prototype.OwningPart

you may be able to shorten this to temp.Parent.Prototype.OwningPart