Beispiel #1
0
        public static void NewDoc(SldWorks iswApp)
        {
            ModelDoc2     PartDoc  = iswApp.NewDocument(AppDomain.CurrentDomain.BaseDirectory + @"SwFile\PartTemplate.PRTDOT", (int)swDwgPaperSizes_e.swDwgPaperA0size, 10, 10);
            ModelDoc2     AssemDoc = iswApp.NewDocument(AppDomain.CurrentDomain.BaseDirectory + @"SwFile\AssemTemplate.ASMDOT", (int)swDwgPaperSizes_e.swDwgPaperA0size, 10, 10);
            ModelDoc2     DrawDoc  = iswApp.NewDocument(AppDomain.CurrentDomain.BaseDirectory + @"SwFile\DrawingTemplate.DRWDOT", (int)swDwgPaperSizes_e.swDwgPaperA0size, 10, 10);
            StringBuilder Sb       = new StringBuilder();

            if (PartDoc != null)
            {
                Sb.Append("零件新建成功" + PartDoc.GetTitle() + "\r\n");
            }
            else
            {
                Sb.Append("零件新建失败!" + "\r\n");
            }
            if (AssemDoc != null)
            {
                Sb.Append("装配体新建成功" + AssemDoc.GetTitle() + "\r\n");
            }
            else
            {
                Sb.Append("装配体新建失败!" + "\r\n");
            }
            if (DrawDoc != null)
            {
                Sb.Append("图纸新建成功" + DrawDoc.GetTitle() + "\r\n");
            }
            else
            {
                Sb.Append("图纸新建失败!" + "\r\n");
            }
            MessageBox.Show(Sb.ToString().Trim());
        }
Beispiel #2
0
        //                                                     DOCUMENT


        void NewPart()
        {
            sw.NewDocument(@"C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2016\templates\Деталь.prtdot", 0, 0, 0);
            sw.ActivateDoc("");
            Model = sw.ActiveDoc;
            Model.SaveAs3(ApplicationPath + "temp_part" + ".SLDPRT", 0, 0);
            PlaneTop(0); name("Y");
            PlaneRight(0); name("X");
            PlaneFront(0); name("Z");
        }
