NX二次開發-建模-遍歷所有物件

NX二次開發專注者發表於2020-10-11
                    //獲取工作部件的所有的體物件
                    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();

 

相關文章