예제 #1
0
        /// <summary>
        /// 编辑零部件,自动区分装配体还是零件
        /// </summary>
        /// <param name="comp">组件</param>
        /// <param name="doc">顶级文档</param>
        /// <param name="silent">静默编辑--提高速度</param>
        /// <param name="readOnly">只读</param>
        /// <returns></returns>
        public static swEditPartCommandStatus_e Edit(this Component2 comp, AssemblyDoc doc, bool silent = true, bool readOnly = false)
        {
            var type = comp.GetCompType();
            int info = -1;

            switch (type)
            {
            case swDocTemplateTypes_e.swDocTemplateTypePART:
                if (comp.Select2(false, -1))
                {
                    doc.EditPart2(silent, readOnly, ref info);
                }
                break;

            case swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY:
                if (comp.Select2(false, -1))
                {
                    doc.EditAssembly();
                }
                info = 0;
                break;

            default:
                throw new FileFormatException(string.Format("不能编辑此类型的组件:{0} 的类型", type.ToString()));
            }
            swEditPartCommandStatus_e state = (swEditPartCommandStatus_e)info;

            return(state);
        }
예제 #2
0
        private void OnlyKeepNamedBody(string v, string s, AssemblyDoc assemblyDoc, Component2 sendToCustomerBodies, Component2 insertComponentSendtoCustomer, ref bool diff1)
        {
            //var tempswModel = (ModelDoc2)swModel;
            var swModel = (ModelDoc2)swApp.ActiveDoc;

            swModel.Extension.SelectByID2(v + "@" + s, "SOLIDBODY", 0, 0, 0, false, 0, null, 0);

            var myFeature = swModel.FeatureManager.InsertDeleteBody2(true);

            insertComponentSendtoCustomer.Select(false);

            assemblyDoc.InsertCavity4(0, 0, 0, true, 1, -1);
            Feature theFeature;

            var tempPart = (ModelDoc2)sendToCustomerBodies.GetModelDoc2();

            theFeature = (Feature)tempPart.FeatureByPositionReverse(0);

            if (theFeature.Name.Contains("Cavity"))
            {
                //theFeature.Select(true);

                swModel = (ModelDoc2)swApp.ActiveDoc;

                bool b = swModel.Extension.SelectByID2(theFeature.Name + "@" + sendToCustomerBodies.GetSelectByIDString(), "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

                swModel.BreakAllExternalReferences();
                diff1 = true;
                //JoinPart1 留下的: 发给客户的没有此部分。 而本地零件中有
            }
            else
            {
                //无法Join时表示 全切了。
                swModel = (ModelDoc2)swApp.ActiveDoc;

                bool b = swModel.Extension.SelectByID2(theFeature.Name + "@" + sendToCustomerBodies.GetSelectByIDString(), "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

                swModel.EditSuppress();

                theFeature = (Feature)tempPart.FeatureByPositionReverse(1);
                if (theFeature.Name.Contains("Join"))
                {
                    b = swModel.Extension.SelectByID2(theFeature.Name + "@" + sendToCustomerBodies.GetSelectByIDString(), "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

                    swModel.EditSuppress();
                }
            }
            sendToCustomerBodies.Select(true);

            assemblyDoc.EditAssembly();
        }
예제 #3
0
        // Строит или изменяет модель
        public void Build()
        {
            InitAndRunSwApp();
            // имена размеров в документе полумуфты
            string fingerParameter1          = "fingers@Круговой массив1";
            string fingerParameter2          = "fingers@Круговой массив2";
            string nomianalDiameterParameter = "nominalDiameter@Эскиз1";

            // имя полумуфты в сборке (имя компонента верхнего уровня)
            string assemblyPolumuftaName = "Полумуфта-1";
            // Менеджер выделения, выбора
            SelectionMgr swSelMgr = (SelectionMgr)swModel.SelectionManager;

            // удалить выделение
            swModel.ClearSelection2(true);
            Component2 swComp = assembly.GetComponentByName(assemblyPolumuftaName);

            // выбрать полумуфту, не добавлять к выбранным, дата?, показать всплывающее кокшко
            swComp.Select4(false, null, false);
            int info = 0;

            // начать изменение полумуфты
            assembly.EditPart2(false, false, ref info);
            // получить редактируемую модель
            ModelDoc2 polumufta = (ModelDoc2)assembly.GetEditTarget();

            // установка изменяемых параметров для всех конфигураций
            polumufta.Parameter(fingerParameter1).SetSystemValue3(
                countFingers,
                (int)swSetValueInConfiguration_e.swSetValue_InAllConfigurations
                );
            polumufta.Parameter(fingerParameter2).SetSystemValue3(
                countFingers,
                (int)swSetValueInConfiguration_e.swSetValue_InAllConfigurations
                );

            polumufta.Parameter(nomianalDiameterParameter).SetSystemValue3(
                nominalDiameter,
                (int)swSetValueInConfiguration_e.swSetValue_InAllConfigurations
                );
            // ??
            bool retVal = polumufta.EditSuppress2();

            //Debug.Assert(retVal);
            // ??
            assembly.EditAssembly();
            swModel.EditRebuild3();
            swModel.ForceRebuild3(false);
            swModel.ViewZoomtofit2();
        }
예제 #4
0
        private void setLoftTerminalTo(string name)
        {
            IFeature         fov             = fieldOfView.FeatureByName("field of view");
            ILoftFeatureData fieldOfViewLoft = (ILoftFeatureData)fov.GetDefinition();

            fieldOfViewLoft.AccessSelections(swDoc, fieldOfView);

            Object[] fovProfiles    = fieldOfViewLoft.Profiles;
            IFeature sizedSketch    = fieldOfView.FeatureByName(name);
            IFeature originalSketch = fovProfiles[0] as IFeature;

            IFeature[] newProfiles = new IFeature[] { fovProfiles[0] as IFeature, sizedSketch };

            fieldOfViewLoft.Profiles = newProfiles;
            fov.ModifyDefinition(fieldOfViewLoft, swDoc, fieldOfView);

            fieldOfViewLoft.ReleaseSelectionAccess();
            swDoc.EditRebuild3();
            swAssembly.EditAssembly();
        }
예제 #5
0
        public void updateExtrusionDepth(double depthInInches)
        {
            if (depthInInches < 0)
            {
                return;
            }

            double depthInMeters = Utilities.inchesToMeters(depthInInches);

            IDisplayDimension dispDim = (IDisplayDimension)extrusion.GetFirstDisplayDimension();
            IDimension        dim     = dispDim.IGetDimension();

            dim.SetSystemValue3(depthInMeters,
                                (int)swSetValueInConfiguration_e.swSetValue_InSpecificConfigurations,
                                new string[] { belongsTo.ReferencedConfiguration });

            swFeatureMgr.EditRollback((int)swMoveRollbackBarTo_e.swMoveRollbackBarToEnd, extrusion.Name);

            swAssembly.EditRebuild();
            swDoc.EditRebuild3();
            swDoc.ForceRebuild3(false);

            swAssembly.EditAssembly();
        }
예제 #6
0
        public void UpdateFromSelection(SelectionMgr swSelMgr, ref AttributeDef mdefattr_chbody)//, ref AttributeDef defattr_chconveyor)
        {
            // Fetch current properties from the selected part(s) (i.e. ChBody in C::E)
            for (int isel = 1; isel <= swSelMgr.GetSelectedObjectCount2(-1); isel++)
            {
                if ((swSelectType_e)swSelMgr.GetSelectedObjectType3(isel, -1) == swSelectType_e.swSelCOMPONENTS)
                {
                    //Component2 swPart = (Component2)swSelMgr.GetSelectedObject6(isel, -1);
                    Component2 swPart      = swSelMgr.GetSelectedObjectsComponent3(isel, -1);
                    ModelDoc2  swPartModel = (ModelDoc2)swPart.GetModelDoc2();
                    Component2 swPartcorr  = swPartModel.Extension.GetCorresponding(swPart); // ***TODO*** for instanced parts? does not work...
                    swPartcorr = swPart;                                                     // ***TODO***

                    if (swPartModel.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
                    {
                        if (swPart.Solving == (int)swComponentSolvingOption_e.swComponentFlexibleSolving)
                        {
                            System.Windows.Forms.MessageBox.Show("Fexible assemblies not supported as ChBody (set as Rigid?)");
                            return;
                        }
                        if (swPart.Solving == (int)swComponentSolvingOption_e.swComponentRigidSolving)
                        {
                            System.Windows.Forms.MessageBox.Show("Setting props to rigid assembly as ChBody");
                            AssemblyDoc swAssemblyDoc = (AssemblyDoc)swPartModel;
                            swPart.Select(false);
                            swAssemblyDoc.EditAssembly();
                            swAssemblyDoc.EditRebuild();
                            //return;
                        }
                    }

                    // fetch SW attribute with Chrono parameters for ChBody
                    SolidWorks.Interop.sldworks.Attribute myattr = null;
                    if (swPartcorr != null)
                    {
                        myattr = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(mdefattr_chbody, 0);
                    }
                    if (myattr == null)
                    {
                        // if not already added to part, create and attach it
                        //System.Windows.Forms.MessageBox.Show("Create data");
                        myattr = mdefattr_chbody.CreateInstance5(swPartModel, swPartcorr, "Chrono::ChBody_data", 0, (int)swInConfigurationOpts_e.swAllConfiguration);

                        swPartModel.ForceRebuild3(false); // needed, but does not work...
                        //swPartModel.Rebuild((int)swRebuildOptions_e.swRebuildAll); // needed but does not work...

                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityInvalid))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityInvalid!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntitySuppressed))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntitySuppressed!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityAmbiguous))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityAmbiguous!");
                        }
                        if (myattr.GetEntityState((int)swAssociatedEntityStates_e.swIsEntityDeleted))
                        {
                            System.Windows.Forms.MessageBox.Show("swIsEntityDeleted!");
                        }
                    }

                    Set_collision_on(Convert.ToBoolean(((Parameter)myattr.GetParameter(
                                                            "collision_on")).GetDoubleValue()));
                    Set_friction(((Parameter)myattr.GetParameter(
                                      "friction")).GetDoubleValue());
                    Set_rolling_friction(((Parameter)myattr.GetParameter(
                                              "rolling_friction")).GetDoubleValue());
                    Set_spinning_friction(((Parameter)myattr.GetParameter(
                                               "spinning_friction")).GetDoubleValue());
                    Set_restitution(((Parameter)myattr.GetParameter(
                                         "restitution")).GetDoubleValue());
                    Set_collision_envelope(((Parameter)myattr.GetParameter(
                                                "collision_envelope")).GetDoubleValue());
                    Set_collision_margin(((Parameter)myattr.GetParameter(
                                              "collision_margin")).GetDoubleValue());
                    Set_collision_family((int)((Parameter)myattr.GetParameter(
                                                   "collision_family")).GetDoubleValue());



                    // fetch SW attribute with Chrono parameters for ChConveyor

                    /*
                     * SolidWorks.Interop.sldworks.Attribute myattr_conv = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conv == null)
                     * {
                     *  // if not already added to part, create and attach it
                     *  //myattr_conv = defattr_chconveyor.CreateInstance5(swPartModel, swPart, "Chrono::ChConveyor_data", 0, (int)swInConfigurationOpts_e.swThisConfiguration);
                     * }
                     */
                    /*
                     * // fetch SW attribute with Chrono parameters for ChConveyor (if any!)
                     * SolidWorks.Interop.sldworks.Attribute myattr_conveyor = (SolidWorks.Interop.sldworks.Attribute)swPart.FindAttribute(defattr_chconveyor, 0);
                     * if (myattr_conveyor != null)
                     * {
                     *  show_conveyor_params = true;
                     *
                     *  Set_conveyor_speed(((Parameter)myattr_conveyor.GetParameter(
                     *                  "conveyor_speed")).GetDoubleValue());
                     * }
                     */
                }
            }
        }
