cancel
Showing results for 
Search instead for 
Did you mean: 

Write Parent of each component

Valued Contributor
Valued Contributor

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

Honored Contributor
Honored Contributor

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

Siemens Phenom Siemens Phenom
Siemens Phenom

 

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

Valued Contributor
Valued Contributor

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

Honored Contributor
Honored Contributor

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

Valued Contributor
Valued Contributor

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

Re: Write Parent of each component

Honored Contributor
Honored Contributor

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

Siemens Phenom Siemens Phenom
Siemens Phenom

 

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

Valued Contributor
Valued Contributor

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.

Re: Write Parent of each component

Honored Contributor
Honored Contributor

I'd try:

temp.Component.Parent.Prototype.OwningPart

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