/// <summary> /// 递归遍历装配体方法 /// </summary> /// <param name="swComp"></param> /// <param name="nLevel"></param> private void TraverseAssembly(Component2 swComp, int nLevel) { object[] vChildComp; Component2 swChildComp; vChildComp = (object[])swComp.GetChildren(); for (int i = 0; i < vChildComp.Length; i++) { swChildComp = (Component2)vChildComp[i]; AssemblyDoc swTempModel = (AssemblyDoc)swChildComp; TraverseAssembly(swChildComp, nLevel + 1); //选中要替换掉的零件 SelectData seldate = ((SelectionMgr)swModel.SelectionManager).CreateSelectData(); swChildComp.Select4(false, seldate, false); //替换零部件 swTempModel.ReplaceComponents("", "", true, true);//零件地址 } //object[] compNum = null; //int idex=1; ////_swApp = (SldWorks)MD_SW_ConnectSW.ConnectSW.iSwApp; //compNum = swApp.GetDocumentDependencies2(parentPath, false, false, false); //if (compNum != null) //{ // while (idex <= compNum.GetUpperBound(0)) // { // string path = compNum[idex].ToString(); // idex++; // } //} }
private void Replace(ModelDoc2 swModel) { swAssembly = (AssemblyDoc)swModel; swAssembly.ReplaceComponents(@"C:\ELETROFRIO\ENGENHARIA SMR\PRODUTOS FINAIS ELETROFRIO\MECÂNICA\RACK PADRAO\COLETOR SUCCAO\2047907.SLDPRT", "", true, true); }
private void ReplaceBolsaCP(Coletor coletor) { swApp.ActivateDoc(coletor.CodigoColetor + ".SLDASM"); swModel = swApp.ActiveDoc; AssemblyDoc swAssembly = (AssemblyDoc)swModel; Object[] components = swAssembly.GetComponents(true); foreach (var componente in components) { Component2 component = (Component2)componente; swModel = component.GetModelDoc2(); string nomeCompletoDoComponente = swModel.GetPathName(); string nomeComExtensao = Path.GetFileName(nomeCompletoDoComponente); if (String.Equals(nomeComExtensao, "BOLSA SOLDA SUCCAO CP TEMPLATE.SLDPRT")) { component.Select(true); break; } } swAssembly.ReplaceComponents($@"C:\ELETROFRIO\ENGENHARIA SMR\PRODUTOS FINAIS ELETROFRIO\MECÂNICA\RACK PADRAO\COLETOR SUCCAO\{coletor.CodigoBolsaSoldaSuccaoCompressor}.SLDPRT", "", true, true); swModel = swApp.ActiveDoc; swModel.Save(); }
public void SaveAs() { IModelDoc2 modDoc = (IModelDoc2)iSwApp.ActiveDoc; ModelDocExtension mDocExten; IModelDoc2 swModel; AssemblyDoc asmDoc = (AssemblyDoc)modDoc; SelectionMgr selectionMgr = modDoc.SelectionManager; Component2 component; string path; string recentPath; int errors = 0; int warnings = 0; recentPath = iSwApp.GetRecentFiles()[0].Substring(0, modDoc.GetPathName().LastIndexOf("\\")); int looptime = selectionMgr.GetSelectedObjectCount2(-1); while (looptime >= 1) { try { looptime--; component = selectionMgr.GetSelectedObject6(looptime + 1, -1); swModel = (IModelDoc2)component.GetModelDoc2(); mDocExten = swModel.Extension; //todo:校核是否是零件类,现在是直接抛出 //另存为对话框 SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "另存为"; sfd.InitialDirectory = recentPath;//更改为最近使用 sfd.Filter = "零件| *.sldprt"; sfd.ShowDialog(); path = sfd.FileName; if (path == "") { return; } //另存为新零件 mDocExten.SaveAs(path, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Copy, null, ref errors, ref warnings); //替换现有零件 asmDoc.ReplaceComponents(path, "", false, true); } catch { } } }
public string Build(SpigotType_e type, int width, int height) { string modelName = GetModelName(type); NewSpigotName = GetSpigotName(type, width, height); Dimension dimension; int addDimH = modelName == "12-30" ? 10 : 1; string newSpigotPath = $@"{RootFolder}{SubjectDestinationFolder}\{NewSpigotName}"; string drawingName = modelName == "12-30" ? modelName : "12-00"; var modelSpigotDrw = $@"{RootFolder}{SourceFolder}\{drawingName}.SLDDRW"; ModelDoc2 swDrawingSpigot = SolidWorksAdapter.OpenDocument(modelSpigotDrw, swDocumentTypes_e.swDocDRAWING); solidWorksDocument = SolidWorksAdapter.AcativeteDoc("12-00"); AssemblyDoc assemblyDocument = (AssemblyDoc)solidWorksDocument; assemblyDocument.ResolveAllLightWeightComponents(false); DeleteEquations(modelName); solidWorksDocument.ForceRebuild3(true); #region formuls var w = (Convert.ToDouble(width) - 1) / 1000; // ???????????? var h = Convert.ToDouble((Convert.ToDouble(height) + addDimH) / 1000); // ???????????? const double step = 50; var weldWidth = Convert.ToDouble((Math.Truncate(Convert.ToDouble(width) / step) + 1)); // ???????????? var weldHeight = Convert.ToDouble((Math.Truncate(Convert.ToDouble(height) / step) + 1)); // ???????????? #endregion DeleteComponents((int)type); if (modelName == "12-20") { PartName = $"12-20-{height}.SLDPRT"; if (CheckExistPart != null) { CheckExistPart(PartName, out IsPartExist, out NewPartPath); } else { MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning); } if (IsPartExist) { solidWorksDocument.Extension.SelectByID2("12-20-001-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); assemblyDocument.ReplaceComponents(NewPartPath, "", true, true); } else { NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}"; solidWorksDocument.Extension.SelectByID2("D1@Вытянуть1@12-20-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D1@Вытянуть[email protected]"))); dimension.SystemValue = h - 0.031; solidWorksDocument.Extension.SelectByID2("D1@Кривая1@12-20-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D1@Кривая[email protected]"))); dimension.SystemValue = weldHeight; SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning); InitiatorSaveExeption(error, warning, NewPartPath); ComponentsPathList.Add(NewPartPath); SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(NewPartPath); } //12-20-002 PartName = $"12-20-{width}.SLDPRT"; MessageObserver.Instance.SetMessage("Check exist part. " + NewPartPath); if (CheckExistPart != null) { MessageObserver.Instance.SetMessage("\tCheckExistPartEvent"); CheckExistPart(PartName, out IsPartExist, out NewPartPath); } else { MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning); } if (IsPartExist) { solidWorksDocument.Extension.SelectByID2("12-20-002-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); assemblyDocument.ReplaceComponents(PartName, "", true, true); } else { NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}"; solidWorksDocument.Extension.SelectByID2("D1@Вытянуть1@12-20-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D1@Вытянуть[email protected]"))); dimension.SystemValue = w - 0.031; solidWorksDocument.Extension.SelectByID2("D1@Кривая1@12-20-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D1@Кривая[email protected]"))); dimension.SystemValue = weldWidth; SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning); InitiatorSaveExeption(error, warning, NewPartPath); ComponentsPathList.Add(NewPartPath); } //12-003 PartName = $"12-03-{width}-{height}.SLDPRT"; if (CheckExistPart != null) { CheckExistPart(PartName, out IsPartExist, out NewPartPath); } else { MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning); } if (IsPartExist) { solidWorksDocument.Extension.SelectByID2("12-003-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); assemblyDocument.ReplaceComponents(PartName, "", true, true); } else { NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}"; solidWorksDocument.Extension.SelectByID2("D3@Эскиз1@12-003-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D3@Эскиз[email protected]"))); dimension.SystemValue = w; solidWorksDocument.Extension.SelectByID2("D2@Эскиз1@12-003-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D2@Эскиз[email protected]"))); dimension.SystemValue = h; solidWorksDocument.EditRebuild3(); SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning); InitiatorSaveExeption(error, warning, NewPartPath); ComponentsPathList.Add(NewPartPath); SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(NewPartPath); } } if (modelName == "12-30") { //12-30-001 PartName = $"12-30-{height}.SLDPRT"; MessageObserver.Instance.SetMessage("Check exist part. " + NewPartPath); if (CheckExistPart != null) { CheckExistPart(PartName, out IsPartExist, out NewPartPath); } else { MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning); } if (IsPartExist) { solidWorksDocument.Extension.SelectByID2("12-30-001-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); assemblyDocument.ReplaceComponents(PartName, "", true, true); } else { NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}"; solidWorksDocument.Extension.SelectByID2("D1@Вытянуть1@12-30-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D1@Вытянуть[email protected]"))); dimension.SystemValue = h - 0.031; solidWorksDocument.Extension.SelectByID2("D1@Кривая1@12-30-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D1@Кривая[email protected]"))); dimension.SystemValue = weldHeight; SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning); InitiatorSaveExeption(error, warning, NewPartPath); ComponentsPathList.Add(NewPartPath); } //12-30-002 PartName = $"12-30-{width}.SLDPRT"; if (CheckExistPart != null) { CheckExistPart(PartName, out IsPartExist, out NewPartPath); } else { MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning); } if (IsPartExist) { solidWorksDocument.Extension.SelectByID2("12-30-002-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); assemblyDocument.ReplaceComponents(PartName, "", true, true); } else { NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}"; solidWorksDocument.Extension.SelectByID2("D1@Вытянуть1@12-30-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D1@Вытянуть[email protected]"))); dimension.SystemValue = w - 0.031; solidWorksDocument.Extension.SelectByID2("D1@Кривая1@12-30-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D1@Кривая[email protected]"))); dimension.SystemValue = weldHeight; SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning); InitiatorSaveExeption(error, warning, NewPartPath); ComponentsPathList.Add(NewPartPath); } //12-003 PartName = $"12-03-{width}-{height}.SLDPRT"; if (CheckExistPart != null) { CheckExistPart(PartName, out IsPartExist, out NewPartPath); } else { MessageObserver.Instance.SetMessage("CheckExistPartEvent can not be null", MessageType.Warning); } if (IsPartExist) { solidWorksDocument.Extension.SelectByID2("12-003-2@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); assemblyDocument.ReplaceComponents(PartName, "", true, true); } else { NewPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{NewPartPath}"; solidWorksDocument.Extension.SelectByID2("D3@Эскиз1@12-003-2@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D3@Эскиз[email protected]"))); dimension.SystemValue = w; solidWorksDocument.Extension.SelectByID2("D2@Эскиз1@12-003-2@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); dimension = ((Dimension)(solidWorksDocument.Parameter("D2@Эскиз[email protected]"))); dimension.SystemValue = h; solidWorksDocument.EditRebuild3(); SolidWorksDocument.Extension.SaveAs(NewPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning); InitiatorSaveExeption(error, warning, NewPartPath); ComponentsPathList.Add(NewPartPath); } } solidWorksDocument.ForceRebuild3(true); solidWorksDocument.Extension.SaveAs(newSpigotPath + ".SLDASM", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning); InitiatorSaveExeption(error, warning, newSpigotPath + ".SLDASM"); SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(NewSpigotName + ".SLDASM"); ComponentsPathList.Add(newSpigotPath + ".SLDASM"); swDrawingSpigot.Extension.SelectByID2("DRW1", "SHEET", 0, 0, 0, false, 0, null, 0); var drw = (DrawingDoc)SolidWorksAdapter.AcativeteDoc(drawingName + ".SLDDRW"); drw.ActivateSheet("DRW1"); drw.SetupSheet5("DRW1", 12, 12, 1, GetDrawingScale(width, height), true, @"\\pdmsrv\SolidWorks Admin\Templates\Основные надписи\A3-A-1.slddrt", 0.42, 0.297, "По умолчанию", false); swDrawingSpigot.Extension.SaveAs(newSpigotPath + ".SLDDRW", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref error, ref warning); InitiatorSaveExeption(error, warning, newSpigotPath + ".SLDDRW"); ComponentsPathList.Add(newSpigotPath + ".SLDDRW"); SolidWorksAdapter.CloseAllDocumentsAndExit(); return(newSpigotPath); }
private void btnAssem1_Click(object sender, EventArgs e) { if (swApp == null) { swApp = (SldWorks)ConnectSW.iSwApp; } List <string> fileAssem1 = new List <string>(); //文件路径集合 string carrerPath = string.Empty; //行星架路径 string planetaryPath = string.Empty; //行星轮路径 string outShaftPath = string.Empty; //输出轴路径 string pineShaftPath = string.Empty; //销轴路径 //获取界面中的文件并打开 int Rows = this.lBoxAssem1.Items.Count; //行的数量 if (Rows == 0) { MessageBox.Show("请选择装配零部件!"); return; } foreach (object item in lBoxAssem1.Items) { fileAssem1.Add(item.ToString()); //界面中的文件 } foreach (string file in fileAssem1) //遍历文件获取路径 { string fileName = file.Substring(file.LastIndexOf("\\") + 1); if (fileName.Contains("架")) { carrerPath = file; } if (fileName.Contains("行星轮")) { planetaryPath = file; } if (fileName.Contains("输出")) { outShaftPath = file; } if (fileName.Contains("销轴")) { pineShaftPath = file; } //swModel = (ModelDoc2)swApp.OpenDoc6(file, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); } //实现装配 //打开装配模板(行星架+输出轴+销轴+行星轮+行星轮垫片+轴承)然后替换相关零部件 swModel = (ModelDoc2)swApp.OpenDoc6(_exePath + "PrtAndAsmTemp\\subAssemly.sldasm", (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); //遍历装配体选择零部件 swModel = (ModelDoc2)swApp.ActiveDoc; swConfMgr = (SolidWorks.Interop.sldworks.ConfigurationManager)swModel.ConfigurationManager; swConf = (SolidWorks.Interop.sldworks.Configuration)swConfMgr.ActiveConfiguration; swRootComp = (Component2)swConf.GetRootComponent(); //TraverseAssembly(swRootComp, 1); object[] vChildComp; Component2 swChildComp; vChildComp = (object[])swRootComp.GetChildren(); AssemblyDoc swTempAssem = (AssemblyDoc)swModel; for (int i = 0; i < vChildComp.Length; i++) { swChildComp = (Component2)vChildComp[i]; string compName = swChildComp.Name2; ModelDoc2 swModelTemp = swChildComp.GetModelDoc2(); //转换成ModelDoc2 //选中要替换掉的零件 SelectData seldate = ((SelectionMgr)swModelTemp.SelectionManager).CreateSelectData(); swChildComp.Select4(false, seldate, false); //替换零部件 if (compName == "行星架-1") { bool isTrue = swTempAssem.ReplaceComponents(carrerPath, "", true, true); //零件地址 } if (compName == "行星轮-1") { swTempAssem.ReplaceComponents(planetaryPath, "", true, true); //零件地址 } if (compName == "输出轴-1") { swTempAssem.ReplaceComponents(outShaftPath, "", true, true); //零件地址 } if (compName == "销轴-1") { swTempAssem.ReplaceComponents(pineShaftPath, "", true, true); //零件地址 } if (compName == "行星架垫片-1") { swTempAssem.ReplaceComponents("", "", true, true); //零件地址 } } swModel.EditRebuild3(); }
private void btnAssembly_Click_1(object sender, EventArgs e) { if (swApp == null) { ConnectSw(); } List <string> fileAssem1 = new List <string>(); //文件路径集合 int Rows = this.lBoxFile3.Items.Count; //行的数量 if (Rows == 0) { MessageBox.Show("请选择装配零部件!"); return; } string FaLan = string.Empty; //电机法兰路径 string InnerGearPath = string.Empty; //内齿轮路径 string standPath = string.Empty; //机座路径 string subAssemPath = string.Empty; //子装配体路径 foreach (object item in lBoxFile3.Items) { fileAssem1.Add(item.ToString()); //界面中的文件 } foreach (string file in fileAssem1) //遍历文件获取路径 { string fileName = file.Substring(file.LastIndexOf("\\") + 1); if (fileName.Contains("法兰")) { FaLan = file; } if (fileName.Contains("内齿")) { InnerGearPath = file; } if (fileName.Contains("机座")) { standPath = file; } if (fileName.Contains("子装配")) { subAssemPath = file; } } swModel = (ModelDoc2)swApp.OpenDoc6(_exePath + "PrtAndAsmTemp\\总装配体.sldasm", (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); //遍历装配体选择零部件 swModel = (ModelDoc2)swApp.ActiveDoc; swConfMgr = (SolidWorks.Interop.sldworks.ConfigurationManager)swModel.ConfigurationManager; swConf = (SolidWorks.Interop.sldworks.Configuration)swConfMgr.ActiveConfiguration; swRootComp = (Component2)swConf.GetRootComponent(); object[] vChildComp; Component2 swChildComp; vChildComp = (object[])swRootComp.GetChildren(); AssemblyDoc swTempAssem = (AssemblyDoc)swModel; for (int i = 0; i < vChildComp.Length; i++) { swChildComp = (Component2)vChildComp[i]; string compName = swChildComp.Name2; ModelDoc2 swModelTemp = swChildComp.GetModelDoc2();//转换成ModelDoc2 //选中要替换掉的零件 SelectData seldate = ((SelectionMgr)swModelTemp.SelectionManager).CreateSelectData(); swChildComp.Select4(false, seldate, false); //替换零部件 if (compName == "电机法兰-1") { bool isTrue = swTempAssem.ReplaceComponents(FaLan, "", true, true);//零件地址 } if (compName == "内齿轮-1") { swTempAssem.ReplaceComponents(InnerGearPath, "", true, true);//零件地址 } if (compName == "立机座-1") { swTempAssem.ReplaceComponents(standPath, "", true, true);//零件地址 } if (compName == "子装配2-1") { swTempAssem.ReplaceComponents(subAssemPath, "", true, true);//轴套子装配地址 } if (compName == "subAssemly-1") { swTempAssem.ReplaceComponents("", "", true, true);//行星架子装配 } } swModel.EditRebuild3(); }
public string Build(RoofType_e type, int width, int lenght, bool onlyPath) { string newPartPath = string.Empty; string modelName; switch (type) { case RoofType_e.One: case RoofType_e.Two: case RoofType_e.Three: case RoofType_e.Four: case RoofType_e.Five: case RoofType_e.Six: modelName = "15-000"; break; default: modelName = "15-000"; break; } string newRoofName = "15-0" + type + "-" + width + "-" + lenght; string newRoofPath = $@"{RootFolder}{SubjectDestinationFolder}\{newRoofName}.SLDASM"; bool IsExistPart = false; CheckExistPart(newRoofName + ".SLDASM", out IsExistPart, out newRoofPath); var modelRoofPath = $@"{RootFolder}{SourceFolder}\{modelName}.SLDASM"; solidWorksDocument = SolidWorksAdapter.SldWoksAppExemplare.OpenDoc6(modelRoofPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel + (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "00", 0, 0); AssemblyDoc solidWorcsAssemvlyDocyment = (AssemblyDoc)solidWorksDocument; solidWorcsAssemvlyDocyment.ResolveAllLightWeightComponents(false); DeleteComponents((int)type); #region Сохранение и изменение элементов var addwidth = 100; var addwidth2 = 75; var type4 = 0; var divwidth = 1; if (type == RoofType_e.Two || type == RoofType_e.Six) { addwidth = 75; divwidth = 2; } if (type == RoofType_e.Four) { type4 = 170; addwidth2 = 170 + 75; } var widthD = (Convert.ToDouble(width) / divwidth + addwidth); var lengthD = (Convert.ToDouble(lenght) - 28.5); const double step = 200; const double step2 = 150; var weldW = Convert.ToDouble((Math.Truncate(Convert.ToDouble(lenght) / step) + 1)); var weldW2 = Convert.ToDouble((Math.Truncate(Convert.ToDouble(lenght) / step2) + 1)); var newComponents = new List <FileInfo>(); //15-001 SolidWorksAdapter.SldWoksAppExemplare.IActivateDoc2("15-001", true, 0); var newPartName = $"15-0{type}-01-{width}-{lenght}"; CheckExistPart(newPartName, out IsExistPart, out newPartPath); if (IsExistPart) { solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0))); solidWorksDocument.Extension.SelectByID2("15-001-1@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorcsAssemvlyDocyment.ReplaceComponents(newPartPath, "", true, true); SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("15-001.SLDPRT"); } else { newPartPath = $@"{SourceFolder}\{SubjectDestinationFolder}\{newPartName}.SLDPRT"; //EditPartParameters("15-001", // $@"{RootFolder}\{SubjectDestinationFolder}\{newPartName}", // new[,] // { // {"D1@Эскиз1", type == RoofType.Five || type == RoofType.Six ? Convert.ToString(140 + lengthD + type4) : Convert.ToString(lengthD + type4)}, // {"D2@Эскиз1", Convert.ToString(widthD)}, // {"D4@Эскиз27", Convert.ToString(addwidth2-4.62)}, // {"D1@Эскиз27", Convert.ToString(90)}, // {"D2@Эскиз27", Convert.ToString((75-4.62))}, // {"D1@Эскиз24", type == RoofType.Five || type == RoofType.Six? Convert.ToString(149.53) : Convert.ToString(9.53)}, // {"D1@Кривая2", Convert.ToString(weldW2*1000)}, // {"D1@Кривая1", Convert.ToString(weldW*1000)} // } ); try { VentsMatdll(new[] { "1700" }, new[] { "", "Шаргень", "2" }, newPartName); } catch (Exception e) { Patterns.Observer.MessageObserver.Instance.SetMessage(e.ToString()); } SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(newPartName); } //15-002 if (type == RoofType_e.Six) { try { SolidWorksAdapter.SldWoksAppExemplare.IActivateDoc2("15-002", true, 0); newPartName = $"15-0{type}-02-{width}-{lenght}"; CheckExistPart(newPartName, out IsExistPart, out newPartPath); if (IsExistPart) { solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0))); solidWorksDocument.Extension.SelectByID2("15-002-1@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorcsAssemvlyDocyment.ReplaceComponents(newPartPath, "", true, true); SolidWorksAdapter.SldWoksAppExemplare.CloseDoc("15-002.SLDPRT"); } else { newPartPath = $@"{RootFolder}\{SubjectDestinationFolder}\{newPartName}.SLDPRT"; //EditPartParameters("15-002", // $@"{RootFolder}\{SubjectDestinationFolder}\{newPartName}", // new[,] // { // {"D1@Эскиз1", type == RoofType.Five || type == RoofType.Six ? Convert.ToString(140 + lengthD + type4) : Convert.ToString(lengthD + type4)}, // {"D2@Эскиз1", Convert.ToString(widthD)}, // {"D4@Эскиз27", Convert.ToString(addwidth2-4.62)}, // {"D1@Эскиз27", Convert.ToString(90)}, // {"D2@Эскиз27", Convert.ToString((75-4.62))}, // {"D2@Эскиз23", type == RoofType.Five || type == RoofType.Six ? Convert.ToString(165) : Convert.ToString(25)}, // {"D1@Кривая2", Convert.ToString(weldW2*1000)}, // {"D1@Кривая1", Convert.ToString(weldW*1000)} // } ); try { VentsMatdll(new[] { "1700" }, new[] { "", "Шаргень", "2" }, newPartName); } catch (Exception e) { //MessageBox.Show(e.ToString()); } SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(newPartName); } solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0))); solidWorksDocument.Extension.SelectByID2("15-001-3@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorksDocument.Extension.SelectByID2("ЗеркальныйКомпонент2@15-000", "COMPPATTERN", 0, 0, 0, false, 0, null, 0); solidWorksDocument.EditSuppress2(); } catch (Exception e) { Patterns.Observer.MessageObserver.Instance.SetMessage(e.ToString()); } } else if (type != RoofType_e.Six) { solidWorksDocument = ((ModelDoc2)(SolidWorksAdapter.SldWoksAppExemplare.ActivateDoc2("15-000.SLDASM", true, 0))); solidWorksDocument.Extension.SelectByID2("15-002-1@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorksDocument.EditDelete(); } switch (type) { case RoofType_e.Two: case RoofType_e.Six: solidWorksDocument.Extension.SelectByID2("Винт самосверл 6-гр.гол с шайбой-33@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorksDocument.EditDelete(); break; default: solidWorksDocument.Extension.SelectByID2("Винт самосверл 6-гр.гол с шайбой-26@15-000", "COMPONENT", 0, 0, 0, false, 0, null, 0); solidWorksDocument.EditDelete(); break; } #endregion // GabaritsForPaintingCamera(SolidWorksDocument); try { solidWorksDocument.ForceRebuild3(true); //Console.WriteLine("newRoofPath " + newRoofPath); solidWorksDocument.SaveAs2(newRoofPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); newComponents.Add(new FileInfo(newRoofPath)); SolidWorksAdapter.CloseAllDocumentsAndExit(); // PDMWebService.Data.PDM.SolidWorksPdmAdapter.Instance.CheckInOutPdm(newComponents, true); //Console.WriteLine("RoofBuilder строка 324 пересмотреть CheckInOutPdm"); foreach (var newComponent in ComponentsPathList) { // ExportXmlSql.Export(newComponent.FullName); } } catch (Exception ex) { Patterns.Observer.MessageObserver.Instance.SetMessage(ex.ToString()); } if (onlyPath) { return(newRoofPath); } //MessageBox.Show(newRoofPath, "Модель построена"); return(newRoofPath); }