Exemplo n.º 1
0
        private void ListBodies()
        {
            ModelDoc2 swModel = null;
            PartDoc   swPart  = null;
            object    vBody;
            bool      bRet;

            swModel = (ModelDoc2)iswApp.ActiveDoc;
            swModel.ClearSelection2(true);
            Debug.Print("File = " + swModel.GetPathName());

            txtPath.Text = swModel.GetPathName();

            this.Text = System.IO.Path.GetFileName(txtPath.Text);

            switch (swModel.GetType())
            {
            case (int)swDocumentTypes_e.swDocPART:
                swPart = (PartDoc)swModel;
                // Solid bodies
                object[] vBodyArr = null;
                Body2    swBody   = default(Body2);

                MathTransform swMathTrans = null;
                vBodyArr = (object[])swPart.GetBodies2((int)swBodyType_e.swSolidBody, true);

                if ((vBodyArr != null))
                {
                    // Debug.Print("  Number of solid bodies: " + vBodyArr.Length);

                    foreach (object vBody_loopVariable in vBodyArr)
                    {
                        vBody  = vBody_loopVariable;
                        swBody = (Body2)vBody;

                        string[] vConfigName = null;
                        vConfigName = (string[])swModel.GetConfigurationNames();
                        string sMatDB   = "";
                        string sMatName = swBody.GetMaterialPropertyName("", out sMatDB);

                        //bRet = swBody.RemoveMaterialProperty((int)swInConfigurationOpts_e.swAllConfiguration, (vConfigName));

                        // Debug.Print("Body--> " + swBody.Name + " " + "");

                        FeatureType Ftype = 0;

                        var childFeature = (object[])swBody.GetFeatures();

                        foreach (var item in childFeature)
                        {
                            Feature f = (Feature)item;

                            Debug.Print(swBody.Name + "-->" + f.GetTypeName());

                            if (f.GetTypeName() == "MoveCopyBody")
                            {
                                Ftype = FeatureType.Copy;
                            }
                            if (f.GetTypeName() == "MirrorSolid")
                            {
                                Ftype = FeatureType.Mirror;
                            }
                        }

                        Body2 swOriBody = null;

                        string swOriBodyName = "";
                        string swOriBodyBox  = "";

                        if (Ftype != 0)
                        {
                            try
                            {
                                swOriBody = swBody.GetOriginalPatternedBody(out swMathTrans);

                                swOriBodyName = swOriBody.Name;

                                swOriBodyBox = GetBodyBox(swOriBody);
                            }
                            catch (Exception)
                            {
                            }
                        }

                        string bbox = GetBodyBox(swBody);

                        BodyModel tempBodyM = new BodyModel(swBody.Name, sMatName, swOriBodyName, Ftype, bbox);

                        if (bbox == swOriBodyBox && swBody.Name.ToString().Contains(swOriBodyName.ToString()) == false)
                        {
                            if ((int)tempBodyM.featureT == 0)
                            {
                                listBodies_Normally.Items.Add(tempBodyM.name);
                            }
                            else if ((int)tempBodyM.featureT == 1 && tempBodyM.name.Contains("镜向") == true)     //mirror
                            {
                                listBodies_MirrorCopy.Items.Add(tempBodyM.name + "<--M--" + tempBodyM.refBodyname);
                                tempBodyM.comment = "镜向-" + tempBodyM.refBodyname;
                                //tempBodyM.name = "镜像-" + tempBodyM.refBodyname + "-" ;
                            }
                            else if ((int)tempBodyM.featureT == 2 && (tempBodyM.name.Contains("复制") == true || tempBodyM.name.Contains("阵列") == true))      //copy
                            {
                                listBodies_MirrorCopy.Items.Add(tempBodyM.name + "<--C--" + tempBodyM.refBodyname);

                                tempBodyM.comment = "复制-" + tempBodyM.refBodyname;
                            }
                        }
                        else
                        {
                            listBodies_Normally.Items.Add(tempBodyM.name);
                        }

                        bodyModels.Add(tempBodyM);
                    }
                }
                break;

            case (int)swDocumentTypes_e.swDocASSEMBLY:
                //ProcessAssembly(swApp, swModel);
                break;

            default:
                return;
            }

            Debug.Print(bodyModels.Count.ToString());
        }