public void GetTiff() { //object obt= iSwApp.GetAddInObject("ConisioSW2.ConisioSWAddIn") as SwAddin; //iSwApp.CommandInProgress = true; if (Directory.Exists("D:\\PDM\\")) { pdm_path = "D:\\PDM\\"; } else if (Directory.Exists("C:\\PDM\\")) { pdm_path = "C:\\PDM\\"; } else { MessageBox.Show("Не найден путь PDM"); return; } ModelDoc2 swModel; ModelDocExtension swModelDocExt; AssemblyDoc swAssy; Component2 swComp; DrawingDoc Part; int errors = 0; int warnings = 0; string fileName; // GetOpenFileName Dictionary <string, string> Dict, Drw; string projekt_path, key, pathName; string[] сonfNames; object[] Comps; swModel = (ModelDoc2)iSwApp.ActiveDoc; if (swModel == null) { fileName = iSwApp.GetOpenFileName("File to SLDASM", "", "SLDASM Files (*.SLDASM)|*.SLDASM|", out _, out _, out _); //Проверяем путь if (fileName == "") { return; } swModel = (ModelDoc2)iSwApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); } //Проверяем открыта сборка или нет if ((swModel.GetType() != 2) | (swModel == null)) { iSwApp.SendMsgToUser2("Откройте сборку", 4, 2); return; } //FileAttributes attr = File.GetAttributes(@"c:\Temp"); //attr.HasFlag(FileAttributes.Directory); // файл или дирректория //swModel = (ModelDoc2)swApp.ActiveDoc; swAssy = (AssemblyDoc)swModel; Dict = new Dictionary <string, string>(); projekt_path = swModel.GetPathName().Remove(swModel.GetPathName().LastIndexOf((char)92) + 1); int value = iSwApp.SendMsgToUser2("Создать Tiff со всей сборки(Да) или только с её папки(Нет)?", 3, 5); iSwApp.UnloadAddIn(sAddinName); //iSwApp.SendMsgToUser2("Значение "+ value, 4, 2); switch (value) { case 3: { List <string> allDRW = new List <string>(Directory.GetFiles(projekt_path, "*.SLDDRW", SearchOption.AllDirectories)); //iSwApp.SendMsgToUser2("Длина " + allDRW.Count, 4, 2); foreach (string pdrw in allDRW) { key = pdrw.Substring(pdrw.LastIndexOf((char)92) + 1); key = key.Substring(0, key.Length - 7); if (!Dict.ContainsKey(key)) { Dict.Add(key, pdrw.Substring(0, pdrw.Length - 7)); } } break; } case 6: { key = swModel.GetPathName().Substring(swModel.GetPathName().LastIndexOf((char)92) + 1); key = key.Substring(0, key.Length - 7); pathName = swModel.GetPathName(); pathName = pathName.Remove(pathName.Length - 7); if (!Dict.ContainsKey(key)) { Dict.Add(key, pathName); } //Создаем список путей компонентов для всех конфигураций сonfNames = (string[])swModel.GetConfigurationNames(); swAssy.ResolveAllLightWeightComponents(false); for (int i = 0; i < сonfNames.Length; i++) { swModel.ShowConfiguration2((string)сonfNames[i]); swModel.ForceRebuild3(false); Comps = (object[])swAssy.GetComponents(false); for (int j = 0; j < Comps.Length; j++) { swComp = (Component2)Comps[j]; //compDoc = (ModelDoc2)swComp.GetModelDoc2(); if ((swComp.GetSuppression() != (int)swComponentSuppressionState_e.swComponentSuppressed) & (swComp != null)) { pathName = swComp.GetPathName(); pathName = pathName.Remove(pathName.Length - 7); key = swComp.GetPathName().Substring(swComp.GetPathName().LastIndexOf((char)92) + 1); key = key.Substring(0, key.Length - 7); if (!Dict.ContainsKey(key)) { Dict.Add(key, pathName); } } } } break; } default: { iSwApp.LoadAddIn(sAddinName); return; } } //Находим где могут быть чертежи Drw = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> k in Dict) { if (value == 6) { if ((k.Value.Contains((string)(pdm_path + "Проект"))) | (k.Value.Contains((pdm_path + "Общеприменяемые")))) { Drw.Add(k.Key, k.Value); } } else { Drw.Add(k.Key, k.Value); } } //Создаем папку DirectoryInfo dirInfo = new DirectoryInfo(projekt_path + "\\TIF"); if (!dirInfo.Exists) { dirInfo.Create(); } //Настройки TIF iSwApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swTiffScreenOrPrintCapture, 1); //1-Print capture iSwApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swTiffPrintPaperSize, 12); //12-Papers User Defined iSwApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swTiffImageType, 0); //0-Black And White iSwApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swTiffCompressionScheme, 2); //2-Group 4 Fax Compression iSwApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swTiffPrintDPI, 600); //300-Integer value //Сохраняем картинки int itogo = 0; StreamWriter writer = new StreamWriter(projekt_path + "TIF\\" + "Список" + ".txt", false); foreach (KeyValuePair <string, string> k in Drw) { //Настройка размеров картинки iSwApp.IGetTemplateSizes(k.Value + ".SLDDRW", out int PaperSize, out double Width, out double Height); iSwApp.SetUserPreferenceDoubleValue((int)swUserPreferenceDoubleValue_e.swTiffPrintDrawingPaperWidth, Width); //Double value in meters iSwApp.SetUserPreferenceDoubleValue((int)swUserPreferenceDoubleValue_e.swTiffPrintDrawingPaperHeight, Height); //Double value in meters Part = (DrawingDoc)iSwApp.OpenDoc6(k.Value + ".SLDDRW", (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_ViewOnly, "", ref errors, ref warnings); if ((errors == 0) & (Part != null)) { swModel = (ModelDoc2)Part; swModelDocExt = (ModelDocExtension)swModel.Extension; swModelDocExt.SaveAs2(projekt_path + "TIF\\" + k.Key + ".TIF", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, "", false, ref errors, ref warnings); writer.WriteLine(k.Value.Substring(k.Value.LastIndexOf((char)92) + 1)); itogo += 1; } iSwApp.CloseDoc(k.Value + ".SLDDRW"); Part = null; } writer.Close(); iSwApp.LoadAddIn(sAddinName); iSwApp.SendMsgToUser2("Всего частей " + Dict.Count + System.Environment.NewLine + "Чертежей сохранено " + itogo, 2, 2); //iSwApp.CommandInProgress = false; }