예제 #7
0
        public static void moveToPosition(Component2 component, int position, double originalPosition)
        {
            /*
             * Buttons have 1 and 0 positions
             * Sliders move along the track from 1 to 0 in 4 steps
             * Dials move in a circle from 0 to 2*pi in 4 steps
             */

            // for now, we will just try to move around the buttons, sliders, and dials, because that is least impossible!
            if (position == -1)
            {
                return;
            }

            // see discussions at
            // https://forum.solidworks.com/message/341157#341157#341157

            double newDistance = 0;

            if (component.Name2.StartsWith("button"))
            {
                if (position == 1)
                {
                    newDistance = Utilities.inchesToMeters(.02);
                }
                else
                {
                    newDistance = originalPosition;
                }
            }
            else if (component.Name2.StartsWith("slider"))
            {
                newDistance = position / 4.0 * originalPosition;
            }
            else if (component.Name2.StartsWith("dial"))
            {
                newDistance = position * Math.PI / 2;
            }

            if (position == 0)
            {
                newDistance = originalPosition;
            }

            Feature mate = swAssembly.FeatureByName(component.Name2 + "-distance");

            if (mate == null)
            {
                return;
            }

            IDisplayDimension dispDim = (IDisplayDimension)mate.GetFirstDisplayDimension();
            IDimension        dim     = dispDim.IGetDimension();

            dim.SetSystemValue3(newDistance,
                                (int)swSetValueInConfiguration_e.swSetValue_InSpecificConfigurations,
                                new string[] { component.ReferencedConfiguration });

            swAssembly.EditRebuild();
            swDoc.ForceRebuild3(false);

            swAssembly.EditAssembly();
        }
