UG二次开发中装配体中的体TAG号两种不同的读取方式

在装配体中,有两种不同的体TAG读取方式,结果是不相同的。

第一种是将以此将每个组件设置为工作组件,通过BodyCollection获得

                    List<Tag> componentBodiesList2 = new List<Tag>(); //创建链表
                    ComponentsTraverse componentsTraverse = new ComponentsTraverse(); //这是个人写的一个组件遍历类
                    ComponentsTraverse.CreateComponentList(); //获取所有组件链表
                    Component component = null;
                    PartLoadStatus partLoadStatus = null;                    

                    foreach (var cl in ComponentsTraverse.componentsList)
                    {
                        component = cl;                       
                        theSession.Parts.SetWorkComponent(component, out partLoadStatus);
                        workPart = theSession.Parts.Work;
                        BodyCollection bodyCollection = workPart.Bodies;
                        Body[] bodies = bodyCollection.ToArray();                       
                        foreach (var bd in bodies)
                        {
                            componentBodiesList2.Add(bd.Tag);
                        }
                    }
                    component = null;
                    theSession.Parts.SetWorkComponent(component, out partLoadStatus);

第二种方法

通过遍历装配体中的对象类实现,

                    workPart = theSession.Parts.Work;
                    int type = UFConstants.SOLID;             //实体类型
                    Tag out_Tag = Tag.Null;
                    List<Tag> componentBodiesList1 = new List<Tag>();  

                    uFObj.CycleObjsInPart(workPart.Tag,type,ref out_Tag);  //遍历对象
                                                          
                    while(out_Tag!=Tag.Null)
                    {                        
                        int type1;
                        int subtype1;
                        uFObj.AskTypeAndSubtype(out_Tag,out type1,out subtype1);  //获取读取的类型,其中会存在面的类型
                        if (type1==70&subtype1==0)                             //选择实体类型
                        {
                            componentBodiesList1.Add(out_Tag);
                        }
                        uFObj.CycleObjsInPart(workPart.Tag, type, ref out_Tag);
                    }

这两种方法获得体对象不相同,前者是属于单个组件模型中的体,后者是属于装配体的。

其对比如下

Tag号对比

第一种	第二种
46153	45120
46154	45122
46155	45123
46156	45124
46157	45125
46158	45127
46159	45129
46176	45130
46178	45132
46179	45133
46180	45134
46181	45135
46182	45138
46183	45139
46184	45140
46185	45141
46205	45143
46206	45144
46207	45146
51712	45147
51713	45148
51714	45149
51715	45151
51716	45155
51717	45158
51722	45159
51723	45161
51724	45163
51729	45164
51730	45165
51731	45166
51733	45167
51735	45168
51736	45169
51737	45171
51738	45172
51740	45173
51741	45174
51742	45176
51743	45180
51744	45181
51745	45182
51746	45183
51747	79297
51748	79300
51749	79303
51750	79305
51751	79310
51752	79312
51753	79314
51754	79316
51755	79320
51757	79322
51758	79323
51759	79325
51762	79326
51764	79328
51765	79330
51766	79333
51767	79334
51768	79337
51769	79338
51770	79340
51771	79342
51772	79344
51773	79348
51774	79353
51775	79356

猜你喜欢

转载自blog.csdn.net/yang19861007/article/details/105385773