NX二次开发-建模-遍历所有对象

                    //获取工作部件的所有的体对象
                    workPart = theSession.Parts.Work;
                    BodyCollection bodyCollection = workPart.Bodies;
                    Body[] bodies = bodyCollection.ToArray();

                    //将体对象按照实体和片体分类
                    Body[] solidBodies = new Body[0];
                    Body[] sheetBodies = new Body[0];
                    foreach(var bd in bodies)
                    {
                        if(bd.IsSolidBody)
                        {
                            Array.Resize(ref solidBodies, solidBodies.Length + 1);
                            solidBodies[solidBodies.Length - 1] = bd;
                        }
                        else
                        {
                            Array.Resize(ref sheetBodies, sheetBodies.Length + 1);
                            sheetBodies[sheetBodies.Length - 1] = bd;
                        }
                    }
                    MessageBox.Show("实体有:"+solidBodies.Length.ToString()+"\n"+"片体有:"+sheetBodies.Length.ToString());

                    //获取体的面
                    Face[] faces = bodies[0].GetFaces();

                    //获取面的边
                    Edge[] edges = faces[0].GetEdges();

 

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