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
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.
These are what I tried and can think of:
1) I can find out the list of the components of an assembly by using:
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 :
But, it returns the assembly part itself and not the part instance of the individual part (WHY?!).
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.
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!).
So, 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.
If you have a reference to a component, you can get the prototype part with the following: