Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access part collections in an assembly

Status
Not open for further replies.

neshom

Mechanical
Joined
Feb 7, 2016
Messages
43
Location
AU
I'd like to access collections (Sketches, Datums, Bodies, etc) of all of the parts in an assembly. The assembly part (.prt) itself is easy because I can use
Code:
NXOpen.Part partWork = theSession.Parts.Work;
to access the part instance of the assembly prt (assuming it is the work part). Using this instance I can access all of the collections that are in the assembly prt itself, but not those that are in other parts that are in the assembly.

So, my question is how I can access the part instances of other components of the assembly?

These are what I tried and can think of:

1) I can find out the list of the components of an assembly by using:
Code:
NXOpen.Assemblies.Component[] childComponents = partWork.ComponentAssembly.RootComponent.GetChildren();
By knowing the component instance of the parts, I was hoping to get access to the part that has the component by using the following for the i-th component:
Code:
childComponents[i].OwningPart
But, it returns the assembly part itself and not the instance of the individual part.

2) Theoretically, I can use the following to find all of the parts loaded in the session, but it also returns the parts that are not part of the assembly.
Code:
NXOpen.PartCollection pc = theSession.Parts;
I may be able to investigate whether each individual part belongs to the assembly or not (which I am not sure how!).

I am wondering whether there is a way to directly (not by checking all of the loaded parts one by one to check which is part of the assembly and which is not) find the list of the parts that belong to the assembly that either itself or one of its components is the work part.

Thanks in advance.
 
Walk the Assembly Tree Top/Down in a recursive way.
There a plenty of GTAC code examples doing that.
Look for "WalkAssemblyTree" in the GTAC library.
 
If you have a reference to a component, you can get the prototype part with:

Code:
{component}.Prototype.OwningPart

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top