Beispiel #3
0
        private void createPart()
        {
            swDoc = null;
            int longstatus = 0;

            swDoc = ((ModelDoc2)(sldApp.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2016\\templates\\Part.prtdot", 0, 0, 0)));
            sldApp.ActivateDoc2("Part2", false, ref longstatus);
            swDoc = ((ModelDoc2)(sldApp.ActiveDoc));
            ModelView myModeview = null;

            myModeview            = ((ModelView)(swDoc.ActiveView));
            myModeview.FrameState = ((int)(swWindowState_e.swWindowMaximized));
        }
Beispiel #4
0
        protected int _save()
        {
            ModelDoc2 swDoc;
            int       errors   = 0;
            int       warnings = 0;

            swDoc = ((ModelDoc2)(swApp.NewDocument(template, 0, 0, 0)));
            CustomPropertyManager swCustProp = swDoc.Extension.get_CustomPropertyManager("");

            swCustProp.Set(Settings.Default.propertyName, name);
            swDoc.Extension.SaveAs(Path.Combine(project.workDir, file), (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
            swApp.OnIdleNotify -= new DSldWorksEvents_OnIdleNotifyEventHandler(_save);
            updateDBForm();
            return(0);
        }
Beispiel #5
0
        public static void NewPartTemplate() // Yeni bir part dökümanı açan metodum
        {
            SldWorks  SldWorks = new SldWorks();
            ModelDoc2 swModel;

            swModel = (ModelDoc2)SldWorks.NewDocument("C:\\ProgramData\\SOLIDWORKS\\SOLIDWORKS 2019\\templates\\Parça.prtdot", 0, 0, 0);
        }
        public static void createSWDrawing(bool createDrawBool)
        {
            swApp = SolidWorksSingleton.swApp;
            string pthTemplateFolder = GUI.pthProjFolder + "\\" + "Ξ_SolidWorks Standard Library" + "\\" + "Templates" + "\\" + "RTPi DRW.DRWDOT";

            pthPartAssytoOpen = GUI.pthProjFolder + "\\" + GUI.GUIProj + "\\" + GUI.PartAssySolidWorkstoOpen;

            //if drawing exist open it, otherwise create the drawing.
            if (createDrawBool == false)
            {
                swApp.OpenDoc6(GUI.pthDrwtoOpen, 3, 256, "", 0, 0);
            }
            else
            {
                //create a drawing
                swModel = (ModelDoc2)swApp.NewDocument(pthTemplateFolder, 0, 0, 0);

                //activate drawing
                swDraw = (DrawingDoc)swModel;

                createPartNumber(3);

                //save the part under a specific number
                swModel.SaveAs(saveName);
            }
        }
Beispiel #7
0
 private DrawingDoc CreateDrawing()
 {
     return(sldWorks.NewDocument(
                DrawingTemplatePath,
                (int)swDwgPaperSizes_e.swDwgPaperDsize,
                1,
                1) as DrawingDoc);
 }
Beispiel #8
0
        public void CreatePart()
        {
            string guild = Guid.NewGuid().ToString();
            string root  = @"C:\Users\timos\source\Project\Solution\Project\VenturiPart\" + guild;

            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            else
            {
                throw new ArgumentException("Чертеж уже существует.");
            }
            swApp = GetSolidWorks.GetApplication();
            defaultPartTemplate = swApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);
            swApp.NewDocument(defaultPartTemplate, 0, 0, 0);
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swModel.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, false, 0, null, 0);
            swModel.SketchManager.InsertSketch(true);
            swModel.ClearSelection2(true);
            swModel.SketchManager.CreateCenterLine(0.000000, 0.000000, 0.000000, -0.173611, 0.000000, 0.000000);
            swModel.SketchManager.CreateLine(0.000000, -0.026016, 0.000000, -0.039342, -0.026016, 0.000000);
            swModel.SketchManager.CreateLine(-0.039342, -0.026016, 0.000000, -0.075130, -0.007488, 0.000000);
            swModel.SketchManager.CreateLine(-0.075130, -0.007488, 0.000000, -0.092897, -0.007488, 0.000000);
            swModel.SketchManager.CreateLine(-0.092897, -0.007488, 0.000000, -0.173611, -0.026016, 0.000000);
            swModel.ClearSelection2(true);
            swModel.Extension.SelectByID2("Point8", "SKETCHPOINT", -0.17361079172679997, -0.026016237064323086, 0, false, 0, null, 0);
            swModel.Extension.SelectByID2("Point2", "SKETCHPOINT", -0.17361079172679997, 0, 0, true, 0, null, 0);
            swModel.SketchAddConstraints("sgVERTICALPOINTS2D");
            swModel.Extension.SelectByID2("Point4", "SKETCHPOINT", 0, -0.026016237064323086, 0, false, 0, null, 0);
            swModel.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, true, 0, null, 0);
            swModel.SketchAddConstraints("sgVERTICALPOINTS2D");
            swModel.Extension.SelectByID2("Point4", "SKETCHPOINT", 0, -0.026016237064323086, 0, false, 0, null, 0);
            swModel.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, true, 0, null, 0);
            swModel.ClearSelection2(true);
            swModel.FeatureManager.FeatureRevolve2(true, true, true, false, false, false, 0, 0, 6.2831853071796004, 0, false, false, 0.01, 0.01, 0, 0.005, 0.01, true, true, true);
            swModel.ISelectionManager.EnableContourSelection = false;
            swModel.ViewZoomtofit2();
            swModel.ForceRebuild3(true);
            swModel.SaveAs(PartName + ".SPLDRT");
            swApp = null;
        }
        public void SldConnect()
        {
            try
            {
                System.Diagnostics.Process[] sw = System.Diagnostics.Process.GetProcessesByName("SLDWORKS");
                object processSw = null;
                if (sw.Length > 1) // kill if more then one copy of sw app is runned
                {
                    foreach (System.Diagnostics.Process sw_close in sw)
                    {
                        sw_close.CloseMainWindow();
                        sw_close.Kill();
                    }
                }
                else
                {
                    processSw = System.Activator.CreateInstance(System.Type.GetTypeFromProgID("SldWorks.Application"));
                    // create or get access to the existace proccess
                    if (processSw == null)
                    {
                        MessageBox.Show(@"Looks like You haven't any installed copy of Solidworks yet");
                    }
                }

                SwApp = (SldWorks)processSw;
                if (SwApp == null)
                {
                    return;
                }
                SwApp.Visible     = true;
                SwApp.UserControl = true;
                ////
                SwApp.INewPart();
                SwModel = (ModelDoc2)SwApp.NewDocument(Application.StartupPath + @"tamplate.prtdot", 100, 0, 0);
                SwModel = SwApp.IActiveDoc2;
            }

            catch (Exception)
            {
                MessageBox.Show(@"Can't connect to SolidWorks");
            }
        }
        /// <summary>
        /// Part creation
        /// </summary>

        public void CreateNewPart()
        {
            if (CreatePart.exisCheck == 1)
            {
                //Open existing part
                swApp.OpenDoc6(CreatePart.pthfileName, 1, 1, "", 0, 0);
            }
            else
            {
                //create a part
                PartDoc swPart = swApp.NewDocument(FileManager.pth_PRTTempl, 0, 0, 0);
            }

            assignModelProperties();

            FileManager.create_PartAssyDrawNumber(1);

            //Save the part under a specific number
            swModel.SaveAs(FileManager.pth_SaveName);
        }
