public static void Build(IModelDoc2 model) { if (model.EditRebuild3()) { logger.Debug("\n Rebuild Success"); } }
public static void Build(IModelDoc2 model) { if (model.EditRebuild3()) { Console.WriteLine(" - SolidWorks Model - Build - Success"); } else { Console.WriteLine(" - WARNING - SolidWorks Model - Build - Failed"); } }
/// <summary> /// dellete equation for model, by index /// </summary> /// <param name="index"></param> /// <param name="swModel"></param> public void DeleteEquation(int index, IModelDoc2 swModel) { try { var myEqu = swModel.GetEquationMgr(); myEqu.Delete(index); swModel.EditRebuild3(); } catch (Exception exception) { MessageObserver.Instance.SetMessage("Exeption at delete equations " + exception.ToString()); } }
private static void AddDimentions(IModelDoc2 swmodel, string configname, out Exception exception) { const long valueset = 1000; exception = null; try { swmodel.GetConfigurationByName(configname); swmodel.EditRebuild3(); var part = (PartDoc)swmodel; var box = part.GetPartBox(true); swmodel.AddCustomInfo3(configname, "Длина", 30, ""); swmodel.AddCustomInfo3(configname, "Ширина", 30, ""); swmodel.AddCustomInfo3(configname, "Высота", 30, ""); swmodel.CustomInfo2[configname, "Длина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long)(Math.Abs(box[0] - box[3]) * valueset)), 0), CultureInfo.InvariantCulture); swmodel.CustomInfo2[configname, "Ширина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long)(Math.Abs(box[1] - box[4]) * valueset)), 0), CultureInfo.InvariantCulture); swmodel.CustomInfo2[configname, "Высота"] = Convert.ToString( Math.Round(Convert.ToDecimal((long)(Math.Abs(box[2] - box[5]) * valueset)), 0), CultureInfo.InvariantCulture); swmodel.EditRebuild3(); } catch (Exception ex) { exception = ex; } }
internal static void DelEquations(int index, IModelDoc2 swModel) { try { Логгер.Информация($"Удаление уравнения #{index} в модели {swModel.GetPathName()}", null, "", "DelEquations"); var myEqu = swModel.GetEquationMgr(); myEqu.Delete(index); swModel.EditRebuild3(); } catch (Exception e) { Логгер.Ошибка($"Удаление уравнения #{index} в модели {swModel.GetPathName()}. {e.Message}", null, e.StackTrace, "DelEquations"); } }
public static bool SaveThisConfigDxf(string folderToSave, string configuration, SldWorks swApp, IModelDoc2 swModel, out string dxfFilePath, bool sheetmetal) { swModel.ShowConfiguration2(configuration); swModel.EditRebuild3(); if (swApp != null && sheetmetal) { List <PartBendInfo> list; Bends.Fix(swApp, out list, true); } var sDxfName = DxfName(swModel.GetTitle(), configuration) + ".dxf"; dxfFilePath = Path.Combine(folderToSave, sDxfName); // dxfFilePath = Path.Combine(@"C:\DXF", sDxfName); Directory.CreateDirectory(folderToSave); var dataAlignment = new double[12]; dataAlignment[0] = 0.0; dataAlignment[1] = 0.0; dataAlignment[2] = 0.0; dataAlignment[3] = 1.0; dataAlignment[4] = 0.0; dataAlignment[5] = 0.0; dataAlignment[6] = 0.0; dataAlignment[7] = 1.0; dataAlignment[8] = 0.0; dataAlignment[9] = 0.0; dataAlignment[10] = 0.0; dataAlignment[11] = 1.0; object varAlignment = dataAlignment; var swPart = (IPartDoc)swModel; int sheetmetalOptions = SheetMetalOptions(true, sheetmetal, false, false, false, true, false); //MessageBox.Show(sheetmetalOptions.ToString()); if (sheetmetal) { return(swPart.ExportToDWG(dxfFilePath, swModel.GetPathName(), sheetmetal ? 1 : 2, true, varAlignment, false, false, sheetmetalOptions, sheetmetal ? 0 : 3)); } else { return(swModel.SaveAs4(dxfFilePath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, 0, 0)); } }
static void GabaritsForPaintingCamera(IModelDoc2 swmodel) { try { const long valueset = 1000; const int swDocPart = 1; const int swDocAssembly = 2; var configNames = swmodel.GetConfigurationNames(); foreach (var configname in configNames) { try { IConfiguration swConf = swmodel.GetConfigurationByName(configname); if (swConf.IsDerived()) continue; } catch (Exception) { // } swmodel.EditRebuild3(); switch (swmodel.GetType()) { case swDocPart: { var part = (IPartDoc)swmodel; var box = part.GetPartBox(true); swmodel.AddCustomInfo3(configname, "Длина", 30, ""); swmodel.AddCustomInfo3(configname, "Ширина", 30, ""); swmodel.AddCustomInfo3(configname, "Высота", 30, ""); swmodel.CustomInfo2[configname, "Длина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(box[0] - box[3])*valueset)), 0)); swmodel.CustomInfo2[configname, "Ширина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(box[1] - box[4])*valueset)), 0)); swmodel.CustomInfo2[configname, "Высота"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(box[2] - box[5])*valueset)), 0)); } break; case swDocAssembly: { var swAssy = (AssemblyDoc) swmodel; var boxAss = swAssy.GetBox((int) swBoundingBoxOptions_e.swBoundingBoxIncludeRefPlanes); swmodel.AddCustomInfo3(configname, "Длина", 30, ""); swmodel.AddCustomInfo3(configname, "Ширина", 30, ""); swmodel.AddCustomInfo3(configname, "Высота", 30, ""); swmodel.CustomInfo2[configname, "Длина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[0] - boxAss[3])*valueset)), 0)); swmodel.CustomInfo2[configname, "Ширина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[1] - boxAss[4])*valueset)), 0)); swmodel.CustomInfo2[configname, "Высота"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[2] - boxAss[5])*valueset)), 0)); } break; } } } catch (Exception e) { Логгер.Ошибка("Ошибка: " + e.StackTrace, e.GetHashCode().ToString("X"), null, "GabaritsForPaintingCamera"); } }
public override void Build() { if (Exist) { return; } NewComponents = null; MessageBox.Show(DateTime.Now.Hour.ToString()); var modelMontageFramePath = $@"{sourceRootFolder}{TemplateFolder}\{"10-4"}.SLDASM"; GetLastVersionAsmPdm(modelMontageFramePath, VaultName); GetLastVersionAsmPdm($@"{sourceRootFolder}{TemplateFolder}\10-02-01-4.SLDPRT", VaultName); var swDocMontageFrame = _swApp.OpenDoc6(modelMontageFramePath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel, "00", 0, 0); _swApp.Visible = true; var swAsm = (AssemblyDoc)swDocMontageFrame; swAsm.ResolveAllLightWeightComponents(false); #endregion #region Основные размеры, величины и переменные // Габариты Ширина меньше ширины установки на 20мм Длина по размеру блока var width = Convert.ToDouble(Width); // Поперечные балки var lenght = Convert.ToDouble(Lenght); // Продольная балка var offsetI = Convert.ToDouble(Convert.ToString(Convert.ToDouble(FrameOffset) * 10)); // Смещение поперечной балки if (offsetI > (lenght - 125) * 10) { offsetI = (lenght - 250) * 10; MessageBox.Show("Смещение превышает допустимое значение! Программой установлено - " + (offsetI / 10)); } #region Металл и х-ки гибки // TODO Коэффициенты и радиусы гибов //var sqlBaseData = new SqlBaseData(); //var bendParams = sqlBaseData.BendTable(Material.Thikness); //var bendRadius = Convert.ToDouble(bendParams[0]); //var kFactor = Convert.ToDouble(bendParams[1]); var bendRadius = Convert.ToDouble("1"); var kFactor = Convert.ToDouble("1"); #endregion #endregion #region Изменение размеров элементов и компонентов сборки var thikness = Convert.ToDouble(Material.Thikness) / 1000; bendRadius = bendRadius / 1000; var w = Convert.ToDouble(width) / 1000; var l = Convert.ToDouble(lenght) / 1000; var offset = Convert.ToDouble(offsetI) / 10000; var offsetMirror = Convert.ToDouble(lenght * 10 - offsetI) / 10000; #region 10-02-4 Зеркальная 10-01-4 if (Type == "3") { swDocMontageFrame.Extension.SelectByID2("10-01-01-4-1@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0); swAsm = ((AssemblyDoc)(swDocMontageFrame)); swAsm.ReplaceComponents(sourceRootFolder + TemplateFolder + "\\10-02-01-4.SLDPRT", "", false, true); swAsm.ResolveAllLightWeightComponents(false); //Продольная зеркальная балка (Длина установки) swDocMontageFrame.Extension.SelectByID2("D1@Эскиз1@10-02-01-4-1@10-4", "DIMENSION", 0, 0, 00, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D1@Эскиз[email protected]"))).SystemValue = l; // Длина установки 0.8; swDocMontageFrame.Extension.SelectByID2("D3@Эскиз25@10-02-01-4-1@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D3@Эскиз[email protected]"))).SystemValue = offsetMirror; //Смещение поперечной балки от края; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-02-01-4-1@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.ActivateSelectedFeature(); swDocMontageFrame.Extension.SelectByID2("D1@Листовой металл@10-02-01-4-1@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D1@Листовой металл@10-02-01-4.Part"))).SystemValue = bendRadius; // Радиус гиба 0.005; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-02-01-4-1@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.ActivateSelectedFeature(); swDocMontageFrame.Extension.SelectByID2("D2@Листовой металл@10-02-01-4-1@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D2@Листовой металл@10-01-01-4.Part"))).SystemValue = kFactor; // K-Factor 0.55; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Толщина@Листовой металл@10-02-01-4-1@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("Толщина@Листовой металл@10-02-01-4.Part"))).SystemValue = thikness; // Толщина Листового металла 0.006; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.ClearSelection2(true); } #endregion //swApp.SendMsgToUser(string.Format("Thikness= {0}, BendRadius= {1}, Ширина= {2}, Длина= {3}, ", Thikness * 1000, BendRadius * 1000, Ширина * 1000, Длина * 1000)); //Продольные балки (Длина установки) #region 10-01-4 swDocMontageFrame.Extension.SelectByID2("D1@Эскиз1@10-01-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D1@Эскиз[email protected]"))).SystemValue = l; // Длина установки 0.8; swDocMontageFrame.Extension.SelectByID2("D3@Эскиз25@10-01-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D3@Эскиз[email protected]"))).SystemValue = offset; //Смещение поперечной балки от края; swDocMontageFrame.EditRebuild3(); //swApp.SendMsgToUser(Offset.ToString()); swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-01-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.ActivateSelectedFeature(); swDocMontageFrame.Extension.SelectByID2("D1@Листовой металл@10-01-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D1@Листовой металл@10-01-01-4.Part"))).SystemValue = bendRadius; // Радиус гиба 0.005; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-01-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.ActivateSelectedFeature(); swDocMontageFrame.Extension.SelectByID2("D2@Листовой металл@10-01-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D2@Листовой металл@10-01-01-4.Part"))).SystemValue = kFactor; // K-Factor 0.55; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Толщина@Листовой металл@10-01-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("Толщина@Листовой металл@10-01-01-4.Part"))).SystemValue = thikness; // Толщина Листового металла 0.006; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.ClearSelection2(true); #endregion #region 10-04-4-2 swDocMontageFrame.Extension.SelectByID2("D1@Эскиз1@10-04-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D1@Эскиз[email protected]"))).SystemValue = (l - 0.14); // Длина установки - 140 0.66; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-04-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.ActivateSelectedFeature(); swDocMontageFrame.Extension.SelectByID2("D1@Листовой металл@10-04-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D1@Листовой металл@10-04-4.Part"))).SystemValue = bendRadius; // Радиус гиба 0.005; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-04-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.ActivateSelectedFeature(); swDocMontageFrame.Extension.SelectByID2("D2@Листовой металл@10-04-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D2@Листовой металл@10-04-4.Part"))).SystemValue = kFactor; // K-Factor 0.55; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Толщина@Листовой металл@10-04-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("Толщина@Листовой металл@10-04-4.Part"))).SystemValue = thikness; // Толщина Листового металла 0.006; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.ClearSelection2(true); #endregion //Поперечная балка (Ширина установки) #region 10-03-4 swDocMontageFrame.Extension.SelectByID2("D2@Эскиз1@10-03-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D2@Эскиз[email protected]"))).SystemValue = (w - 0.12); // Ширина установки - 20 - 100 0.88; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-03-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.ActivateSelectedFeature(); swDocMontageFrame.Extension.SelectByID2("D1@Листовой металл@10-03-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D1@Листовой металл@10-03-01-4.Part"))).SystemValue = bendRadius; // Радиус гиба 0.005; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Листовой металл@10-03-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.ActivateSelectedFeature(); swDocMontageFrame.Extension.SelectByID2("D2@Листовой металл@10-03-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("D2@Листовой металл@10-03-01-4.Part"))).SystemValue = kFactor; // K-Factor 0.55; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.Extension.SelectByID2("Толщина@Листовой металл@10-03-01-4-2@10-4", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swDocMontageFrame.Parameter("Толщина@Листовой металл@10-03-01-4.Part"))).SystemValue = thikness; // Толщина Листового металла 0.006; swDocMontageFrame.EditRebuild3(); swDocMontageFrame.ClearSelection2(true); #endregion #endregion #region Удаление поперечной балки if (internalCrossbeam == false) { swDocMontageFrame.Extension.SelectByID2("10-03-01-4-1@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-39@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-40@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 6402_gost-23@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Hex Nut 5915_gost-19@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-22@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-41@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-42@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 6402_gost-24@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Hex Nut 5915_gost-20@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-23@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-43@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-44@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 6402_gost-25@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Hex Nut 5915_gost-21@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-24@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-45@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-46@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Washer 6402_gost-26@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Hex Nut 5915_gost-22@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-25@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-25@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.EditDelete(); // Удаление ненужных элементов продольной балки const int deleteOption = (int)swDeleteSelectionOptions_e.swDelete_Absorbed + (int)swDeleteSelectionOptions_e.swDelete_Children; swDocMontageFrame.Extension.SelectByID2("Вырез-Вытянуть8@10-01-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.Extension.DeleteSelection2(deleteOption); } #endregion #region Удаление продольной балки // Погашение внутренней продольной балки if (internalLongitudinalBeam == false) { foreach (var s in new[] { "5", "6", "7", "8", "13" }) { swDocMontageFrame.Extension.SelectByID2("Hex Bolt 7805_gost-" + s + "@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.EditDelete(); } foreach (var s in new[] { "6", "7", "8", "9", "37", "38", "39", "40" }) { swDocMontageFrame.Extension.SelectByID2("Washer 6402_gost-" + s + "@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.EditDelete(); } foreach (var s in new[] { "17", "18", "19", "20", "21", "22", "23", "24", "57", "58", "59", "60" }) { swDocMontageFrame.Extension.SelectByID2("Washer 11371_gost-" + s + "@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.EditDelete(); } swDocMontageFrame.Extension.SelectByID2("10-04-4-2@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.EditDelete(); // Удаление ненужных элементов поперечной балки swDocMontageFrame.Extension.SelectByID2("Регулируемая ножка-10@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.EditDelete(); swDocMontageFrame.Extension.SelectByID2("Регулируемая ножка-11@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.EditDelete(); foreach (var s in new[] { "10", "11", "40", "41", "42", "43" }) { swDocMontageFrame.Extension.SelectByID2("Hex Nut 5915_gost-" + s + "@10-4", "COMPONENT", 0, 0, 0, true, 0, null, 0); swDocMontageFrame.EditDelete(); } const int deleteOption = (int)swDeleteSelectionOptions_e.swDelete_Absorbed + (int)swDeleteSelectionOptions_e.swDelete_Children; swDocMontageFrame.Extension.SelectByID2("Вырез-Вытянуть5@10-03-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.Extension.DeleteSelection2(deleteOption); swDocMontageFrame.Extension.SelectByID2("Вырез-Вытянуть4@10-03-01-4-2@10-4", "BODYFEATURE", 0, 0, 0, false, 0, null, 0); swDocMontageFrame.Extension.DeleteSelection2(deleteOption); } #endregion #region Сохранение элементов и сборки, а также применение материалов #region Детали //Продольные балки (Длина установки) #region 10-01-01-4 - Деталь _swApp.IActivateDoc2("10-01-01-4", false, 0); IModelDoc2 swPartDoc = _swApp.IActiveDoc2; switch (Type) { //case "2": case "0": typeOfMfs = ""; break; case "3": case "2": case "1": typeOfMfs = "-0" + Type; break; } var newPartName = string.Format("10-01-01-{0}{4}-{1}{2}{3}.SLDPRT", Material.Thikness, lenght, FrameOffset, typeOfMfs, addMatName); var newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}"; if (File.Exists(newPartPath)) { swDocMontageFrame = ((ModelDoc2)(_swApp.ActivateDoc2("10-4.SLDASM", true, 0))); swDocMontageFrame.Extension.SelectByID2("10-01-01-4-2@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0); swAsm.ReplaceComponents(newPartPath, "", true, true); _swApp.CloseDoc("10-01-01-4.SLDPRT"); } else { swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); AddMaterial(Material, newPartPath); ComponentToAdd(newPartPath); _swApp.CloseDoc(newPartName); } #endregion // #region 10-02-01-4 - Деталь Зеркальная 10-01-01-4 if (Type == "3") { _swApp.IActivateDoc2("10-02-01-4", false, 0); swPartDoc = _swApp.IActiveDoc2; switch (Type) { case "2": case "0": typeOfMfs = ""; break; case "3": case "1": typeOfMfs = "-0" + Type; break; } newPartName = string.Format("10-02-01-{0}{4}-{1}{2}{3}.SLDPRT", Material.Thikness, lenght, FrameOffset, typeOfMfs, addMatName); newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}"; if (File.Exists(newPartPath)) { swDocMontageFrame = ((ModelDoc2)(_swApp.ActivateDoc2("10-4.SLDASM", true, 0))); swDocMontageFrame.Extension.SelectByID2("10-02-01-4-1@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0); swAsm.ReplaceComponents(newPartPath, "", false, true); _swApp.CloseDoc("10-02-01-4.SLDPRT"); } else { swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); AddMaterial(Material, newPartPath); _swApp.CloseDoc(newPartName); ComponentToAdd(newPartName); } #endregion #region 10-04-4 - Деталь if (internalLongitudinalBeam) { _swApp.IActivateDoc2("10-04-4", false, 0); swPartDoc = ((IModelDoc2)(_swApp.ActiveDoc)); newPartName = string.Format("10-04-{0}{2}-{1}.SLDPRT", Material.Thikness, (lenght - 140), addMatName); newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}"; if (File.Exists(newPartPath)) { swDocMontageFrame = ((ModelDoc2)(_swApp.ActivateDoc2("10-4.SLDASM", true, 0))); swDocMontageFrame.Extension.SelectByID2("10-04-4-2@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0); swAsm.ReplaceComponents(newPartPath, "", true, true); _swApp.CloseDoc("10-04-4.SLDPRT"); } else { swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); AddMaterial(Material, newPartPath); _swApp.CloseDoc(newPartName); ComponentToAdd(newPartPath); } } else { _swApp.CloseDoc("10-04-4.SLDPRT"); } #endregion //Поперечная балка (Ширина установки) #region 10-03-01-4 - Деталь _swApp.IActivateDoc2("10-03-01-4", false, 0); swPartDoc = ((IModelDoc2)(_swApp.ActiveDoc)); switch (Type) { case "3": case "2": typeOfMfs = "-0" + Type; break; case "1": case "0": typeOfMfs = ""; break; } newPartName = string.Format("10-03-01-{0}{3}-{1}{2}.SLDPRT", Material.Thikness, (width - 120), typeOfMfs, addMatName); newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}"; var newPrt0202 = string.Format("10-02-01-{0}{3}-{1}{2}.SLDPRT", Material.Thikness, (width - 120), typeOfMfs, addMatName); newPrt0202 = $@"{destRootFolder}\{DestinationFolder}\{newPrt0202}"; if (File.Exists(newPartPath)) { swDocMontageFrame = ((ModelDoc2)(_swApp.ActivateDoc2("10-4.SLDASM", true, 0))); swDocMontageFrame.Extension.SelectByID2("10-03-01-4-2@10-4", "COMPONENT", 0, 0, 0, false, 0, null, 0); swAsm.ReplaceComponents(newPartPath, "", true, true); _swApp.CloseDoc("10-03-01-4.SLDPRT"); } else { swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); AddMaterial(Material, newPartPath); if (Type == "2") { swPartDoc.Extension.SelectByID2("D1@Эскиз28@" + Path.GetFileNameWithoutExtension(newPrt0202) + ".SLDPRT", "DIMENSION", 0, 0, 0, false, 0, null, 0); ((Dimension)(swPartDoc.Parameter("D1@Эскиз28"))).SystemValue = -0.05; swPartDoc.EditRebuild3(); swPartDoc.SaveAs2(newPrt0202, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); AddMaterial(Material, newPrt0202); _swApp.CloseDoc(newPrt0202); ComponentToAdd(newPrt0202); } _swApp.CloseDoc(newPartName); } #endregion #endregion _swApp.IActivateDoc2("10-4.SLDASM", false, 0); swDocMontageFrame = ((ModelDoc2)(_swApp.ActiveDoc)); GabaritsForPaintingCamera(swDocMontageFrame); swDocMontageFrame.ForceRebuild3(true); swDocMontageFrame.SaveAs2(ModelPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); ComponentToAdd(ModelPath); #endregion _swApp.CloseDoc(ModelPath); _swApp = null; List <VaultSystem.VentsCadFile> newFilesList; VaultSystem.CheckInOutPdmNew(NewComponents, true, out newFilesList); #region Export To XML foreach (var newComponent in NewComponents) { // ExportXmlSql.Export(newComponent.FullName); } #endregion #region //var drawing = "12-00"; //if (modelName == "12-30") //{ // drawing = modelName; //} //Dimension myDimension; //var modelSpigotDrw = $@"{sourceRootFolder}{TemplateFolder}\{drawing}.SLDDRW"; //GetLastVersionAsmPdm(modelSpigotDrw, VaultName); //if (!InitializeSw(true)) return; //var swDrwSpigot = _swApp.OpenDoc6(modelSpigotDrw, (int)swDocumentTypes_e.swDocDRAWING, // (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel, "", 0, 0); //if (swDrwSpigot == null) return; //ModelDoc2 swDoc = _swApp.ActivateDoc2("12-00", false, 0); //var swAsm = (AssemblyDoc)swDoc; //swAsm.ResolveAllLightWeightComponents(false); //switch (modelName) //{ // case "12-20": // DelEquations(5, swDoc); // DelEquations(4, swDoc); // DelEquations(3, swDoc); // break; // case "12-30": // DelEquations(0, swDoc); // DelEquations(0, swDoc); // DelEquations(0, swDoc); // break; //} //swDoc.ForceRebuild3(true); //string newPartName; //string newPartPath; //IModelDoc2 swPartDoc; //#region Удаление ненужного //string[] itemsToDelete = null; //switch (Type) //{ // case "20": // itemsToDelete = new[] { "12-30-001-1", "12-30-001-2", "12-30-002-1", "12-30-002-2", // "ВНС-96.61.002-1", "ВНС-96.61.002-2", "ВНС-96.61.002-3", "ВНС-96.61.002-4", // "ВНС-96.61.002-5", "ВНС-96.61.002-6", "ВНС-96.61.002-7", "ВНС-96.61.002-8", // "12-30-001-3", "12-30-001-4", "12-30-002-3", "12-30-002-4", // "12-003-2", "Клей-2" }; // break; // case "30": // itemsToDelete = new[] { "12-20-001-1", "12-20-001-2", "12-20-002-1", "12-20-002-2", // "ВНС-96.61.001-1", "ВНС-96.61.001-2", "ВНС-96.61.001-3", "ВНС-96.61.001-4", // "ВНС-96.61.001-5", "ВНС-96.61.001-6", "ВНС-96.61.001-7", "ВНС-96.61.001-8", // "12-20-001-3", "12-20-001-4", "12-20-002-3", "12-20-002-4", // "12-003-1", "Клей-1"}; // break; //} //foreach (var item in itemsToDelete) //{ // DoWithSwDoc(_swApp, CompType.COMPONENT, item, Act.DeletWithOption); //} //DoWithSwDoc(_swApp, CompType.FTRFOLDER, "30", Act.Delete); //DoWithSwDoc(_swApp, CompType.FTRFOLDER, "20", Act.Delete); //#endregion //#region Сохранение и изменение элементов //string path; //int fileId; //int projectId; //var addDimH = 1; //if (modelName == "12-30") //{ // addDimH = 10; //} //var w = (Convert.ToDouble(Width) - 1) / 1000; //var h = Convert.ToDouble((Convert.ToDouble(Height) + addDimH) / 1000); //const double step = 50; //var weldW = Convert.ToDouble((Math.Truncate(Convert.ToDouble(Width) / step) + 1)); //var weldH = Convert.ToDouble((Math.Truncate(Convert.ToDouble(Height) / step) + 1)); //if (modelName == "12-20") //{ // //12-20-001 // _swApp.IActivateDoc2("12-20-001", false, 0); // swPartDoc = _swApp.IActiveDoc2; // newPartName = $"12-20-{Height}.SLDPRT"; // newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}"; // if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId)) // { // swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0))); // swDoc.Extension.SelectByID2("12-20-001-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); // swAsm.ReplaceComponents(newPartPath, "", true, true); // _swApp.CloseDoc("12-20-001.SLDPRT"); // } // else // { // swDoc.Extension.SelectByID2("D1@Вытянуть1@12-20-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D1@Вытянуть[email protected]"))); // myDimension.SystemValue = h - 0.031; // swDoc.Extension.SelectByID2("D1@Кривая1@12-20-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D1@Кривая[email protected]"))); // myDimension.SystemValue = weldH; // swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); // ComponentToAdd(newPartPath); // _swApp.CloseDoc(newPartName); // } // //12-20-002 // _swApp.IActivateDoc2("12-20-002", false, 0); // swPartDoc = _swApp.IActiveDoc2; // newPartName = $"12-20-{Width}.SLDPRT"; // newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}"; // if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId)) // { // swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0))); // swDoc.Extension.SelectByID2("12-20-002-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); // swAsm.ReplaceComponents(newPartPath, "", true, true); // _swApp.CloseDoc("12-20-002.SLDPRT"); // } // else // { // swDoc.Extension.SelectByID2("D1@Вытянуть1@12-20-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D1@Вытянуть[email protected]"))); // myDimension.SystemValue = w - 0.031; // swDoc.Extension.SelectByID2("D1@Кривая1@12-20-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D1@Кривая[email protected]"))); // myDimension.SystemValue = weldW; // swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); // ComponentToAdd(newPartPath); // _swApp.CloseDoc(newPartName); // } // //12-003 // _swApp.IActivateDoc2("12-003", false, 0); // swPartDoc = _swApp.IActiveDoc2; // newPartName = $"12-03-{Width}-{Height}.SLDPRT"; // newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}"; // if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId)) // { // swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0))); // swDoc.Extension.SelectByID2("12-003-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); // swAsm.ReplaceComponents(newPartPath, "", true, true); // _swApp.CloseDoc("12-003.SLDPRT"); // } // else // { // swDoc.Extension.SelectByID2("D3@Эскиз1@12-003-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D3@Эскиз[email protected]"))); // myDimension.SystemValue = w; // swDoc.Extension.SelectByID2("D2@Эскиз1@12-003-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D2@Эскиз[email protected]"))); // myDimension.SystemValue = h; // swDoc.EditRebuild3(); // swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); // ComponentToAdd(newPartPath); // _swApp.CloseDoc(newPartName); // } //} //if (modelName == "12-30") //{ // //12-30-001 // _swApp.IActivateDoc2("12-30-001", false, 0); // swPartDoc = _swApp.IActiveDoc2; // newPartName = $"12-30-01-{Height}.SLDPRT"; // newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}"; // if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId)) // { // swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0))); // swDoc.Extension.SelectByID2("12-30-001-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); // swAsm.ReplaceComponents(newPartPath, "", true, true); // _swApp.CloseDoc("12-30-001.SLDPRT"); // } // else // { // swDoc.Extension.SelectByID2("D1@Вытянуть1@12-30-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D1@Вытянуть[email protected]"))); // myDimension.SystemValue = h - 0.031; // swDoc.Extension.SelectByID2("D1@Кривая1@12-30-001-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D1@Кривая[email protected]"))); // myDimension.SystemValue = weldH; // swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); // ComponentToAdd(newPartPath); // _swApp.CloseDoc(newPartName); // } // //12-30-002 // _swApp.IActivateDoc2("12-30-002", false, 0); // swPartDoc = _swApp.IActiveDoc2; // newPartName = $"12-30-02-{Width}.SLDPRT"; // newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}"; // if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId)) // { // swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0))); // swDoc.Extension.SelectByID2("12-30-002-1@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); // swAsm.ReplaceComponents(newPartPath, "", true, true); // _swApp.CloseDoc("12-30-002.SLDPRT"); // } // else // { // swDoc.Extension.SelectByID2("D1@Вытянуть1@12-30-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D1@Вытянуть[email protected]"))); // myDimension.SystemValue = w - 0.031; // swDoc.Extension.SelectByID2("D1@Кривая1@12-30-002-1@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D1@Кривая[email protected]"))); // myDimension.SystemValue = weldH; // swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); // ComponentToAdd(newPartPath); // _swApp.CloseDoc(newPartName); // } // //12-003 // _swApp.IActivateDoc2("12-003", false, 0); // swPartDoc = _swApp.IActiveDoc2; // newPartName = $"12-03-{Width}-{Height}.SLDPRT"; // newPartPath = $@"{destRootFolder}\{DestinationFolder}\{newPartName}"; // if (GetExistingFile(Path.GetFileNameWithoutExtension(newPartPath), out path, out fileId, out projectId)) // { // swDoc = ((ModelDoc2)(VentsCad._swApp.ActivateDoc2("12-00.SLDASM", true, 0))); // swDoc.Extension.SelectByID2("12-003-2@12-00", "COMPONENT", 0, 0, 0, false, 0, null, 0); // swAsm.ReplaceComponents(newPartPath, "", true, true); // _swApp.CloseDoc("12-003.SLDPRT"); // } // else // { // swDoc.Extension.SelectByID2("D3@Эскиз1@12-003-2@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D3@Эскиз[email protected]"))); // myDimension.SystemValue = w; // swDoc.Extension.SelectByID2("D2@Эскиз1@12-003-2@12-00", "DIMENSION", 0, 0, 0, false, 0, null, 0); // myDimension = ((Dimension)(swDoc.Parameter("D2@Эскиз[email protected]"))); // myDimension.SystemValue = h; // swDoc.EditRebuild3(); // swPartDoc.SaveAs2(newPartPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); // ComponentToAdd(newPartPath); // _swApp.CloseDoc(newPartName); // } //} //#endregion //GabaritsForPaintingCamera(swDoc); //swDoc.ForceRebuild3(true); //swDoc.SaveAs2(ModelPath + ".SLDASM", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); //_swApp.CloseDoc(ModelName + ".SLDASM"); //swDrwSpigot.Extension.SelectByID2("DRW1", "SHEET", 0, 0, 0, false, 0, null, 0); //var drw = (DrawingDoc)(_swApp.IActivateDoc3(drawing + ".SLDDRW", true, 0)); //drw.ActivateSheet("DRW1"); //var m = 5; //if (Convert.ToInt32(Width) > 500 || Convert.ToInt32(Height) > 500) { m = 10; } //if (Convert.ToInt32(Width) > 850 || Convert.ToInt32(Height) > 850) { m = 15; } //if (Convert.ToInt32(Width) > 1250 || Convert.ToInt32(Height) > 1250) { m = 20; } //drw.SetupSheet5("DRW1", 12, 12, 1, m, true, destRootFolder + @"\Vents-PDM\\Библиотека проектирования\\Templates\\Основные надписи\\A3-A-1.slddrt", 0.42, 0.297, "По умолчанию", false); //var errors = 0; var warnings = 0; //swDrwSpigot.SaveAs4(ModelPath + ".SLDDRW", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, ref errors, ref warnings); //ComponentToAdd(new[] { ModelPath + ".SLDDRW", ModelPath + ".SLDASM" }); //_swApp.CloseDoc(ModelPath); //_swApp.ExitApp(); //_swApp = null; //List<VaultSystem.VentsCadFiles> newFilesList; //VaultSystem.CheckInOutPdmNew(NewComponents, true, //DestVaultName, // out newFilesList); //foreach (var item in newFilesList) //{ // if (item.LocalPartFileInfo.ToUpper().Contains(".SLDASM")) // { // AddInSqlBaseSpigot(item.PartName.Remove(item.PartName.LastIndexOf('.')), item.PartIdPdm, // Convert.ToInt32(Type), Convert.ToInt32(Height), Convert.ToInt32(Width)); // } //} //foreach (var newComponent in NewComponents) //{ // PartInfoToXml(newComponent.LocalPartFileInfo); //} #endregion Place = GetPlace(); } }
private static void GabaritsForPaintingCamera(IModelDoc2 swmodel) { try { const long valueset = 1000; const int swDocPart = 1; const int swDocAssembly = 2; for (var i = 0; i < swmodel.GetConfigurationCount(); i++) { i = i + 1; var configname = swmodel.IGetConfigurationNames(ref i); // MessageBox.Show(configname, swmodel.GetConfigurationCount().ToString()); Configuration swConf = swmodel.GetConfigurationByName(configname); if (swConf.IsDerived()) continue; //swmodel.ShowConfiguration2(configname); swmodel.EditRebuild3(); switch (swmodel.GetType()) { case swDocPart: { // MessageBox.Show("swDocPart"); var part = (PartDoc) swmodel; var box = part.GetPartBox(true); swmodel.AddCustomInfo3(configname, "Длина", 30, ""); swmodel.AddCustomInfo3(configname, "Ширина", 30, ""); swmodel.AddCustomInfo3(configname, "Высота", 30, ""); // swmodel.AddCustomInfo3(configname, "Длина", , ""); swmodel.CustomInfo2[configname, "Длина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(box[0] - box[3])*valueset)), 0)); swmodel.CustomInfo2[configname, "Ширина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(box[1] - box[4])*valueset)), 0)); swmodel.CustomInfo2[configname, "Высота"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(box[2] - box[5])*valueset)), 0)); } break; case swDocAssembly: { // MessageBox.Show("AssemblyDoc"); var swAssy = (AssemblyDoc) swmodel; var boxAss = swAssy.GetBox((int) swBoundingBoxOptions_e.swBoundingBoxIncludeRefPlanes); swmodel.AddCustomInfo3(configname, "Длина", 30, ""); swmodel.AddCustomInfo3(configname, "Ширина", 30, ""); swmodel.AddCustomInfo3(configname, "Высота", 30, ""); swmodel.CustomInfo2[configname, "Длина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[0] - boxAss[3])*valueset)), 0)); swmodel.CustomInfo2[configname, "Ширина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[1] - boxAss[4])*valueset)), 0)); swmodel.CustomInfo2[configname, "Высота"] = Convert.ToString( Math.Round(Convert.ToDecimal((long) (Math.Abs(boxAss[2] - boxAss[5])*valueset)), 0)); } break; } } } catch (Exception ex) { MessageBox.Show($"{swmodel.GetTitle()}\n{ex.Message}\n{ex.StackTrace}", "GabaritsForPaintingCamera"); } }
private static void DelEquations(int index, IModelDoc2 swModel) { try { Логгер.Информация($"Удаление уравнения #{index} в модели {swModel.GetPathName()}", "", null, "DelEquations"); var myEqu = swModel.GetEquationMgr(); myEqu.Delete(index); swModel.EditRebuild3(); //myEqu.Add2(index, "\"" + System.Convert.ToChar(index) + "\"=" + index, false); } catch (Exception e) { Логгер.Ошибка($"Удаление уравнения #{index} в модели {swModel.GetPathName()}. {e.Message}", e.StackTrace, null, "DelEquations"); } }
private const string ШаблонЧертежаРазверткиВнеХранилища = "flattpattern.drwdot";//@"C:\flattpattern.drwdot"; public void CreateFlattPatternUpdateCutlistAndEdrawing() { #region Сбор информации по детали и сохранение разверток //SldWorks swApp = null; try { var swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); swApp = new SldWorks { Visible = true }; IModelDoc2 swModel = swApp.IActiveDoc2; swModel.Extension.ViewDisplayRealView = false; if (!IsSheetMetalPart((IPartDoc)swModel)) { MessageBox.Show("Деталь не из листового материала"); } string[] swModelConfNames; var activeconfiguration = (Configuration)swModel.GetActiveConfiguration(); swModelConfNames = (string[])swModel.GetConfigurationNames(); var swModelConfNames2 = (string[])swModel.GetConfigurationNames(); try { foreach (var configName in from name in swModelConfNames2 let config = (Configuration)swModel.GetConfigurationByName(name) where !config.IsDerived() select name) { swModel.ShowConfiguration2(configName); swModel.EditRebuild3(); FileInfo template = null; try { template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища); //MessageBox.Show(template.FullName); Thread.Sleep(1000); } catch (Exception exception) { MessageBox.Show(exception.ToString()); template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища); Thread.Sleep(1000); } finally { if (template == null) { template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища); } } //MessageBox.Show(template.FullName); var swDraw = (DrawingDoc)swApp.INewDocument2(template.FullName, (int)swDwgPaperSizes_e.swDwgPaperA0size, 0.841, 0.594); swDraw.CreateFlatPatternViewFromModelView3(swModel.GetPathName(), configName, 0.841 / 2, 0.594 / 2, 0, true, false); ((IModelDoc2)swDraw).ForceRebuild3(true); #region азгибание всех сгибов try { swModel.EditRebuild3(); var swPart = (IPartDoc)swModel; Feature swFeature = swPart.FirstFeature(); const string strSearch = "FlatPattern"; while (swFeature != null) { var nameTypeFeature = swFeature.GetTypeName2(); if (nameTypeFeature == strSearch) { swFeature.Select(true); swPart.EditUnsuppress(); Feature swSubFeature = swFeature.GetFirstSubFeature(); while (swSubFeature != null) { var nameTypeSubFeature = swSubFeature.GetTypeName2(); if (nameTypeSubFeature == "UiBend") { swFeature.Select(true); swPart.EditUnsuppress(); swModel.EditRebuild3(); try { swSubFeature.SetSuppression2( (int)swFeatureSuppressionAction_e.swUnSuppressFeature, (int)swInConfigurationOpts_e.swAllConfiguration, swModelConfNames2); } catch (Exception) {} } swSubFeature = swSubFeature.GetNextSubFeature(); } } swFeature = swFeature.GetNextFeature(); } swModel.EditRebuild3(); } catch (Exception exception) { MessageBox.Show(exception.Message); } #endregion swModel.ForceRebuild3(false); var thikness = GetFromCutlist(swModel, "Толщина листового металла"); var errors = 0; var warnings = 0; var newDxf = (IModelDoc2)swDraw; try { Directory.CreateDirectory("C:\\Dxf\\"); } catch (Exception) {} newDxf.Extension.SaveAs( "C:\\Dxf\\" + Path.GetFileNameWithoutExtension(swModel.GetPathName()) + "-" + configName + "-" + thikness + ".dxf", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_UpdateInactiveViews, null, ref errors, ref warnings); swApp.CloseDoc(Path.GetFileName(newDxf.GetPathName())); } } catch (Exception exception) { MessageBox.Show(exception.ToString()); } try { swModel.ShowConfiguration2(activeconfiguration.Name); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } #endregion } catch (Exception exception) { MessageBox.Show(exception.ToString()); } }
static void GabaritsForPaintingCamera(IModelDoc2 swmodel) { try { const long valueset = 1000; const int swDocPart = 1; const int swDocAssembly = 2; var configNames = swmodel.GetConfigurationNames(); foreach (var configname in configNames) { try { IConfiguration swConf = swmodel.GetConfigurationByName(configname); if (swConf.IsDerived()) { continue; } } catch (Exception) { // } swmodel.EditRebuild3(); switch (swmodel.GetType()) { case swDocPart: { var part = (IPartDoc)swmodel; var box = part.GetPartBox(true); swmodel.AddCustomInfo3(configname, "Длина", 30, ""); swmodel.AddCustomInfo3(configname, "Ширина", 30, ""); swmodel.AddCustomInfo3(configname, "Высота", 30, ""); swmodel.CustomInfo2[configname, "Длина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long)(Math.Abs(box[0] - box[3]) * valueset)), 0)); swmodel.CustomInfo2[configname, "Ширина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long)(Math.Abs(box[1] - box[4]) * valueset)), 0)); swmodel.CustomInfo2[configname, "Высота"] = Convert.ToString( Math.Round(Convert.ToDecimal((long)(Math.Abs(box[2] - box[5]) * valueset)), 0)); } break; case swDocAssembly: { var swAssy = (AssemblyDoc)swmodel; var boxAss = swAssy.GetBox((int)swBoundingBoxOptions_e.swBoundingBoxIncludeRefPlanes); swmodel.AddCustomInfo3(configname, "Длина", 30, ""); swmodel.AddCustomInfo3(configname, "Ширина", 30, ""); swmodel.AddCustomInfo3(configname, "Высота", 30, ""); swmodel.CustomInfo2[configname, "Длина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long)(Math.Abs(boxAss[0] - boxAss[3]) * valueset)), 0)); swmodel.CustomInfo2[configname, "Ширина"] = Convert.ToString( Math.Round(Convert.ToDecimal((long)(Math.Abs(boxAss[1] - boxAss[4]) * valueset)), 0)); swmodel.CustomInfo2[configname, "Высота"] = Convert.ToString( Math.Round(Convert.ToDecimal((long)(Math.Abs(boxAss[2] - boxAss[5]) * valueset)), 0)); } break; } } } catch (Exception e) { Логгер.Ошибка("Ошибка: " + e.StackTrace, e.GetHashCode().ToString("X"), null, "GabaritsForPaintingCamera"); } }
public void CreateFlattPatternUpdateCutlistAndEdrawing(List <Configs> configsList) { #region Сбор информации по детали и сохранение разверток try { var swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); IModelDoc2 swModel = swApp.IActiveDoc2; swModel.Extension.ViewDisplayRealView = false; if (!IsSheetMetalPart((IPartDoc)swModel)) { MessageBox.Show(@"Деталь не из листового материала"); } string[] swModelConfNames2; if (configsList != null) { swModelConfNames2 = configsList.Where(x => x.IsCheacked).Select(x => x.Name).ToArray(); } else { swModelConfNames2 = (string[])swModel.GetConfigurationNames(); } var activeconfiguration = (Configuration)swModel.GetActiveConfiguration(); try { foreach (var configName in from name in swModelConfNames2 let config = (Configuration)swModel.GetConfigurationByName(name) where !config.IsDerived() select name) { swModel.ShowConfiguration2(configName); swModel.EditRebuild3(); { #region азгибание всех сгибов try { swModel.EditRebuild3(); var swPart = (IPartDoc)swModel; Feature swFeature = swPart.FirstFeature(); const string strSearch = "FlatPattern"; while (swFeature != null) { var nameTypeFeature = swFeature.GetTypeName2(); if (nameTypeFeature == strSearch) { swFeature.Select(true); swPart.EditUnsuppress(); Feature swSubFeature = swFeature.GetFirstSubFeature(); while (swSubFeature != null) { var nameTypeSubFeature = swSubFeature.GetTypeName2(); if (nameTypeSubFeature == "UiBend") { swFeature.Select(true); swPart.EditUnsuppress(); swModel.EditRebuild3(); swSubFeature.SetSuppression2( (int)swFeatureSuppressionAction_e.swUnSuppressFeature, (int)swInConfigurationOpts_e.swAllConfiguration, swModelConfNames2); } swSubFeature = swSubFeature.GetNextSubFeature(); } } swFeature = swFeature.GetNextFeature(); } swModel.EditRebuild3(); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } #endregion var swModelDocExt = swModel.Extension; string val; string valout; var swCustProp = swModelDocExt.CustomPropertyManager[configName]; swCustProp.Get4("Код", false, out val, out valout); if (!string.IsNullOrEmpty(valout)) { valout = "-" + valout; } swModel.ForceRebuild3(false); var thikness = GetFromCutlist(swModel, "Толщина листового металла"); var boolstatus = (IPartDoc)swModel; Directory.CreateDirectory(@"C:\DXF\"); boolstatus.ExportFlatPatternView( @"C:\DXF\" + swModel.GetTitle() + "-" + configName + "-" + thikness + valout + ".dxf", (int)swExportFlatPatternViewOptions_e.swExportFlatPatternOption_RemoveBends); } } } catch (Exception exception) { MessageBox.Show(exception.ToString()); } try { swModel.ShowConfiguration2(activeconfiguration.Name); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } #endregion } catch (Exception exception) { MessageBox.Show(exception.ToString()); } }