快捷搜索: 王者荣耀 脱发

各种功能的代码示例1

1、遍历零件中的所有的face

//遍历零件中的所有的face
 		public void TraverseFace(IPartDoc currentPartDoc)
        {
          
   
            //获取所有Body
            Array bodies = (Array)(currentPartDoc.GetBodies2((int)swBodyType_e.swSolidBody, true));

            //遍历每个Body
            foreach (IBody2 body in bodies)
            {
          
   
                /*获取所有Face*/
                Array faces = (Array)body.GetFaces();
                for (int i = 0; i < faces.Length; i++)
                {
          
   
                    //获取当前正在遍历的面
                    IFace2 face = (IFace2)faces.GetValue(i);
                    //这里就可以对每一个face进行处理。
                }
            }
        }

2、遍历一个face中的所有edge

//遍历一个face中的所有edge
  		public int TraverseEdge(IFace2 tempFace)
        {
          
   
            int num = 0;
            //获取面的环
            object[] tempLoops = (object[])tempFace.GetLoops();
            //遍历环上的边
            foreach (ILoop2 tempLoop in tempLoops)
            {
          
                   
                //如果是外环
                if (tempLoop.IsOuter() == true)
                {
          
   
                    //遍历边
                    object[] edges = (object[])tempLoop.GetEdges();                    
                    for (int b = 0; b < edges.Length; b++)
                     foreach ( IEdge edge in edges)
                    {
          
   
                        //获取当前在遍历的Edge
                        //可以对每一个边进行处理。例如:                       
                        //取该edge的起点
                        if (edge.IGetStartVertex() != null)
                        {
          
   
                            double[] pointArray = new double[3];
                            pointArray = edge.IGetStartVertex().GetPoint();
                        }
                        num++;
                    }
                }
            }
            return num;
        }

3、获取一个face的信息

//获取一个face的信息
 		public int GetFaceInformation(IFace2 tempFace)
        {
          
   
            //获得该面的面积,结果保留8位小数
            double tempFaceArea = Math.Round(tempFace.GetArea(), 8);
            //获得该面的边数
            int tempFaceEdgeCount = tempFace.GetEdgeCount();
            //得到surface
            ISurface tempsurface = tempFace.GetSurface();

            //判断tempsurface的类型
            //如果该面为平面
            if (tempsurface.IsPlane())
            {
          
   
                //得到平面法线和点,
                double[] normalOfPlane = new double[3];
                normalOfPlane[0] = tempsurface.PlaneParams[0];
                normalOfPlane[1] = tempsurface.PlaneParams[1];
                normalOfPlane[2] = tempsurface.PlaneParams[2];
                double[] rootPt = new double[3];
                rootPt[0] = tempsurface.PlaneParams[3];
                rootPt[1] = tempsurface.PlaneParams[4];
                rootPt[2] = tempsurface.PlaneParams[5];
            }
            //如果该面为柱面
            if (tempsurface.IsCylinder())
            {
          
   
                //得到柱面半径,其余信息可以查看帮助文档
                double[] originPt = new double[3];
                originPt[0] = tempsurface.CylinderParams[0];
                originPt[1] = tempsurface.CylinderParams[1];
                originPt[2] = tempsurface.CylinderParams[2];
                double[] axis = new double[3];
                axis[0] = tempsurface.CylinderParams[3];
                axis[1] = tempsurface.CylinderParams[4];
                axis[2] = tempsurface.CylinderParams[5];
                double radiusOfCylinder = tempsurface.CylinderParams[6];
            }
            //如果该面是球面
            if (tempsurface.IsSphere())
            {
          
   
                //得到球面半径,其余信息可以查看帮助文档
                double radiusOfSphere = tempsurface.SphereParams[3];
            }
            return tempFaceEdgeCount;
        }

4、清除所有选中

//清除所有选中
IModelDoc2 doc = curDoc;
 doc .ClearSelection2(true);
经验分享 程序员 微信小程序 职场和发展