예제 #8
0
        private void getModelDoc()
        {
            swDoc = ((ModelDoc2)(swApp.ActiveDoc));
            if (swDoc.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
            {
                swAssembly = ((AssemblyDoc)(swDoc));
            }
            swSelectionMgr    = ((SelectionMgr)(swDoc.SelectionManager));
            swConfMgr         = ((ConfigurationManager)swDoc.ConfigurationManager);
            swConf            = ((Configuration)swConfMgr.ActiveConfiguration);
            swSketchMgr       = ((ISketchManager)swDoc.SketchManager);
            measure           = swDoc.Extension.CreateMeasure();
            measure.ArcOption = 1; // minimum distance
            mathUtils         = swApp.IGetMathUtility();
            swFeatureMgr      = ((FeatureManager)swDoc.FeatureManager);

            mainBody = findComponent(swConf.GetRootComponent3(true), "body");

            if (mainBody == null)
            {
                mainBody = findComponent(swConf.GetRootComponent3(true), "base");
                if (mainBody == null)
                {
                    Utilities.alert("we need a component with 'body' in its name to be the main body");
                }
            }

            allSolidComponents = getAllComponents();
            ourComponents      = getAllOurComponents();
            if (generatedMirrorExtrusions == null)
            {
                generatedMirrorExtrusions = new List <IFeature>();
            }

            swAssembly.EditAssembly();

            InstructionsGenerator.swApp          = swApp;
            InstructionsGenerator.swDoc          = swDoc;
            InstructionsGenerator.swAssembly     = swAssembly;
            InstructionsGenerator.swSelectionMgr = swSelectionMgr;

            RayTracer.swApp          = swApp;
            RayTracer.swDoc          = swDoc;
            RayTracer.swAssembly     = swAssembly;
            RayTracer.swSelectionMgr = swSelectionMgr;
            RayTracer.swSketchMgr    = swSketchMgr;
            RayTracer.mathUtils      = mathUtils;
            RayTracer.visualize      = visualize.Checked;
            RayTracer.ourComponents  = ourComponents;
            RayTracer.camera         = camera;

            Simulator.swApp         = swApp;
            Simulator.swDoc         = swDoc;
            Simulator.swAssembly    = swAssembly;
            Simulator.swFeatureMgr  = swFeatureMgr;
            Simulator.mainBody      = mainBody;
            Simulator.ourComponents = ourComponents;

            Utilities.swApp          = swApp;
            Utilities.swDoc          = swDoc;
            Utilities.swAssembly     = swAssembly;
            Utilities.swSelectionMgr = swSelectionMgr;
            Utilities.swConfMgr      = swConfMgr;
            Utilities.swConf         = swConf;
            Utilities.swFeatureMgr   = swFeatureMgr;
            Utilities.swSketchMgr    = swSketchMgr;
            Utilities.measure        = measure;
            Utilities.mathUtils      = mathUtils;
        }
예제 #9
0
        /// <summary>
        /// 当结果返回True 时 表示两个零件不一样,结果false时表示 两个零件一样
        /// </summary>
        /// <param name="sendTocustomer"></param>
        /// <param name="localModel"></param>
        /// <returns></returns>
        public bool CheckTwoParts(string sendTocustomer, string localModel)
        {
            bool different1 = false;

            bool different2 = false;

            swApp = ConnectToSolidWorks();
            // swApp = ConnectToSolidWorks();

            //加载参考关系零件
            swApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swLoadExternalReferences, (int)swLoadExternalReferences_e.swLoadExternalReferences_ChangedOnly);

            //后台模式 前台不显示界面

            swApp.EnableBackgroundProcessing = true;

            //禁止记录文件路径
            swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swLockRecentDocumentsList, true);

            swApp.OpenDoc(localModel, 1);

            swApp.OpenDoc(sendTocustomer, 1);

            ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;

            string LocalPath = System.IO.Directory.GetParent(swModel.GetPathName()).ToString();

            string tempAssembly = swApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplateAssembly);

            AssemblyDoc assemblyDoc = (AssemblyDoc)swApp.NewDocument(tempAssembly, 0, 0, 0);

            Component2 insertComponentSendtoCustomer = assemblyDoc.AddComponent5(sendTocustomer, 0, "", false, "", 0, 0, 0);
            Component2 insertComponentLocal          = assemblyDoc.AddComponent5(localModel, 0, "", false, "", 0, 0, 0);

            string sendSelect  = insertComponentSendtoCustomer.GetSelectByIDString();
            string localSelect = insertComponentLocal.GetSelectByIDString();

            swModel = (ModelDoc2)swApp.ActiveDoc;

            bool b1 = swModel.Extension.SelectByID2("Point1@Origin" + "@" + sendSelect, "EXTSKETCHPOINT", 0, 0, 0, false, 0, null, 0);
            bool b2 = swModel.Extension.SelectByID2("Point1@Origin" + "@" + localSelect, "EXTSKETCHPOINT", 0, 0, 0, true, 0, null, 0);
            int  longstatus;

            Mate2 mate2 = assemblyDoc.AddMate5(20, -1, false, 0, 0.001, 0.001, 0.001, 0.001, 0, 0, 0, false, false, 0, out longstatus);

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swModel.SaveAs(LocalPath + @"\TopCheck.sldasm");

            //不显示特征树
            //swModel.Extension.HideFeatureManager(true);

            swModel.ClearSelection2(true);
            //swModel.FeatureManager.ViewFeatures = false;

            //FeatureManager featureManager = swModel.FeatureManager;

            //禁用特征树
            //featureManager.EnableFeatureTree = false;

            // swModel.FeatureManager.EnableFeatureTreeWindow = false;

            #region first join

            Component2        sendToCustomerBodies     = default(Component2);
            List <Component2> sendToCustomerBodiesList = new List <Component2>();

            object swFaceOrPlane = default(object);

            assemblyDoc.InsertNewVirtualPart(swFaceOrPlane, out sendToCustomerBodies);

            sendToCustomerBodies.Select(true);

            assemblyDoc.FixComponent();
            sendToCustomerBodies.Select(true);
            assemblyDoc.EditPart();

            insertComponentSendtoCustomer.Select(false);
            insertComponentLocal.Select(true);

            assemblyDoc.InsertJoin2(false, false);

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModel.BreakAllExternalReferences();

            object[] splits = sendToCustomerBodies.Name2.Split('^');
            // string compName = System.IO.Directory.GetParent(swModel.GetPathName()) + "\\" + splits[0];
            string compName = System.IO.Directory.GetParent(swModel.GetPathName()) + "\\" + "localBodies-1";

            ModelDoc2 compModel = default(ModelDoc2);
            compModel = (ModelDoc2)sendToCustomerBodies.GetModelDoc();

            if (compModel.GetType() == (int)swDocumentTypes_e.swDocPART)
            {
                compName = compName + ".sldprt";
            }
            else
            {
                compName = compName + ".sldasm";
            }

            bool ret;

            ret = sendToCustomerBodies.SaveVirtualComponent(compName);

            sendToCustomerBodiesList.Add(sendToCustomerBodies);

            insertComponentSendtoCustomer.Select(false);

            swModel = (ModelDoc2)sendToCustomerBodies.GetModelDoc2();

            #region 获取所有零件中的零件,每一个实体做一次反切

            List <string> bodyNamesCustomer = new List <string>();

            PartDoc swPart = null;
            object  vBody;
            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 + " " + "");

                    bodyNamesCustomer.Add(swBody.Name);
                }
            }

            //如果实体数量大于1,则继续新建对应数量的join 实体。

            OnlyKeepNamedBody(bodyNamesCustomer[0], sendToCustomerBodies.GetSelectByIDString(), assemblyDoc, sendToCustomerBodies, insertComponentSendtoCustomer, ref different1);

            if (bodyNamesCustomer.Count > 1)
            {
                assemblyDoc.EditAssembly();

                for (int i = 0; i < bodyNamesCustomer.Count - 1; i++)
                {
                    Component2 returnpart = default(Component2);
                    var        partSelect = CreateNewJoinPart(assemblyDoc, insertComponentSendtoCustomer, insertComponentLocal, swModel, "localBodies-" + (i + 2), out returnpart);
                    sendToCustomerBodiesList.Add(returnpart);

                    OnlyKeepNamedBody(bodyNamesCustomer[i + 1], partSelect, assemblyDoc, returnpart, insertComponentSendtoCustomer, ref different1);
                }
            }
            // boolstatus = Part.Extension.SelectByID2("Join1[2]@localBodies-1@TopCheck", "SOLIDBODY", 0, 0, 0, True, 0, Nothing, 0)
            //Dim myFeature As Object
            //Set myFeature = Part.FeatureManager.InsertDeleteBody2(True)

            #endregion 获取所有零件中的零件,每一个实体做一次反切

            //assemblyDoc.InsertCavity4(0, 0, 0, true, 1, -1);
            Feature theFeature;

            //theFeature = swModel.FeatureByPositionReverse(0);

            //if (theFeature.Name.Contains("Cavity"))
            //{
            //    //theFeature.Select(true);

            //    swModel = (ModelDoc2)swApp.ActiveDoc;

            //    bool b = swModel.Extension.SelectByID2(theFeature.Name + "@" + sendToCustomerBodies.GetSelectByIDString(), "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

            //    swModel.BreakAllExternalReferences();
            //    different1 = true;
            //    //JoinPart1 留下的: 发给客户的没有此部分。 而本地零件中有
            //}
            //else
            //{
            //    //无法Join时表示 全切了。
            //    swModel = (ModelDoc2)swApp.ActiveDoc;

            //    bool b = swModel.Extension.SelectByID2(theFeature.Name + "@" + sendToCustomerBodies.GetSelectByIDString(), "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

            //    swModel.EditSuppress();
            //}
            //sendToCustomerBodies.Select(true);

            assemblyDoc.EditAssembly();

            #endregion first join

            #region sercond join2

            Component2        localBodies     = default(Component2);
            List <Component2> LocalBodiesList = new List <Component2>();
            assemblyDoc.InsertNewVirtualPart(swFaceOrPlane, out localBodies);

            localBodies.Select(true);

            assemblyDoc.FixComponent();
            localBodies.Select(true);
            assemblyDoc.EditPart();

            insertComponentSendtoCustomer.Select(false);
            insertComponentLocal.Select(true);

            assemblyDoc.InsertJoin2(false, false);

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModel.BreakAllExternalReferences();

            splits = localBodies.Name2.Split('^');
            // string compName = System.IO.Directory.GetParent(swModel.GetPathName()) + "\\" + splits[0];
            compName = System.IO.Directory.GetParent(swModel.GetPathName()) + "\\" + "sendToCustomerBodies-1";

            compModel = default(ModelDoc2);
            compModel = (ModelDoc2)localBodies.GetModelDoc();

            if (compModel.GetType() == (int)swDocumentTypes_e.swDocPART)
            {
                compName = compName + ".sldprt";
            }
            else
            {
                compName = compName + ".sldasm";
            }

            ret = localBodies.SaveVirtualComponent(compName);
            LocalBodiesList.Add(localBodies);
            insertComponentLocal.Select(false);

            swModel = (ModelDoc2)localBodies.GetModelDoc2();

            #region 获取所有零件中的零件,每一个实体做一次反切

            List <string> bodyNamesLocal = new List <string>();

            PartDoc swPart2 = null;
            object  vBody2;
            swPart2 = (PartDoc)swModel;
            // Solid bodies
            object[] vBodyArr2 = null;
            Body2    swBody2   = default(Body2);

            MathTransform swMathTrans2 = null;
            vBodyArr2 = (object[])swPart2.GetBodies2((int)swBodyType_e.swSolidBody, true);

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

                foreach (object vBody_loopVariable in vBodyArr2)
                {
                    vBody2  = vBody_loopVariable;
                    swBody2 = (Body2)vBody2;

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

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

                    bodyNamesLocal.Add(swBody2.Name);
                }
            }

            //如果实体数量大于1,则继续新建对应数量的join 实体。

            OnlyKeepNamedBody(bodyNamesLocal[0], localBodies.GetSelectByIDString(), assemblyDoc, localBodies, insertComponentLocal, ref different2);

            if (bodyNamesLocal.Count > 1)
            {
                assemblyDoc.EditAssembly();

                for (int i = 0; i < bodyNamesLocal.Count - 1; i++)
                {
                    Component2 returnpart = default(Component2);
                    var        partSelect = CreateNewJoinPart(assemblyDoc, insertComponentSendtoCustomer, insertComponentLocal, swModel, "sendToCustomerBodies-" + (i + 2), out returnpart);
                    LocalBodiesList.Add(returnpart);
                    OnlyKeepNamedBody(bodyNamesLocal[i + 1], partSelect, assemblyDoc, returnpart, insertComponentLocal, ref different2);
                }
            }
            // boolstatus = Part.Extension.SelectByID2("Join1[2]@localBodies-1@TopCheck", "SOLIDBODY", 0, 0, 0, True, 0, Nothing, 0)
            //Dim myFeature As Object
            //Set myFeature = Part.FeatureManager.InsertDeleteBody2(True)

            #endregion 获取所有零件中的零件,每一个实体做一次反切

            //assemblyDoc.InsertCavity4(0, 0, 0, true, 1, -1);

            //theFeature = swModel.FeatureByPositionReverse(0);

            //swModel = (ModelDoc2)localBodies.GetModelDoc2();

            //theFeature = swModel.FeatureByPositionReverse(0);

            //if (theFeature.Name.Contains("Cavity"))
            //{
            //    //theFeature.Select(true);

            //    swModel = (ModelDoc2)swApp.ActiveDoc;

            //    bool b = swModel.Extension.SelectByID2(theFeature.Name + "@" + localBodies.GetSelectByIDString(), "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

            //    swModel.BreakAllExternalReferences();
            //    different2 = true;
            //    //JoinPart2 留下的: 发给客户的有此部分。 而本地零件中没有
            //}
            //else
            //{
            //    //无法Join时表示 全切了。
            //    swModel = (ModelDoc2)swApp.ActiveDoc;

            //    bool b = swModel.Extension.SelectByID2(theFeature.Name + "@" + sendToCustomerBodies.GetSelectByIDString(), "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

            //    swModel.EditSuppress();
            //}

            //localBodies.Select(true);

            //assemblyDoc.EditAssembly();

            #endregion sercond join2

            #region joinPartPublic

            Component2 publicBodies = default(Component2);

            assemblyDoc.InsertNewVirtualPart(swFaceOrPlane, out publicBodies);

            publicBodies.Select(true);

            assemblyDoc.FixComponent();
            publicBodies.Select(true);
            assemblyDoc.EditPart();

            insertComponentSendtoCustomer.Select(false);
            insertComponentLocal.Select(true);

            assemblyDoc.InsertJoin2(false, false);

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModel.BreakAllExternalReferences();

            splits = publicBodies.Name2.Split('^');
            // string compName = System.IO.Directory.GetParent(swModel.GetPathName()) + "\\" + splits[0];
            compName = System.IO.Directory.GetParent(swModel.GetPathName()) + "\\" + "publicBodies";

            compModel = default(ModelDoc2);
            compModel = (ModelDoc2)publicBodies.GetModelDoc();

            if (compModel.GetType() == (int)swDocumentTypes_e.swDocPART)
            {
                compName = compName + ".sldprt";
            }
            else
            {
                compName = compName + ".sldasm";
            }

            ret = publicBodies.SaveVirtualComponent(compName);

            swModel.ClearSelection();

            foreach (var item in sendToCustomerBodiesList)
            {
                item.Select(false);

                assemblyDoc.InsertCavity4(0, 0, 0, true, 1, -1);

                theFeature = (Feature)swModel.FeatureByPositionReverse(0);

                swModel    = (ModelDoc2)publicBodies.GetModelDoc2();
                theFeature = (Feature)swModel.FeatureByPositionReverse(0);

                if (theFeature.Name.Contains("Cavity"))
                {
                    //theFeature.Select(true);

                    swModel = (ModelDoc2)swApp.ActiveDoc;

                    bool b = swModel.Extension.SelectByID2(theFeature.Name + "@" + publicBodies.GetSelectByIDString(), "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

                    swModel.BreakAllExternalReferences();

                    //joinPartPublic 留下的: 发给客户的有此部分。 而本地零件中没有
                }
                else
                {
                }
            }
            foreach (var item in LocalBodiesList)
            {
                item.Select(false);

                assemblyDoc.InsertCavity4(0, 0, 0, true, 1, -1);

                theFeature = (Feature)swModel.FeatureByPositionReverse(0);

                swModel    = (ModelDoc2)publicBodies.GetModelDoc2();
                theFeature = (Feature)swModel.FeatureByPositionReverse(0);

                if (theFeature.Name.Contains("Cavity"))
                {
                    //theFeature.Select(true);

                    swModel = (ModelDoc2)swApp.ActiveDoc;

                    bool b = swModel.Extension.SelectByID2(theFeature.Name + "@" + publicBodies.GetSelectByIDString(), "BODYFEATURE", 0, 0, 0, false, 0, null, 0);

                    swModel.BreakAllExternalReferences();

                    //joinPartPublic 留下的: 发给客户的有此部分。 而本地零件中没有
                }
                else
                {
                }
            }

            publicBodies.Select(true);

            assemblyDoc.EditAssembly();

            #endregion joinPartPublic

            foreach (var item in sendToCustomerBodiesList)
            {
                item.Select(false);
                setColour(Color.Red);
            }
            foreach (var item in LocalBodiesList)
            {
                item.Select(false);
                setColour(Color.Blue);
            }

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModel.ClearSelection2(true);

            insertComponentLocal.Select(false);
            insertComponentSendtoCustomer.Select(true);
            swModel.HideComponent2();
            swModel.ClearSelection2(true);

            publicBodies.Select(false);
            assemblyDoc.SetComponentTransparent(true);
            setColour(Color.Green);
            swModel.EditRebuild3();
            swModel.Save();

            swModel.SaveAs3(LocalPath + @"\01_CheckResult.sldprt", 0, 0);

            swApp.CloseDoc("TopCheck.sldasm");
            swApp.CloseAllDocuments(true);
            swApp.OpenDoc(LocalPath + @"\01_CheckResult.sldprt", 1);
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModel.ShowNamedView2("*Isometric", 7);

            swModel.ViewZoomtofit2();

            swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swLockRecentDocumentsList, false);
            try
            {
                System.IO.File.Delete(LocalPath + @"\TopCheck.sldasm");
                System.IO.File.Delete(LocalPath + @"\localBodies.sldprt");
                System.IO.File.Delete(LocalPath + @"\sendToCustomerBodies.sldprt");
                System.IO.File.Delete(LocalPath + @"\publicBodies.sldprt");
            }
            catch (Exception)
            {
            }

            //第二次反向剪切

            swApp.CloseDoc(sendTocustomer);
            swApp.CloseDoc(localModel);

            swModel.FeatureManager.EnableFeatureTree = true;

            swApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swLoadExternalReferences, 2);

            if (different1 == false && different2 == false)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }