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

        /// 
        /// 获得装配体中所有的面(非单个工作组件)
        /// 
        /// 工作部件
        /// 所有面的对象
        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;
                }
            }
        }
        /// 
        /// 获得单个组件的面对象(非工作组件)
        /// 
        /// 组件
        /// 面对象
        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);
            }
        }
        /// 
        /// 获得装配体中的所有面对象
        /// 
        /// 工作组件
        /// 所有面对象
        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;
                }
            }
        }

 

你可能感兴趣的:(NX二次开发,组件,c#)