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 JAE on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NX Open - Get immidiate children

Status
Not open for further replies.

NutAce

Mechanical
Joined
Apr 22, 2010
Messages
1,192
Location
CH
Hello all,

I'm taking my first steps into NX Open using c# and have the following problem...

From an assembly I am able to produce a list of the child components...However it is returning a list of ALL the components in the Assembly.
I would like to see only the immidiate children (sub assemblies toplevels)...

What Ihave so far is;

Code:
                //get all parts in session and create List
                List<NXOpen.Part> newDisplayParts = new List<NXOpen.Part>();

                foreach (NXOpen.Part part in theSession.Parts)
                {
                    NXOpen.Assemblies.Component childComp = part.ComponentAssembly.RootComponent;
                    if (childComp != null)
                    {
                        foreach (NXOpen.Assemblies.Component comp in childComp.GetChildren())
                        {
                            //Checking if comp.protype is an actual NXOpen part is
                            if (comp.Prototype is NXOpen.Part)
                            {
                                theSession.ListingWindow.Open();
                                theSession.ListingWindow.WriteLine(comp.DisplayName);
                                NXOpen.Part prototype = (NXOpen.Part) comp.Prototype;
                                if (prototype == workPart)
                                {
                                    newDisplayParts.Add(part);
                                }
                            }
                        }
                    }
                }

How to proceed?

Ronald van den Broek
Application Specialist
Winterthur Gas & Diesel Ltd
NX8.5.3 / TC9.1.2
HPZ420 Intel(R) Xeon(R) CPU E5-1620 0 @ 3.60GHz, 32 Gb Win7 64B
Nvidea Quadro4000 2048MB DDR5
HP EliteBook 8570W Intel(R) Core(TM) I7-3740QM CPU @ 2.70GHz, 16Gb Win7 64B

 
Don't loop through all the parts that are in the current NX session, only process the desired assembly part. In other words, eliminate this loop:
Code:
foreach (NXOpen.Part part in theSession.Parts)

Instead, get a reference to the assembly of interest and only process that one "part".

www.nxjournaling.com
 
Thanks Cowski...It works now..


Ronald van den Broek
Application Specialist
Winterthur Gas & Diesel Ltd
NX8.5.3 / TC9.1.2
HPZ420 Intel(R) Xeon(R) CPU E5-1620 0 @ 3.60GHz, 32 Gb Win7 64B
Nvidea Quadro4000 2048MB DDR5
HP EliteBook 8570W Intel(R) Core(TM) I7-3740QM CPU @ 2.70GHz, 16Gb Win7 64B

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top