void Mate(string name1, string name2, string plane1, string plane2, double dist = 0) { Clear(); double d = abs(dist) * mm; Model.Extension.SelectByID2(plane1 + "@" + name1 + "@temp_assembly", "PLANE", 0, 0, 0, false, 1, null, 0); Model.Extension.SelectByID2(plane2 + "@" + name2 + "@temp_assembly", "PLANE", 0, 0, 0, true, 1, null, 0); swAssembly.AddMate5(5, 0, dist < 0 ? true : false, d, d, d, 0, 0, 0, 0, 0, false, false, 0, out int log); }
/// <summary> /// 轴配合 /// </summary> /// <typeparam name="TAxisOne"></typeparam> /// <typeparam name="TAxisTwo"></typeparam> /// <param name="doc"></param> /// <param name="axisOne"></param> /// <param name="compAxisTwo"></param> /// <param name="mathUtility"></param> /// <param name="comp"></param> /// <returns></returns> public static Mate2 AddAxisCoinMate <TAxisOne, TAxisTwo>(this AssemblyDoc doc, TAxisOne axisOne, TAxisTwo compAxisTwo, MathUtility mathUtility = null, Component2 comp = null) { int mateError = 0; Mate2 swMate = default; SelectEntityOrFeature <TAxisOne>(axisOne, false); SelectEntityOrFeature <TAxisTwo>(compAxisTwo, true); swMate = doc.AddMate5((int)swMateType_e.swMateCOINCIDENT, AxisAlign(axisOne, compAxisTwo, mathUtility, comp).SWToInt(), false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out mateError); return(swMate); }
public static Mate2 AddAxisCoinMate <TAxisOne, TAxisTwo>(this AssemblyDoc doc, TAxisOne axisOne, TAxisTwo axisTwo) { int mateError = 0; Mate2 swMate = default; SelectEntityOrFeature <TAxisOne>(axisOne, false); SelectEntityOrFeature <TAxisTwo>(axisTwo, true); swMate = doc.AddMate5((int)swMateType_e.swMateCOINCIDENT, AxisAlign(axisOne, axisTwo).SWToInt(), false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out mateError); return(swMate); }
private void Contraindre(Feature plan, Face2 e) { AssemblyDoc Ass = MdlBase.eAssemblyDoc(); e.eSelectEntite(MdlBase); plan.eSelect(true); int longstatus = 0; 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.ClearSelection2(true); }
private void Run(Component2 Comp) { try { List <Feature> ListePlanRef; if (CompBase.IsNull()) { ListePlanRef = MdlBase.eListeFonctions(f => { return(f.GetTypeName2() == FeatureType.swTnRefPlane); }); } else { ListePlanRef = CompBase.eListeFonctions(f => { return(f.GetTypeName2() == FeatureType.swTnRefPlane); }); } Log.Message(Comp.Name2); List <Feature> ListePlan = Comp.eListeFonctions(f => { return(f.GetTypeName2() == FeatureType.swTnRefPlane); }); Boolean EstFixe = Comp.IsFixed(); Comp.eLiberer(_Ass); Mate2 FxContrainte = null; int Erreur = 0; for (int i = 0; i < Math.Min(3, Math.Min(ListePlanRef.Count, ListePlan.Count)); i++) { Feature PlanRef = ListePlanRef[i]; Feature Plan = ListePlan[i]; PlanRef.eSelectionnerById2(MdlBase, -1, false); Plan.eSelectionnerById2(MdlBase, -1, true); FxContrainte = _Ass.AddMate5((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, true, 0, out Erreur); } MdlBase.eEffacerSelection(); if (EstFixe || FixerComposant) { Comp.eFixer(_Ass); } } catch (Exception e) { this.LogErreur(new Object[] { e }); } }
public void Main() { ModelDoc2 swDoc; PartDoc swPart = null; DrawingDoc swDrawing = null; AssemblyDoc swAssembly = null; bool boolstatus = false; int longstatus = 0; int longwarnings = 0; string FileLocation = "E:\\My Douments\\MQP\\SOLIDWORKS\\Gear Creation script\\"; //directory for all parts created and modified in this code (Templates should be here) string Gear_Template = "Spur gear - Metric Template.sldprt"; //filename of the spur gear template string Housing = "GEAR_HOUSING_MACRO.sldprt"; //filename for gearbox housing string ASSEMBLY = "GEARBOX_ASSEMBLY_MACRO.sldasm"; //filename for Assembly file string SHAFT_TEMPLATE = "SHAFT_TEMPLATE.sldprt"; int i; //number of gears to create (replace with input data later) //***************************CREATE GEARS*********************************** int num_gears = 5; //number of gears in assembly to generate double[][] Gear_info = new double[num_gears][]; //array of arrays(jagged) to store data about each gear //raw gear data {#teeth, width,shaft,locked to shaft, other gear to mesh with(255 indicates no output),distance from } // 0 1 2 3 4 5 Gear_info[0] = new double[] { 10, 4, 0, 1, 1, 0.000 }; // #teeth, width mm, which shaft to connect to, if locked on shaft, distance between shafts Gear_info[1] = new double[] { 40, 4, 1, 0, 2, 0.000 }; Gear_info[2] = new double[] { 20, 4, 2, 1, 255, 0.000 }; Gear_info[3] = new double[] { 40, 4, 2, 1, 4, 0.004 }; Gear_info[4] = new double[] { 20, 4, 1, 1, 255, 0.004 }; //shaft info double Shaft_Diameter = 1; //diameter in mm (also used for bore dia. in gears) int num_shafts = 3; double Shaft_length = 2 * Gear_info[0][1]; //length of shaft, make slightly larger than width of gear for now double Modulus = .25; //gear modulus for all gears double[] shaft_spacing = new double[] { 4, 5, 8 }; //temporarily use this for the shaft spacing for (i = 0; i < num_gears; i++) //create each gear based off the template { swDoc = ((ModelDoc2)(swApp.OpenDoc6(FileLocation + Gear_Template, 1, 0, "", ref longstatus, ref longwarnings))); double NUM_TEETH = Gear_info[i][0]; Double WIDTH = Gear_info[i][1];// gear depth in mm double SHOW_TEETH = NUM_TEETH; //change sketch dimmensions in the reference sketch: "HoldingSke" ((Dimension)(swDoc.Parameter("Show_teeth@HoldingSke"))).SystemValue = SHOW_TEETH * (3.14159 / 180); //have to convert degrees to radians, num_teeth is saved as angle measurment in the sketch ((Dimension)(swDoc.Parameter("Num_teeth@HoldingSke"))).SystemValue = NUM_TEETH * (3.14159 / 180); //display all the teeth ((Dimension)(swDoc.Parameter("Width@HoldingSke"))).SystemValue = WIDTH / 1000; ((Dimension)(swDoc.Parameter("Bore@HoldingSke"))).SystemValue = Shaft_Diameter / 1000; ((Dimension)(swDoc.Parameter("Module@HoldingSke"))).SystemValue = Modulus / 1000; boolstatus = swDoc.EditRebuild3(); //rebuild the document longstatus = swDoc.SaveAs3(FileLocation + "GEAR_MACRO" + i + ".sldprt", 0, 2); //save gear as gear number i in a new folder called MACRO_PARTS } //***************************CREATE SHAFTS*********************************** for (i = 0; i < num_shafts; i++) { swDoc = ((ModelDoc2)(swApp.OpenDoc6(FileLocation + SHAFT_TEMPLATE, 1, 0, "", ref longstatus, ref longwarnings))); //change sketch dimmensions ((Dimension)(swDoc.Parameter("Diameter@Sketch1"))).SystemValue = Shaft_Diameter / 1000; ((Dimension)(swDoc.Parameter("Shaft Length@Sketch1"))).SystemValue = Shaft_length / 1000; boolstatus = swDoc.EditRebuild3(); //rebuild the document longstatus = swDoc.SaveAs3(FileLocation + "SHAFT_MACRO" + i + ".sldprt", 0, 2); //save gear as gear number i in a new folder called MACRO_PARTS //code to create shafts of set diameters or something } //***************************CREATE ASSEMBLY*********************************** //Open All components to be added for (i = 0; i < num_gears; i++) { swDoc = ((ModelDoc2)(swApp.OpenDoc6(FileLocation + "GEAR_MACRO" + i + ".sldprt", 1, 0, "", ref longstatus, ref longwarnings))); swDoc = ((ModelDoc2)(swApp.OpenDoc6(FileLocation + "SHAFT_MACRO" + i + ".sldprt", 1, 0, "", ref longstatus, ref longwarnings))); } //Open the assembly swDoc = ((ModelDoc2)(swApp.OpenDoc6(FileLocation + "Assembly_Template.SLDASM", 2, 0, "", ref longstatus, ref longwarnings))); swDoc = ((ModelDoc2)(swApp.ActiveDoc)); swApp.ActivateDoc2("Assembly_Template.SLDASM", false, ref longstatus); swAssembly = ((AssemblyDoc)(swDoc)); //add components to SW assembly //****** Currently Parts must already be opened seperately to add to assmebly ******* //***************************SHAFT MATES*********************************** //names of edges and faces in the template: Front Edge ( circle along front) // Surface (cylinder surface of rod) //make face coincident with corresponding hole on housing Mate2 myMate = null; //insert shaft //insert point for mate //align along axis //mate oring to point double[][] Shaft_coord = new double[num_shafts][]; //array of arrays(jagged) to store data about each gear double x; double y; double z; //shaft coords x, y, z Shaft_coord[0] = new double[] { .000, .000, .000 }; Shaft_coord[1] = new double[] { .000, .000, .008 }; Shaft_coord[2] = new double[] { .000, .000, .018 }; //Shaft_coord[3] = new double[] {.019, .000, 0}; for (i = 0; i < num_shafts; i++) { boolstatus = swAssembly.AddComponent(FileLocation + "SHAFT_Macro" + i + ".sldprt", 0, 0, 0); if (i == 0) { swDoc.ClearSelection2(true); boolstatus = swDoc.Extension.SelectByID2("SHAFT_MACRO" + i + "-1@Assembly_Template", "COMPONENT", 0, 0, 0, false, 0, null, 0); swAssembly.UnfixComponent(); } x = Shaft_coord[i][0]; y = Shaft_coord[i][1]; z = Shaft_coord[i][2]; boolstatus = swDoc.Extension.SelectByID2("Shaft coords sketch", "SKETCH", 0, 0, 0, false, 0, null, 0); swDoc.EditSketch(); swDoc.ClearSelection2(true); SketchPoint skPoint = null; skPoint = ((SketchPoint)(swDoc.SketchManager.CreatePoint(x, y, z))); //create a point //have to make point fixed! //make origin coincident to its sketch point boolstatus = swDoc.Extension.SelectByID2("Point" + (i + 11) + "@Shaft coords sketch", "EXTSKETCHPOINT", x, y, z, true, 1, null, 0); boolstatus = swDoc.Extension.SelectByID2("Point1@Origin@SHAFT_MACRO" + i + "-1@Assembly_Template", "EXTSKETCHPOINT", 0, 0, 0, true, 1, null, 0); myMate = null; swAssembly = ((AssemblyDoc)(swDoc)); myMate = ((Mate2)(swAssembly.AddMate5(0, 0, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out longstatus))); swDoc.ClearSelection2(true); swDoc.EditRebuild3(); //parallel to axis boolstatus = swDoc.Extension.SelectByID2("Center Axis@SHAFT_MACRO" + i + "-1@Assembly_Template", "AXIS", 0, 0, 0, false, 0, null, 0); boolstatus = swDoc.Extension.SelectByID2("Line1@Reference Direction", "EXTSKETCHSEGMENT", 0, 0, 0.0021382559642120218, true, 1, null, 0); myMate = null; swAssembly = ((AssemblyDoc)(swDoc)); myMate = ((Mate2)(swAssembly.AddMate5(3, 1, false, 0.0029999999999767309, 0.001, 0.001, 0.001, 0.001, 0, 0.5235987755983, 0.5235987755983, false, false, 0, out longstatus))); swDoc.ClearSelection2(true); swDoc.EditRebuild3(); } //***************************GEAR MATES*********************************** string face_sel; //holds string with name of the face to select for (i = 0; i < num_gears; i++) { Double DistanceMate = Gear_info[i][5]; // gear loacation on shaft boolstatus = swAssembly.AddComponent(FileLocation + "GEAR_MACRO" + i + ".sldprt", -0.5, 0, 0); //Distance mate from edge of shaft boolstatus = swDoc.Extension.SelectByID2("EDGE@GEAR_MACRO" + i + "-1@Assembly_Template", "PLANE", 0, 0, 0, true, 0, null, 0); //face plane of gear boolstatus = swDoc.Extension.SelectByID2("Right@SHAFT_MACRO" + Gear_info[i][2] + "-1@Assembly_Template", "PLANE", 0, 0, 0, true, 0, null, 0); //shaft hole in housing myMate = (Mate2)swAssembly.AddMate5(5, 1, false, DistanceMate, DistanceMate, DistanceMate, 0, 0, 0, 0, 0, false, false, 0, out longstatus); swDoc.ClearSelection2(true); //concentric to shaft boolstatus = swDoc.Extension.SelectByID2("Central Axis@GEAR_MACRO" + i + "-1@Assembly_Template", "AXIS", 0, 0, 0, true, 0, null, 0); //axis of gear boolstatus = swDoc.Extension.SelectByID2("Center Axis@SHAFT_MACRO" + Gear_info[i][2] + "-1@Assembly_Template", "AXIS", 0, 0, 0, true, 0, null, 0); //axis of shaft myMate = (Mate2)swAssembly.AddMate4((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, out longstatus); swDoc.ClearSelection2(true); //lock to shaft if (Gear_info[i][3] == 1) //if gear locked to shaft (make two planes coincident) { boolstatus = swDoc.Extension.SelectByID2("Plane2@GEAR_MACRO" + i + "-1@Assembly_Template", "PLANE", 0, 0, 0, true, 0, null, 0); //face plane of shaft boolstatus = swDoc.Extension.SelectByID2("Front@SHAFT_MACRO" + Gear_info[i][2] + "-1@Assembly_Template", "PLANE", 0, 0, 0, true, 0, null, 0); //shaft hole in housing myMate = (Mate2)swAssembly.AddMate4((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, out longstatus); swDoc.ClearSelection2(true); swDoc.EditRebuild3(); } } //gear mate for (i = 0; i < (num_gears); i++) { if (Gear_info[i][4] != 255) //if -1 that means do not make a gear mate (don't make gear mate for last gear sinc it is output, no gear to mesh to!!!!) { boolstatus = swDoc.Extension.SelectByID2("Central Axis@GEAR_MACRO" + i + "-1@Assembly_Template", "AXIS", 0, 0, 0, true, 0, null, 0); //axis of gear boolstatus = swDoc.Extension.SelectByID2("Central Axis@GEAR_MACRO" + Gear_info[i][4] + "-1@Assembly_Template", "AXIS", 0, 0, 0, true, 0, null, 0); //axis of gear myMate = (Mate2)swAssembly.AddMate4((int)swMateType_e.swMateGEAR, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, Gear_info[i][0], Gear_info[i + 1][0], 0, 0, 0, false, false, out longstatus); //gear mate, specify num. and denom. of gear ratio as #teeth on gear swDoc.ClearSelection2(true); swDoc.EditRebuild3(); } } /* * * * // boolstatus = swDoc.Extension.SelectByID2("", "FACE", -0.00455748224163699, 0.0037205844126901866, 0.004682722786242266, false, 0, null, 0); * // boolstatus = swDoc.Extension.SelectByID2("", "FACE", 0.0018884588073433406, 0.00336302382845588, -0.00060759657679909651, true, 0, null, 1); * // swDoc.ClearSelection2(true); * * boolstatus = swDoc.Extension.SelectByID2("Plane3@30 tooth gear-1@Assem4", "PLANE", 0, 0, 0, true, 0, null, 0); * boolstatus = swDoc.Extension.SelectByID2("Plane3@50 tooth gear-1@Assem4", "PLANE", 0, 0, 0, true, 0, null, 0); * //Mate2 myMate = null; * // swAssembly = ((AssemblyDoc)(swDoc)); * * //add mate to two parts (by selection) * // myMate = (Mate2)swAssembly.AddMate4((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, out longstatus); * // swDoc.ClearSelection2(true); * * * boolstatus = swDoc.Extension.SelectByID2("Bore of@50 tooth gear-1@Assem4", "PLANE", 0, 0, 0, true, 0, null, 0); * * * swDoc.EditRebuild3(); */ }
/// <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); } }
private void Run(Component2 cBase) { if (cBase == null) { this.LogMethode(new String[] { _NomConfigActive }); this.LogMethode(new String[] { "Une reference à un objet a été perdue cBase :", cBase.IsRefToString() }); return; } try { List <Body2> ListeCorps = cBase.eListeCorps(); List <Face2> ListeFace = new List <Face2>(); // Recherche des faces cylindriques foreach (Body2 C in ListeCorps) { foreach (Face2 F in C.eListeDesFaces()) { Surface S = F.GetSurface(); if (S.IsCylinder()) { if (PercageOuvert || (F.GetLoopCount() > 1)) { // Si le diametre == 0 on recupère toutes les faces if ((ListeDiametre.Count == 1) && (ListeDiametre[0] == 0)) { if ((Face == null) || (F.eListeDesFacesContigues().Contains(Face))) { ListeFace.Add(F); } } // Sinon, on verifie qu'elle corresponde bien au diametre demandé else { Double[] ListeParam = (Double[])S.CylinderParams; Double Diam = Math.Round(ListeParam[6] * 2.0 * 1000, 2); if (ListeDiametre.Contains(Diam)) { if ((Face == null) || (F.eListeDesFacesContigues().Contains(Face))) { ListeFace.Add(F); } } } } } } } // S'il n'y a pas assez de composant de perçage, on en rajoute while (_ListePercage.Count < ListeFace.Count) { AjouterPercage(); } _MdlBase.EditRebuild3(); // Mise à jour des références des perçages //ReinitialiserRefListe(ref _ListePercage); List <String> ListeComp = new List <String>(); if (!_DicConfigWithComp.ContainsKey(_NomConfigActive)) { _DicConfigWithComp.Add(_NomConfigActive, ListeComp); } else { ListeComp = _DicConfigWithComp[_NomConfigActive]; } List <String> ListeNomComp = _ListePercage.Keys.ToList(); // Contrainte des perçages for (int i = 0; i < ListeFace.Count; i++) { String NomComp = ListeNomComp[i]; Component2 Comp = _AssBase.GetComponentByName(NomComp); // On active le composant au cas ou :) _MdlBase.eSelectByIdComp(_ListePercage[NomComp]); _AssBase.eModifierEtatComposant(swComponentSuppressionState_e.swComponentResolved); _MdlBase.eEffacerSelection(); Face2 Cylindre = ListeFace[i]; ListeComp.Add(NomComp); //DesactiverContrainte(Comp); _MdlBase.ClearSelection2(true); if (Plan.IsRef()) { Plan.eSelect(); } else if (Face.IsRef()) { Face.eSelectEntite(); } else { Face2 FaceContrainte = FacePlane(Cylindre); // Si on trouve une face pour la contrainte, on sélectionne // Sinon, on passe au trou suivant if (FaceContrainte.IsRef()) { FaceContrainte.eSelectEntite(); } else { continue; } } Feature fPlan = PlanContrainte(Comp); if (fPlan == null) { this.LogMethode(new String[] { "Pas de \"Plan de face\"" }); continue; } fPlan.eSelect(true); int longstatus = 0; _AssBase.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(); Cylindre.eSelectEntite(); Face2 fFace = FaceCylindrique(Comp); fFace.eSelectEntite(true); _AssBase.AddMate5((int)swMateType_e.swMateCONCENTRIC, (int)swMateAlign_e.swMateAlignCLOSEST, false, 0, 0, 0, 0, 0, 0, 0, 0, false, true, 0, out longstatus); _MdlBase.eEffacerSelection(); } } catch (Exception e) { this.LogMethode(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; }
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 }); } }
private void Run(Component2 cBase) { if (cBase == null) { this.LogMethode(new String[] { "Une reference à un objet a été perdue cBase :", cBase.IsRefToString() }); return; } try { List <Body2> ListeCorps = cBase.eListeCorps(); List <Trou> ListeTrou = new List <Trou>(); // Recherche des faces cylindriques foreach (Body2 C in ListeCorps) { // On recherche la face fixe de la tôle Face2 faceFixe = C.eFaceFixeTolerie(); // S'il n'y en a pas c'est que ce n'est pas une tôle if (faceFixe.IsNull()) { continue; } // On recherche les faces de cette tôle var liste = new List <Face2>(); faceFixe.eChercherFacesTangentes(ref liste); // Pour chaque face plane foreach (Face2 faceBase in liste.FindAll(f => ((Surface)f.GetSurface()).IsPlane())) { // On récupère les boucles internes var listePercage = new List <Loop2>(); foreach (Loop2 loop in (Object[])faceBase.GetLoops()) { if (!loop.IsOuter()) { listePercage.Add(loop); } } // Pour chaque boucle interne foreach (var loop in listePercage) { var edge = (Edge)loop.GetEdges()[0]; var facePercage = edge.eAutreFace(faceBase); // On verifie que le perçage est un cylindre // et qu'il débouche bien if (facePercage.eEstUnCylindre() && (facePercage.GetLoopCount() > 1)) { // Si le diametre == 0 on recupère toutes les faces if ((ListeDiametre.Count == 1) && (ListeDiametre[0] == 0)) { ListeTrou.Add(new Trou(facePercage, faceBase)); } // Sinon, on verifie qu'elle corresponde bien au diametre demandé else if (ListeDiametre.Contains(DiametreMm(facePercage))) { ListeTrou.Add(new Trou(facePercage, faceBase)); } } } } } // S'il n'y a pas assez de composant de perçage, on en rajoute while (_ListePercage.Count < ListeTrou.Count) { AjouterPercage(); } MdlBase.EditRebuild3(); List <String> ListeNomComp = _ListePercage.Keys.ToList(); // Contrainte des perçages for (int i = 0; i < ListeTrou.Count; i++) { String NomComp = ListeNomComp[i]; Component2 Comp = _AssBase.GetComponentByName(NomComp); // On active le composant au cas ou :) MdlBase.eSelectByIdComp(_ListePercage[NomComp]); _AssBase.eModifierEtatComposant(swComponentSuppressionState_e.swComponentResolved); MdlBase.eEffacerSelection(); int longstatus = 0; var Trou = ListeTrou[i]; MdlBase.ClearSelection2(true); Trou.Plan.eSelectEntite(); PlanDeFace(Comp).eSelect(true); _AssBase.AddMate5((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out longstatus); MdlBase.eEffacerSelection(); Trou.Cylindre.eSelectEntite(); FaceCylindrique(Comp).eSelectEntite(true); _AssBase.AddMate5((int)swMateType_e.swMateCONCENTRIC, (int)swMateAlign_e.swMateAlignCLOSEST, false, 0, 0, 0, 0, 0, 0, 0, 0, false, true, 0, out longstatus); MdlBase.eEffacerSelection(); } } catch (Exception e) { this.LogMethode(new Object[] { e }); } }
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(); }