UG二次开发-获取装配体中的所有体对象


        /// <summary>
        /// 获得单个组件的体(非工作组件)
        /// </summary>
        /// <param name="component">组件对象</param>
        /// <param name="bodies">组件包括的实体</param>
        public static void GetComponentBodies(Component component, out Body[] bodies)
        {
            bodies = new Body[0];
            Tag objectTag = Tag.Null;
            uFAssem.CycleObjsInComp(component.Tag, ref objectTag);
            while (objectTag != Tag.Null)
            {
                int type;
                int subType;
                uFObj.AskTypeAndSubtype(objectTag, out type, out subType);
                if (type == 70 & subType == 0)
                {
                    Array.Resize(ref bodies, bodies.Length + 1);
                    NXObjectManager nXObjectManager = new NXObjectManager();
                    Body body = (Body)nXObjectManager.GetTaggedObject(objectTag);
                    bodies[bodies.Length - 1] = body;
                }
                uFAssem.CycleObjsInComp(component.Tag, ref objectTag);
            }
        }
        /// <summary>
        /// 获得工作部件的所有体对象
        /// </summary>
        /// <param name="part">工作部件</param>
        /// <param name="allBodies">所有的体对象</param>
        public static void GetWorkPartBodies(Part part, out Body[] allBodies)
        {
            allBodies = new Body[0];
            part = theSession.Parts.Work;
            Tag rootTag = uFAssem.AskRootPartOcc(part.Tag);
            Tag[] rootComponentChildrenTag;
            int partNum = uFAssem.AskPartOccChildren(rootTag, out rootComponentChildrenTag);
            NXObjectManager nXObjectManager = new NXObjectManager();
            foreach (var rcc in rootComponentChildrenTag)
            {
                Component component = (Component)nXObjectManager.GetTaggedObject(rcc);
                Body[] bodies;
                GetComponentBodies(component, out bodies);
                foreach (var bd in bodies)
                {
                    Array.Resize(ref allBodies, allBodies.Length + 1);
                    allBodies[allBodies.Length - 1] = bd;
                }
            }
        }

猜你喜欢

转载自blog.csdn.net/yang19861007/article/details/105387464
今日推荐