/// <summary> /// Get all the components of the assembly by traversing /// </summary> /// <param
name="part"> Working parts </param> /// <param name="componentsList"> Component list </param> ///
<param name="developmentType"> Choose the type of development </param> public static void
TraversalComponents( List<NXOpen.Assemblies.Component>
componentsList,DevelopmentType developmentType) { if (developmentType ==
DevelopmentType.UGOPEN) { Tag componentTag = Tag.Null;
uFObj.CycleObjsInPart(uFAssem.AskWorkPart(), 63, ref componentTag);
// Traverses the components in an assembly by type , Read in order , Read one at a time while (componentTag != Tag.Null) // The end condition is that the read component is null {
NXObjectManager nXObjectManager = new NXObjectManager(); TaggedObject
taggedObject = nXObjectManager.GetTaggedObject(componentTag);
// take tag Convert to TaggedObject object Component newComponent = (Component)taggedObject;
// take taggedObject Convert to Component object componentsList.Add(newComponent);
uFObj.CycleObjsInPart(uFAssem.AskWorkPart(), 63, ref componentTag); // Read next component }
} else if(developmentType==DevelopmentType.NXOPEN) { ComponentAssembly
componentAssembly = workPart.ComponentAssembly; Component rootComponent =
componentAssembly.RootComponent; GetComponentsChildren(rootComponent,
componentsList); } } /// <summary> /// use NXOPEN Get all the components of the assembly ( recursive algorithm ) /// </summary>
/// <param name="rootComponent"></param> /// <param
name="componentsList"></param> public static void
GetComponentsChildren(Component rootComponent, List<Component> componentsList)
{ Component[] componentsChildren = rootComponent.GetChildren(); foreach (var cc
in componentsChildren) { componentsList.Add(cc); GetComponentsChildren(cc,
componentsList); } } /// <summary> /// Defines an enumeration of development types /// </summary> public enum
DevelopmentType { /// <summary> /// use OPEN C/C++ /// </summary> UGOPEN, ///
<summary> /// use NXOPEN /// </summary> NXOPEN, }
 

Technology