Beispiel #11
0
        static void CreateRevolve()
        {
            SldWorks          swApp = new SldWorks();
            ModelDoc2         swModel;
            ModelDocExtension swModelDocExt;
            FeatureManager    swFeatMgr;
            SelectionMgr      swSelMgr;

            bool boolstatus;

            swModel = (ModelDoc2)swApp.NewDocument("C:\\Users\\nemati\\Documents\\Visual Studio 2015\\Projects\\SWBlankApp\\SWBlankApp\\PartTemplate.SLDPRT", 0, 0, 0);
            //swModel = (ModelDoc2)swApp.ActiveDoc;
            swModelDocExt = swModel.Extension;
            swSelMgr      = (SelectionMgr)swModel.SelectionManager;

            boolstatus = swModelDocExt.SelectByID2("Right Plane", "PLANE", 0, 0, 0, true, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", 0, 0, 0, true, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            swModel.InsertAxis2(true);


            boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", -0.08954836342753, 0.0004336873289503, 0.006720765739942, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            swModel.InsertSketch2(true);
            swModel.ClearSelection2(true);
            swModel.SketchRectangle(-0.05, -0.05, 0, 0, 0.1, 0, true);

            swModel.InsertSketch2(true);
            swModel.ShowNamedView2("*Trimetric", 8);

            boolstatus = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault);
            boolstatus = swModelDocExt.SelectByID2("Axis1", "AXIS", 0, 0, 0, true, 4, null, (int)swSelectOption_e.swSelectOptionDefault);
            swFeatMgr  = swModel.FeatureManager;

            swFeatMgr.FeatureRevolve2(true, true, false, false, false, false, 0, 0, 6.28318530718, 0, false,
                                      false, 0.01, 0.01, 0, 0, 0, true, true, true);


            swModel.SaveAs("C:\\Users\\nemati\\Documents\\Visual Studio 2015\\Projects\\SWBlankApp\\SWBlankApp\\FeatureRevolve.SLDPRT");

            swApp.ExitApp();
        }
