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

        /// <summary>
        /// 获得装配体中所有的面(非单个工作组件)
        /// </summary>
        /// <param name="part">工作部件</param>
        /// <param name="allFaces">所有面的对象</param>
        public static void GetWorkPartFaces(Part part, out Face[] allFaces)
        {
            Body[] bodies;
            GetWorkPartBodies(part, out bodies);
            allFaces = new Face[0];
            foreach (var bd in bodies)
            {
                Face[] faces = bd.GetFaces();
                foreach (var fc in faces)
                {
                    Array.Resize(ref allFaces, allFaces.Length + 1);
                    allFaces[allFaces.Length - 1] = fc;
                }
            }
        }
        /// <summary>
        /// 获得单个组件的面对象(非工作组件)
        /// </summary>
        /// <param name="component">组件</param>
        /// <param name="faces">面对象</param>
        public static void GetComponentFaces(Component component, out Face[] faces)
        {
            faces = new Face[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 == 2)
                {
                    Array.Resize(ref faces, faces.Length + 1);
                    NXObjectManager nXObjectManager = new NXObjectManager();
                    Face face = (Face)nXObjectManager.GetTaggedObject(objectTag);
                    faces[faces.Length - 1] = face;
                }
                uFAssem.CycleObjsInComp(component.Tag, ref objectTag);
            }
        }
        /// <summary>
        /// 获得装配体中的所有面对象
        /// </summary>
        /// <param name="part">工作组件</param>
        /// <param name="allFaces">所有面对象</param>
        public static void GetWorkPartFaces1(Part part, out Face[] allFaces)
        {
            allFaces = new Face[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);
                Face[] faces;
                GetComponentFaces(component, out faces);
                foreach (var fc in faces)
                {
                    Array.Resize(ref allFaces, allFaces.Length + 1);
                    allFaces[allFaces.Length - 1] = fc;
                }
            }
        }

猜你喜欢

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