UGNX⼆次开发中的组件遍历(C#)
/// <summary>
/// 通过遍历获取装配体的全部组件
/// </summary>
/// <param name="part">⼯作部件</param>
/// <param name="componentsList">组件链表</param>
/// <param name="developmentType">选择开发的类型</param>
public static void TraversalComponents( List<NXOpen.Assemblies.Component> componentsList,DevelopmentType developmentType)
{
if (developmentType == DevelopmentType.UGOPEN)
param name
{
Tag componentTag = Tag.Null;
uFObj.CycleObjsInPart(uFAssem.AskWorkPart(), 63, ref componentTag);                    //根据类型遍历装配体中的组件,按次序读取,⼀次读取⼀个                    while (componentTag != Tag.Null)                                                        //以读取的组件为空为结束条件
{
NXObjectManager nXObjectManager = new NXObjectManager();
TaggedObject taggedObject = nXObjectManager.GetTaggedObject(componentTag);        //将tag转化为TaggedObject对象
Component newComponent = (Component)taggedObject;                                  //将taggedObject转化为Component对象
componentsList.Add(newComponent);
uFObj.CycleObjsInPart(uFAssem.AskWorkPart(), 63, ref componentTag);                      //读取下⼀个组件
}
}
else if(developmentType==DevelopmentType.NXOPEN)
{
ComponentAssembly componentAssembly = workPart.ComponentAssembly;
Component rootComponent = componentAssembly.RootComponent;
GetComponentsChildren(rootComponent, componentsList);
}
}
/// <summary>
/// ⽤NXOPEN获得装配体的所有组件(递归算法)
/
// </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>
/// 定义开发类型的枚举
/// </summary>
public enum DevelopmentType
{
/// <summary>
/// 采⽤OPEN C/C++
/// </summary>
UGOPEN,
/// <summary>
/
// 采⽤NXOPEN
/// </summary>
NXOPEN,
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。