Beispiel #12
0
        /// <summary>
        /// Create a part using the standard template
        /// </summary>
        /// <returns></returns>
        protected IModelDoc2 CreatePartDoc()
        {
            var partTemplateName = SwApp.GetUserPreferenceStringValue((int)swUserPreferenceStringValue_e.swDefaultTemplatePart);

            return((IModelDoc2)SwApp.NewDocument(partTemplateName, 0, 0, 0));
        }
Beispiel #13
0
        //Microsoft.Office.Interop.MSProject


        //string[] args
        static void CreateSketch()
        {
            SldWorks swApp = new SldWorks();
            //Feature myFeature;
            ModelDoc2 swModel = default(ModelDoc2);
            //RefPlane myRefPlane;
            SketchManager  swSkMgr = default(SketchManager);
            FeatureManager swFeMgr = default(FeatureManager);

            //Feature swFeat;
            //Sketch swSketch;
            int  longstatus = 0;
            bool boolstatus = false;

            swApp.ResetUntitledCount(0, 0, 0);

            swModel = (ModelDoc2)swApp.NewDocument("C:\\Users\\nemati\\Documents\\Visual Studio 2015\\Projects\\SWBlankApp\\SWBlankApp\\PartTemplate.SLDPRT", 0, 0, 0);
            swApp.ActivateDoc2("Part1", false, ref longstatus);
            swModel = (ModelDoc2)swApp.ActiveDoc;


            swSkMgr = swModel.SketchManager;
            swFeMgr = swModel.FeatureManager;
            swSkMgr.InsertSketch(true);
            //swFeMgr.FeatureExtruRefSurface()
            boolstatus = swModel.Extension.SelectByID2("Top Plane", "PLANE", -0.0553489443349025, 0.00330468607538553, 0.0269617286188933, false, 0, null, 0);
            swModel.ClearSelection2(true);


            if (swModel == null)
            {
                swApp.SendMsgToUser2("Ridi.", (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk);
                return;
            }

            int modelType = 0;

            modelType = swModel.GetType();

            if (modelType != (int)swDocumentTypes_e.swDocPART)
            {
                swApp.SendMsgToUser2("A part document must be active.", (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk);
                return;
            }

            // Creating sample point
            SketchPoint skPoint = default(SketchPoint);

            skPoint = swSkMgr.CreatePoint(-100, 100, 0);


            // Creating sample arc
            SketchSegment skArc = default(SketchSegment);

            skArc = swSkMgr.Create3PointArc(0, 0, 0, 10, 10, 0, -10, 10, 0);


            // Creating sample circle
            SketchSegment skCircle = default(SketchSegment);

            skCircle = swSkMgr.CreateCircleByRadius(-20, 20, 0, 7.5);


            swSkMgr.InsertSketch(true);



            //swModel.SketchCircle();

            Console.WriteLine(swApp.Visible.ToString());

            Console.WriteLine(swApp.FrameWidth.ToString());

            //swApp.CreateNewWindow();

            swModel.SaveAs("C:\\Users\\nemati\\Documents\\Visual Studio 2015\\Projects\\SWBlankApp\\SWBlankApp\\SketchArc.SLDPRT");


            //swApp.

            swApp.ExitApp();

            //swApp = null;

            //swApp
        }
 /// <summary>
 /// 通过模板创建新零件或者新项目
 /// </summary>
 /// <param name="app"></param>
 /// <param name="TemFilePath">*.asmdot 或者 *.prtdot</param>
 /// <returns></returns>
 public static ModelDoc2 NewPartOrAssembly(this SldWorks app, string TemFilePath)
 {
     return(app.NewDocument(TemFilePath, (int)swDwgPaperSizes_e.swDwgPaperA4size, 100, 100) as ModelDoc2);
 }
Beispiel #15
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);
            }
        }