/// <summary> /// Creer un percage ou ajouter /// </summary> /// <param name="comp"></param> private void AjouterPercage(Component2 comp = null) { Component2 Comp = comp; if (comp.IsNull()) { Comp = _AssBase.AddComponent5(CompPercage.GetPathName(), (int)swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", true, CompPercage.eNomConfiguration(), 0, 0, 0); } _MdlBase.eSelectByIdComp(Comp.GetSelectByIDString()); _AssBase.eModifierEtatComposant(swComponentSuppressionState_e.swComponentResolved); _MdlBase.eEffacerSelection(); _ListePercage.Add(Comp.Name2, Comp.GetSelectByIDString()); }
/// <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); } }
protected override void Command() { Ass = MdlBase.eAssemblyDoc(); try { CurveDrivenPatternFeatureData def = FonctionRepetition.GetDefinition(); Object[] tabB = def.PatternBodyArray; Body2 b = (Body2)tabB[0]; MathTransform compRepetTrans = ComposantRepetition.Transform2; MathTransform baseMarcheTrans = Marche.Transform2; Vertex v = (Vertex)Point; Edge e = (Edge)Arrete; List <Face2> ListeFace = FonctionRepetition.eListeDesFaces(); Sketch sk = PointMarche.GetSketch(); Feature fPointMarche = (Feature)sk; List <Component2> ListeComposants = new List <Component2>() { Marche }; Double arr = 0.0001; for (int i = 1; i <= (def.D1InstanceCount + def.D2InstanceCount); i++) { MathTransform bodyTrans = def.GetTransform(i); if (bodyTrans.IsNull()) { break; } MathTransform Transform = compRepetTrans.Inverse(); Transform = Transform.Multiply(bodyTrans); Transform = Transform.Multiply(compRepetTrans); Transform = baseMarcheTrans.Multiply(Transform); gPoint pt = new gPoint(v); gSegment sg = new gSegment(e); pt.MultiplyTransfom(bodyTrans); sg.MultiplyTransfom(bodyTrans); Vertex vertex = null; Edge edge = null; foreach (Face2 face in ListeFace) { foreach (Edge ed in face.eListeDesArretes()) { gSegment s = new gSegment(ed); if (sg.Compare(s, arr)) { edge = ed; } if (s.Start.Comparer(pt, arr)) { vertex = ed.GetStartVertex(); } if (s.End.Comparer(pt, arr)) { vertex = ed.GetEndVertex(); } if (edge.IsRef() && vertex.IsRef()) { break; } } if (edge.IsRef() && vertex.IsRef()) { break; } } Entity eVertex = (Entity)vertex; Entity eEdge = (Entity)edge; Component2 cp = Ass.AddComponent5(Marche.GetPathName(), (int)swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", false, "", 0, 0, 0); if (cp.IsNull()) { continue; } // Quand on réinsere un composant, les précédentes contraintes sont recrées. // On les supprime pour eviter des conflits Object[] Mates = cp.GetMates(); if (Mates.IsRef()) { foreach (Feature mate in Mates) { mate.eSelect(); MdlBase.Extension.DeleteSelection2((int)swDeleteSelectionOptions_e.swDelete_Absorbed); } } WindowLog.Ecrire(cp.Name2); cp.Transform2 = Transform; ListeComposants.Add(cp); int longstatus = 0; MdlBase.eEffacerSelection(); eVertex.eSelectEntite(false); Feature f = cp.FeatureByName(fPointMarche.Name); Sketch sketchOrigine = f.GetSpecificFeature2(); Object[] tabPt = sketchOrigine.GetSketchPoints2(); SketchPoint origine = (SketchPoint)tabPt[0]; origine.Select4(true, null); Mate2 mPoint = Ass.AddMate5((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignCLOSEST, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out longstatus); MdlBase.eEffacerSelection(); MdlBase.eEffacerSelection(); eEdge.eSelectEntite(false); cp.FeatureByName(AxeMarche.Name).eSelect(true); Mate2 mAxe = Ass.AddMate5((int)swMateType_e.swMateANGLE, (int)swMateAlign_e.swAlignNONE, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out longstatus); MdlBase.eEffacerSelection(); MdlBase.eEffacerSelection(); Plan.eSelect(false); cp.FeatureByName(PlanMarche.Name).eSelect(true); Mate2 mPlan = Ass.AddMate5((int)swMateType_e.swMatePARALLEL, (int)swMateAlign_e.swAlignNONE, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out longstatus); MdlBase.eEffacerSelection(); Feature m = (Feature)mPoint; WindowLog.Ecrire(" " + m.Name); m = (Feature)mAxe; WindowLog.Ecrire(" " + m.Name); m = (Feature)mPlan; WindowLog.Ecrire(" " + m.Name); } MdlBase.eEffacerSelection(); foreach (var cp in ListeComposants) { cp.eSelectById(MdlBase, -1, true); } Feature Dossier = MdlBase.FeatureManager.InsertFeatureTreeFolder2((int)swFeatureTreeFolderType_e.swFeatureTreeFolder_Containing); Dossier.eRenommerFonction(String.Format("Marches ({0} {1}) ", ComposantRepetition.Name2, FonctionRepetition.Name)); } catch (Exception e) { this.LogErreur(new Object[] { e }); } }
/// <summary> /// /// </summary> /// <param name="assemblyName"></param> /// <param name="partsname"></param> private void CreateNewAssembly(string assemblyName, List <string> partsname) { string assemblyDefaultPath = iswApp.GetDocumentTemplate(2, "", 0, 0, 0); var part = iswApp.NewDocument(assemblyDefaultPath, 0, 0, 0); if (part != null) { AssemblyDoc assemblyDoc = part as AssemblyDoc; ModelDoc2 modelDoc2 = assemblyDoc as ModelDoc2; ModelDocExtension swModExt = default(ModelDocExtension); int errors = 0; int warnings = 0; swModExt = (ModelDocExtension)modelDoc2.Extension; swModExt.SaveAs(assemblyName, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, errors, warnings); modelDoc2 = (ModelDoc2)iswApp.ActiveDoc; int i = 0; int tempV = ProgressBar.Value; foreach (var partN in partsname) { labStatus.Text = "正在装配-->" + Path.GetFileNameWithoutExtension(partN); ProgressBar.Value = tempV + i; iswApp.OpenDoc6(partN.ToString(), 1, 32, "", ref errors, ref warnings); assemblyDoc = (AssemblyDoc)iswApp.ActivateDoc3(System.IO.Path.GetFileNameWithoutExtension(assemblyName) + ".sldasm", true, 0, errors); Component2 swInsertedComponent = default(Component2); swInsertedComponent = assemblyDoc.AddComponent5(partN, 0, "", false, "", 0, 0, 0); modelDoc2 = (ModelDoc2)iswApp.ActiveDoc; modelDoc2.ClearSelection2(true); modelDoc2.Extension.SelectByID2(swInsertedComponent.GetSelectByIDString(), "COMPONENT", 0, 0, 0, false, 0, null, 0); assemblyDoc.UnfixComponent(); modelDoc2.ClearSelection2(true); modelDoc2.Extension.SelectByID2("Point1@Origin@" + swInsertedComponent.GetSelectByIDString(), "EXTSKETCHPOINT", 0, 0, 0, false, 0, null, 0); modelDoc2.Extension.SelectByID2("Point1@Origin", "EXTSKETCHPOINT", 0, 0, 0, true, 0, null, 0); Mate2 mate2 = default(Mate2); mate2 = assemblyDoc.AddMate5(20, -1, false, 0, 0, 0, 0, 0.001, 0, 0, 0, false, false, 0, out int warings); modelDoc2.ClearSelection2(true); modelDoc2.EditRebuild3(); iswApp.CloseDoc(partN); i = i + 1; } iswApp.ActivateDoc3(System.IO.Path.GetFileNameWithoutExtension(assemblyName) + ".sldasm", true, 0, errors); modelDoc2 = (ModelDoc2)iswApp.ActiveDoc; modelDoc2.ShowNamedView2("*等轴测", 7); modelDoc2.ViewZoomtofit2(); modelDoc2.Save(); } ProgressBar.Value = ProgressBar.Maximum; }
static void InsertComponents(AssemblyDoc assembly, ModelDoc2 component1, ModelDoc2 component2) { /* This will insert the components into the newly created * assembly and mate them so their origins are aligned */ ModelDoc2 swModel = (ModelDoc2)assembly; ModelDocExtension swDocExt = swModel.Extension; int mateError; string mateName; string firstSelection = ""; string secondSelection = ""; // Add Component1 swComp1 = assembly.AddComponent5(component1.GetPathName(), (int)swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", false, "", 0, 0, 0); string comp1Name = swComp1.Name2; if (swComp1 == null) { Logger.Warn("Component addition was unsuccessful."); } else { // Logger.Info("Component added successfully."); } // Add Component2 swComp2 = assembly.AddComponent5(component2.GetPathName(), (int)swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", false, "", 0, 0, 0); string comp2Name = swComp2.Name2; if (swComp2 == null) { Logger.Warn("Component addition was unsuccessful."); } else { // Logger.Info("Component added successfully."); } // Add Mate 1 swModel.ClearSelection(); mateName = "Aligned_Origins"; if (lang == "french") { firstSelection = "Point1@Origine@" + comp1Name + "@" + swModel.GetTitle(); secondSelection = "Point1@Origine@" + comp2Name + "@" + swModel.GetTitle(); } else if (lang == "english") { firstSelection = "Point1@Origin@" + comp1Name + "@" + swModel.GetTitle(); secondSelection = "Point1@Origin@" + comp2Name + "@" + swModel.GetTitle(); } else { Logger.Error("VolumeComparator.cs", "InsertComponents()", "Could not create mate since language is not recognized."); } boolstat = swDocExt.SelectByID2(firstSelection, "EXTSKETCHPOINT", 0, 0, 0, false, 1, null, 0); boolstat = swDocExt.SelectByID2(secondSelection, "EXTSKETCHPOINT", 0, 0, 0, true, 1, null, 0); mateFeature = (Feature)assembly.AddMate5((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, (int)swMateWidthOptions_e.swMateWidth_Centered, out mateError); if (mateError != 1) { Logger.Error("VolumeComparator", "InsertComponent", "swAddMateError: " + mateError); } mateFeature.Name = mateName; swModel.ClearSelection(); // Add Mate 2 swModel.ClearSelection(); mateName = "Aligned_Top"; if (lang == "french") { firstSelection = "Plan de dessus@" + comp1Name + "@" + swModel.GetTitle(); secondSelection = "Plan de dessus@" + comp2Name + "@" + swModel.GetTitle(); } else if (lang == "english") { firstSelection = "Top@" + comp1Name + "@" + swModel.GetTitle(); secondSelection = "Top@" + comp2Name + "@" + swModel.GetTitle(); } else { Logger.Error("VolumeComparator.cs", "InsertComponents()", "Could not create mate since language is not recognized."); } boolstat = swDocExt.SelectByID2(firstSelection, "PLANE", 0, 0, 0, false, 1, null, 0); boolstat = swDocExt.SelectByID2(secondSelection, "PLANE", 0, 0, 0, true, 1, null, 0); if (!boolstat) { firstSelection = "Top Plane@" + comp1Name + "@" + swModel.GetTitle(); secondSelection = "Top Plane@" + comp2Name + "@" + swModel.GetTitle(); boolstat = swDocExt.SelectByID2(firstSelection, "PLANE", 0, 0, 0, false, 1, null, 0); boolstat = swDocExt.SelectByID2(secondSelection, "PLANE", 0, 0, 0, true, 1, null, 0); } mateFeature = (Feature)assembly.AddMate5((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, (int)swMateWidthOptions_e.swMateWidth_Centered, out mateError); if (mateError != 1) { Logger.Error("VolumeComparator", "InsertComponent", "swAddMateError: " + mateError); } mateFeature.Name = mateName; swModel.ClearSelection(); // Add Mate 3 swModel.ClearSelection(); mateName = "Aligned_Front"; if (lang == "french") { firstSelection = "Plan de face@" + comp1Name + "@" + swModel.GetTitle(); secondSelection = "Plan de face@" + comp2Name + "@" + swModel.GetTitle(); } else if (lang == "english") { firstSelection = "Front@" + comp1Name + "@" + swModel.GetTitle(); secondSelection = "Front@" + comp2Name + "@" + swModel.GetTitle(); } else { Logger.Error("VolumeComparator.cs", "InsertComponents()", "Could not create mate since language is not recognized."); } boolstat = swDocExt.SelectByID2(firstSelection, "PLANE", 0, 0, 0, false, 1, null, 0); boolstat = swDocExt.SelectByID2(secondSelection, "PLANE", 0, 0, 0, true, 1, null, 0); if (!boolstat) { firstSelection = "Front Plane@" + comp1Name + "@" + swModel.GetTitle(); secondSelection = "Front Plane@" + comp2Name + "@" + swModel.GetTitle(); boolstat = swDocExt.SelectByID2(firstSelection, "PLANE", 0, 0, 0, false, 1, null, 0); boolstat = swDocExt.SelectByID2(secondSelection, "PLANE", 0, 0, 0, true, 1, null, 0); } mateFeature = (Feature)assembly.AddMate5((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, (int)swMateWidthOptions_e.swMateWidth_Centered, out mateError); if (mateError != 1) { Logger.Error("VolumeComparator", "InsertComponent", "swAddMateError: " + mateError); } mateFeature.Name = mateName; swModel.ClearSelection(); }