/// <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) { 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, }
 

技术
今日推荐
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:766591547
关注微信