Esempio n. 1
0
        /// <summary>
        /// Получение параметров печати
        /// </summary>
        public static YayPrintSettings GetSavedPrintSettings()
        {
            string xmlpath = ActivateFolder();

            YayPrintSettings ps;
            XmlSerializer    serializer = new XmlSerializer(typeof(YayPrintSettings));

            if (File.Exists(xmlpath))
            {
                using (StreamReader reader = new StreamReader(xmlpath))
                {
                    ps = (YayPrintSettings)serializer.Deserialize(reader);
                    if (ps == null)
                    {
                        TaskDialog.Show("Внимание", "Не удалось получить сохраненные настройки печати");
                        Debug.WriteLine("Unable to get print setiings, set to default");
                        ps = new YayPrintSettings();
                    }
                }
            }
            else
            {
                ps = new YayPrintSettings();
            }

            if (ps.excludeColors == null || ps.excludeColors.Count == 0)
            {
                ps.excludeColors = YayPrintSettings.GetStandardExcludeColors();
            }

            return(ps);
        }
Esempio n. 2
0
        /// <summary>
        /// Проверяет, были ли внесены изменения в параметры печати.
        /// Ревит возвращает ошибку, если попытаться сохранить параметры печати, не изменив их.
        /// </summary>
        /// <param name="pset"></param>
        /// <param name="printSettings"></param>
        /// <returns></returns>
        public static bool PrintSettingsEquals(PrintSetting pset, YayPrintSettings printSettings)
        {
            PrintParameters pParams = pset.PrintParameters;
            bool            c1      = printSettings.colorsType.Equals(pParams.ColorDepth);
            bool            c2      = printSettings.hiddenLineProcessing.Equals(pParams.HiddenLineViews);
            bool            c3      = printSettings.rasterQuality.Equals(pParams.RasterQuality);

            bool check = c1 && c2 && c3;

            return(check);
        }
Esempio n. 3
0
        private static List <MySheet> GetSheetsFromDocument(Document doc, YayPrintSettings printSets)
        {
            List <MySheet> sheets = new FilteredElementCollector(doc)
                                    .WhereElementIsNotElementType()
                                    .OfClass(typeof(ViewSheet))
                                    .Cast <ViewSheet>()
                                    .Select(i => new MySheet(i, printSets.alwaysColorParamName))
                                    .ToList();

            sheets.Sort();
            return(sheets);
        }
Esempio n. 4
0
        public static bool SaveSettings(YayPrintSettings yps)
        {
            string        xmlpath    = ActivateFolder();
            XmlSerializer serializer = new XmlSerializer(typeof(YayPrintSettings));

            if (File.Exists(xmlpath))
            {
                File.Delete(xmlpath);
            }
            using (FileStream writer = new FileStream(xmlpath, FileMode.OpenOrCreate))
            {
                serializer.Serialize(writer, yps);
            }
            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Сохраняю новые значения папки для сохранения и конструктора имени в Storage.
        /// Другие настройки сохраняются в стандартных параметрах печати.
        /// </summary>
        /// <param name="outputFolder"></param>
        /// <param name="nameConstructor"></param>
        public void SaveNewSettings(YayPrintSettings printSettings) //string outputFolder, string nameConstructor)
        {
            using (Transaction t = new Transaction(_doc))
            {
                t.Start("Сохранение настроек печати");

                Schema sch = Schema.Lookup(new Guid(schemaGuid));
                Entity ent = _storageElem.GetEntity(sch);


                ent.Set <string>(sch.GetField(PrintSettingField.GetFieldName(PrintSettingFields.OutputFolder)), printSettings.outputFolder);
                ent.Set <string>(sch.GetField(PrintSettingField.GetFieldName(PrintSettingFields.NameConstructor)), printSettings.nameConstructor);
                ent.Set <string>(sch.GetField(PrintSettingField.GetFieldName(PrintSettingFields.PrinterName)), printSettings.printerName);

                int colorTypeInt = (int)printSettings.colorsType;
                ent.Set <string>(sch.GetField(PrintSettingField.GetFieldName(PrintSettingFields.ColorsType)), colorTypeInt.ToString());

                string joinPdfValue = printSettings.mergePdfs.ToString();
                ent.Set <string>(sch.GetField(PrintSettingField.GetFieldName(PrintSettingFields.JoinPdf)), joinPdfValue);
                ent.Set <string>(sch.GetField(PrintSettingField.GetFieldName(PrintSettingFields.PrintToPaper)), printSettings.printToPaper.ToString());

                int rasterQualityValue = (int)printSettings.rasterQuality;
                ent.Set <string>(sch.GetField(PrintSettingField.GetFieldName(PrintSettingFields.RasterQuality)), rasterQualityValue.ToString());

                int hiddenLinesValue = (int)printSettings.hiddenLineProcessing;
                ent.Set <string>(sch.GetField(PrintSettingField.GetFieldName(PrintSettingFields.HiddenLineViewsType)), hiddenLinesValue.ToString());


                //foreach (string fieldName in Enum.GetValues(typeof(PrintSettingFields)))
                //{
                //    Field f = sch.GetField(fieldName);
                //    ent.Set<string>(f, value);
                //}
                //Field f1 = sch.GetField(fieldFolder);
                //Field f2 = sch.GetField(fieldConstructor);



                //ent.Set<string>(f1, outputFolder);
                //ent.Set<string>(f2, nameConstructor);

                _storageElem.SetEntity(ent);

                t.Commit();
            }
        }
Esempio n. 6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("BatchPrint"));
            Debug.WriteLine("Print started");

            App.assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

            Selection sel     = commandData.Application.ActiveUIDocument.Selection;
            Document  mainDoc = commandData.Application.ActiveUIDocument.Document;

            string mainDocTitle = SheetSupport.GetDocTitleWithoutRvt(mainDoc.Title);

            YayPrintSettings printSettings = YayPrintSettings.GetSavedPrintSettings();

            printSettings.dwgProfiles = DwgSupport.GetAllDwgExportSettingsNames(mainDoc);


            //листы из всех открытых файлов, ключ - имя файла, значение - список листов
            Dictionary <string, List <MySheet> > allSheets = SheetSupport.GetAllSheets(commandData, printSettings);

            //получаю выбранные листы в диспетчере проекта
            List <ElementId> selIds = sel.GetElementIds().ToList();
            //List<MySheet> mSheets0 = new List<MySheet>();
            bool sheetsIsChecked = false;

            foreach (ElementId id in selIds)
            {
                Element   elem  = mainDoc.GetElement(id);
                ViewSheet sheet = elem as ViewSheet;
                if (sheet == null)
                {
                    continue;
                }
                sheetsIsChecked = true;

                MySheet sheetInBase = allSheets[mainDocTitle].Where(i => i.sheet.Id.IntegerValue == sheet.Id.IntegerValue).First();
                sheetInBase.IsPrintable = true;

                //mSheets0.Add(new MySheet(sheet));
            }
            if (!sheetsIsChecked)
            {
                message = "Не выбраны листы. Выберите листы в Диспетчере проекта через Shift.";
                Debug.WriteLine("Печать остановлена, не выбраны листы");
                return(Result.Failed);
            }


            //запись статистики по файлу
            //ProjectRating.Worker.Execute(commandData);

            //очистка старых Schema при необходимости

            /*try
             * {
             *  Autodesk.Revit.DB.ExtensibleStorage.Schema sch =
             *       Autodesk.Revit.DB.ExtensibleStorage.Schema.Lookup(new Guid("414447EA-4228-4B87-A97C-612462722AD4"));
             *  Autodesk.Revit.DB.ExtensibleStorage.Schema.EraseSchemaAndAllEntities(sch, true);
             *
             *  Autodesk.Revit.DB.ExtensibleStorage.Schema sch2 =
             *       Autodesk.Revit.DB.ExtensibleStorage.Schema.Lookup(new Guid("414447EA-4228-4B87-A97C-612462722AD5"));
             *  Autodesk.Revit.DB.ExtensibleStorage.Schema.EraseSchemaAndAllEntities(sch2, true);
             *  Debug.WriteLine("Schema очищены");
             * }
             * catch
             * {
             *  Debug.WriteLine("Не удалось очистить Schema");
             * }
             */

            FormPrint form = new FormPrint(allSheets, printSettings);

            form.ShowDialog();

            if (form.DialogResult != System.Windows.Forms.DialogResult.OK)
            {
                return(Result.Cancelled);
            }
            Debug.WriteLine("В окне печати нажат ОК, переход к печати");
            printSettings = form.printSettings;

            string printerName = printSettings.printerName;

            allSheets = form.sheetsSelected;
            Debug.WriteLine("Выбранные для печати листы");
            foreach (var kvp in allSheets)
            {
                Debug.WriteLine(" Файл " + kvp.Key);
                foreach (MySheet ms in kvp.Value)
                {
                    Debug.WriteLine("  Лист " + ms.sheet.Name);
                }
            }

            string outputFolderCommon = printSettings.outputFolder;

            YayPrintSettings.SaveSettings(printSettings);
            Debug.WriteLine("Настройки печати сохранены");

            //Дополнительные возможности работают только с PDFCreator
            if (printerName != "PDFCreator")
            {
                if (printSettings.colorsType == ColorType.MonochromeWithExcludes || printSettings.mergePdfs || printSettings.useOrientation)
                {
                    string errmsg = "Объединение PDF и печать \"Штампа\" в цвете поддерживаются только  для PDFCreator.";
                    errmsg += "\nВо избежание ошибок эти настройки будут отключены.";
                    TaskDialog.Show("Предупреждение", errmsg);
                    printSettings.mergePdfs      = false;
                    printSettings.excludeColors  = new List <PdfColor>();
                    printSettings.useOrientation = false;
                    Debug.WriteLine("Выбранные настройки несовместимы с принтером " + printerName);
                }
            }
            else
            {
                if (!printSettings.useOrientation)
                {
                    SupportRegistry.SetOrientationForPdfCreator(OrientationType.Automatic);
                    Debug.WriteLine("Установлена ориентация листа Automatic");
                }
            }
            bool   printToFile  = form.printToFile;
            string outputFolder = "";

            if (printToFile)
            {
                outputFolder = PrintSupport.CreateFolderToPrint(mainDoc, printerName, outputFolderCommon);
                Debug.WriteLine("Создана папка для печати: " + outputFolder);
            }
            //List<string> pfdFileNames = new List<string>();

            //печатаю листы из каждого выбранного revit-файла
            List <MySheet> printedSheets = new List <MySheet>();

            foreach (string docTitle in allSheets.Keys)
            {
                Document openedDoc = null;
                Debug.WriteLine("Печать листов из файла " + docTitle);

                RevitLinkType rlt = null;

                //проверяю, текущий это документ или полученный через ссылку
                if (docTitle == mainDocTitle)
                {
                    openedDoc = mainDoc;
                    Debug.WriteLine("Это не ссылочный документ");
                }
                else
                {
                    List <RevitLinkType> linkTypes = new FilteredElementCollector(mainDoc)
                                                     .OfClass(typeof(RevitLinkType))
                                                     .Cast <RevitLinkType>()
                                                     .Where(i => SheetSupport.GetDocTitleWithoutRvt(i.Name) == docTitle)
                                                     .ToList();
                    if (linkTypes.Count == 0)
                    {
                        throw new Exception("Cant find opened link file " + docTitle);
                    }
                    rlt = linkTypes.First();

                    //проверю, не открыт ли уже документ, который пытаемся печатать
                    foreach (Document testOpenedDoc in commandData.Application.Application.Documents)
                    {
                        if (testOpenedDoc.IsLinked)
                        {
                            continue;
                        }
                        if (testOpenedDoc.Title == docTitle || testOpenedDoc.Title.StartsWith(docTitle) || docTitle.StartsWith(testOpenedDoc.Title))
                        {
                            openedDoc = testOpenedDoc;
                            Debug.WriteLine("Это открытый ссылочный документ");
                        }
                    }

                    //иначе придется открывать документ через ссылку
                    if (openedDoc == null)
                    {
                        Debug.WriteLine("Это закрытый ссылочный документ, пытаюсь его открыть");
                        List <Document> linkDocs = new FilteredElementCollector(mainDoc)
                                                   .OfClass(typeof(RevitLinkInstance))
                                                   .Cast <RevitLinkInstance>()
                                                   .Select(i => i.GetLinkDocument())
                                                   .Where(i => i != null)
                                                   .Where(i => SheetSupport.GetDocTitleWithoutRvt(i.Title) == docTitle)
                                                   .ToList();
                        if (linkDocs.Count == 0)
                        {
                            throw new Exception("Cant find link file " + docTitle);
                        }
                        Document linkDoc = linkDocs.First();

                        if (linkDoc.IsWorkshared)
                        {
                            Debug.WriteLine("Это файл совместной работы, открываю с отсоединением");
                            ModelPath   mpath = linkDoc.GetWorksharingCentralModelPath();
                            OpenOptions oo    = new OpenOptions();
                            oo.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets;
                            WorksetConfiguration wc = new WorksetConfiguration(WorksetConfigurationOption.OpenAllWorksets);
                            oo.SetOpenWorksetsConfiguration(wc);
                            rlt.Unload(new SaveCoordinates());
                            openedDoc = commandData.Application.Application.OpenDocumentFile(mpath, oo);
                        }
                        else
                        {
                            Debug.WriteLine("Это однопользательский файл");
                            string docPath = linkDoc.PathName;
                            rlt.Unload(new SaveCoordinates());
                            openedDoc = commandData.Application.Application.OpenDocumentFile(docPath);
                        }
                    }
                    Debug.WriteLine("Файл-ссылка успешно открыт");
                } //


                List <MySheet> mSheets = allSheets[docTitle];

                if (docTitle != mainDocTitle)
                {
                    List <ViewSheet> linkSheets = new FilteredElementCollector(openedDoc)
                                                  .OfClass(typeof(ViewSheet))
                                                  .Cast <ViewSheet>()
                                                  .ToList();
                    List <MySheet> tempSheets = new List <MySheet>();
                    foreach (MySheet ms in mSheets)
                    {
                        foreach (ViewSheet vs in linkSheets)
                        {
                            if (ms.SheetId == vs.Id.IntegerValue)
                            {
                                MySheet newMs = new MySheet(vs, printSettings.alwaysColorParamName);
                                tempSheets.Add(newMs);
                            }
                        }
                    }
                    mSheets = tempSheets;
                }
                Debug.WriteLine("Листов для печати найдено в данном файле: " + mSheets.Count.ToString());

                Debug.WriteLine(": " + mSheets.Count.ToString());
                PrintManager pManager = openedDoc.PrintManager;
                Debug.WriteLine("Текущий выбранный принтер: " + pManager.PrinterName);
                Debug.WriteLine("Попытка назначить принтер: " + printerName);
                pManager.SelectNewPrintDriver(printerName);
                pManager            = openedDoc.PrintManager;
                pManager.PrintRange = PrintRange.Current;
                pManager.Apply();
                Debug.WriteLine("Настройки менеджера печати успешно применены");


                //список основных надписей нужен потому, что размеры листа хранятся в них
                //могут быть примечания, сделанные Основной надписью, надо их отфильровать, поэтому >0.6
                List <FamilyInstance> titleBlocks = new FilteredElementCollector(openedDoc)
                                                    .WhereElementIsNotElementType()
                                                    .OfCategory(BuiltInCategory.OST_TitleBlocks)
                                                    .Cast <FamilyInstance>()
                                                    .Where(t => t.get_Parameter(BuiltInParameter.SHEET_HEIGHT).AsDouble() > 0.6)
                                                    .ToList();
                Debug.WriteLine("Найдено основных надписей: " + titleBlocks.Count.ToString());


                //получаю имя формата и проверяю, настроены ли размеры бумаги в Сервере печати
                string formatsCheckinMessage = PrintSupport.PrintFormatsCheckIn(openedDoc, printerName, titleBlocks, ref mSheets);
                if (formatsCheckinMessage != "")
                {
                    message = formatsCheckinMessage;
                    Debug.WriteLine("Проверка форматов листов неудачна: " + message);
                    return(Result.Failed);
                }
                Debug.WriteLine("Проверка форматов листов выполнена успешно, переход к печати");

                //если включен экспорт dwg - нахожу параметры экспорта по имени
                DWGExportOptions dwgOptions = null;
                if (printSettings.exportToDwg)
                {
                    List <ExportDWGSettings> curDwgSettings = DwgSupport.GetAllDwgExportSettingsNames(openedDoc)
                                                              .Where(i => i.Name == printSettings.selectedDwgExportProfileName)
                                                              .ToList();
                    if (curDwgSettings.Count == 0)
                    {
                        TaskDialog.Show("Ошибка", "В файле " + openedDoc.Title + " не найден dwg профиль " + printSettings.selectedDwgExportProfileName);
                        dwgOptions = DwgSupport.GetAllDwgExportSettingsNames(openedDoc).First().GetDWGExportOptions();
                    }
                    else
                    {
                        dwgOptions = curDwgSettings.First().GetDWGExportOptions();
                    }
                }

                //печатаю каждый лист
                foreach (MySheet msheet in mSheets)
                {
                    Debug.WriteLine(" ");
                    Debug.WriteLine("Печатается лист: " + msheet.sheet.Name);
                    if (printSettings.refreshSchedules)
                    {
                        SchedulesRefresh.Start(openedDoc, msheet.sheet);
                        Debug.WriteLine("Спецификации обновлены успешно");
                    }


                    using (Transaction t = new Transaction(openedDoc))
                    {
                        t.Start("Профили печати");

                        string fileName0 = "";
                        if (printSettings.mergePdfs)
                        {
                            string guid = Guid.NewGuid().ToString();
                            fileName0 = msheet.sheet.SheetNumber + "_" + guid + ".pdf";
                        }
                        else
                        {
                            fileName0 = msheet.NameByConstructor(printSettings.nameConstructor);
                        }
                        string fileName = SheetSupport.ClearIllegalCharacters(fileName0);
                        if (fileName.Length > 128)
                        {
                            Debug.WriteLine("Имя листа длиннее 128 символов, будет урезано");
                            string cutname = fileName.Substring(0, 63);
                            cutname += fileName.Substring(fileName.Length - 64);
                            fileName = cutname;
                        }

                        if (printerName == "PDFCreator" && printSettings.useOrientation)
                        {
                            if (msheet.IsVertical)
                            {
                                SupportRegistry.SetOrientationForPdfCreator(OrientationType.Portrait);
                                Debug.WriteLine("Принудительно установлена Portrait ориентация");
                            }
                            if (!msheet.IsVertical)
                            {
                                SupportRegistry.SetOrientationForPdfCreator(OrientationType.Landscape);
                                Debug.WriteLine("Принудительно установлена Landscape ориентация");
                            }
                        }

                        for (int i = 0; i < msheet.titleBlocks.Count; i++)
                        {
                            string tempFilename = "";
                            if (msheet.titleBlocks.Count > 1)
                            {
                                Debug.WriteLine("На листе более 1 основной надписи! Печать части №" + i.ToString());
                                tempFilename = fileName.Replace(".pdf", "_" + i.ToString() + ".pdf");
                            }
                            else
                            {
                                Debug.WriteLine("На листе 1 основная надпись Id " + msheet.titleBlocks.First().Id.IntegerValue.ToString());
                                tempFilename = fileName;
                            }

                            string fullFilename = System.IO.Path.Combine(outputFolder, tempFilename);
                            Debug.WriteLine("Полное имя файла: " + fullFilename);

                            if (fullFilename.Length > 256)
                            {
                                throw new Exception("Слишком длинное имя файла " + fullFilename);
                            }

                            //смещаю область для печати многолистовых спецификаций
                            double offsetX = -i * msheet.widthMm / 25.4; //смещение задается в дюймах!
                            Debug.WriteLine("Смещение печати по X: " + offsetX.ToString("F3"));

                            PrintSetting ps = PrintSupport.CreatePrintSetting(openedDoc, pManager, msheet, printSettings, offsetX, 0);

                            pManager.PrintSetup.CurrentPrintSetting = ps;
                            Debug.WriteLine("Настройки печати применены, " + ps.Name);


                            PrintSupport.PrintView(msheet.sheet, pManager, ps, tempFilename);
                            Debug.WriteLine("Лист успешно отправлен на принтер");
                            msheet.PdfFileName = fullFilename;
                            printedSheets.Add(new MySheet(msheet));
                        }

                        if (printerName == "PDFCreator" && printSettings.useOrientation)
                        {
                            System.Threading.Thread.Sleep(5000);
                        }

                        t.RollBack();
                    }

                    //если включен dwg - то ещё экспортирую этот лист
                    if (printSettings.exportToDwg)
                    {
                        List <ElementId> sheetsIds = new List <ElementId> {
                            msheet.sheet.Id
                        };
                        string sheetname = msheet.NameByConstructor(printSettings.dwgNameConstructor);
                        openedDoc.Export(outputFolder, sheetname, sheetsIds, dwgOptions);
                    }
                }

                if (rlt != null)
                {
                    openedDoc.Close(false);
#if R2017
                    RevitLinkLoadResult LoadResult = rlt.Reload();
#else
                    LinkLoadResult loadResult = rlt.Reload();
#endif
                    Debug.WriteLine("Ссылочный документ закрыт");
                }
            }
            int printedSheetsCount = printedSheets.Count;
            printedSheets.Sort();

            //если требуется постобработка файлов - ждем, пока они напечатаются
            if (printSettings.colorsType == ColorType.MonochromeWithExcludes || printSettings.mergePdfs)
            {
                Debug.WriteLine("Включена постобработка файлов; ожидание окончания печати. Требуемое число файлов " + printedSheetsCount.ToString());
                int watchTimer = 0;
                while (printToFile)
                {
                    int filescount = System.IO.Directory.GetFiles(outputFolder, "*.pdf").Length;
                    Debug.WriteLine("Итерация №" + watchTimer + ", файлов напечатано " + filescount);
                    if (filescount >= printedSheetsCount)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(500);
                    watchTimer++;


                    if (watchTimer > 100)
                    {
                        BalloonTip.Show("Обнаружены неполадки", "Печать PDF заняла продолжительное время или произошел сбой. Дождитесь окончания печати.");
                        Debug.WriteLine("Не удалось дождаться окончания печати");
                        return(Result.Failed);
                    }
                }
            }


            List <string> pdfFileNames = printedSheets.Select(i => i.PdfFileName).ToList();
            Debug.WriteLine("PDF файлы которые должны быть напечатаны:");
            foreach (string pdfname in pdfFileNames)
            {
                Debug.WriteLine("  " + pdfname);
            }
            Debug.WriteLine("PDF файлы напечатанные по факту:");
            foreach (string pdfnameOut in System.IO.Directory.GetFiles(outputFolder, "*.pdf"))
            {
                Debug.WriteLine("  " + pdfnameOut);
            }

            //преобразую файл в черно-белый при необходимости
            if (printSettings.colorsType == ColorType.MonochromeWithExcludes)
            {
                Debug.WriteLine("Преобразование PDF файла в черно-белый");
                foreach (MySheet msheet in printedSheets)
                {
                    if (msheet.ForceColored)
                    {
                        Debug.WriteLine("Лист не преобразовывается в черно-белый: " + msheet.sheet.Name);
                        continue;
                    }

                    string file    = msheet.PdfFileName;
                    string outFile = file.Replace(".pdf", "_OUT.pdf");
                    Debug.WriteLine("Файл будет преобразован из " + file + " в " + outFile);

                    pdf.PdfWorker.SetExcludeColors(printSettings.excludeColors);
                    pdf.PdfWorker.ConvertToGrayScale(file, outFile);

                    //GrayscaleConvertTools.ConvertPdf(file, outFile, ColorType.Grayscale, new List<ExcludeRectangle> { rect, rect2 });

                    System.IO.File.Delete(file);
                    System.IO.File.Move(outFile, file);
                    Debug.WriteLine("Лист успешно преобразован");
                }
            }



            //объединяю файлы при необходимости
            if (printSettings.mergePdfs)
            {
                Debug.WriteLine(" ");
                Debug.WriteLine("\nОбъединение PDF файлов");
                System.Threading.Thread.Sleep(500);
                string combinedFile = System.IO.Path.Combine(outputFolder, mainDoc.Title + ".pdf");

                BatchPrintYay.pdf.PdfWorker.CombineMultiplyPDFs(pdfFileNames, combinedFile);

                foreach (string file in pdfFileNames)
                {
                    System.IO.File.Delete(file);
                    Debug.WriteLine("Удален файл " + file);
                }
                Debug.WriteLine("Объединено успешно");
            }

            if (printToFile)
            {
                System.Diagnostics.Process.Start(outputFolder);
                Debug.WriteLine("Открыта папка " + outputFolder);
            }

            //восстанавливаю настройки PDFCreator
            //if(printerName == "PDFCreator")
            //{
            //    SupportRegistry.RestoreSettingsForPDFCreator();
            //}


            string msg = "Напечатано листов: " + printedSheetsCount;
            BalloonTip.Show("Печать завершена!", msg);
            Debug.WriteLine("Печать успешно завершена, напечатано листов " + printedSheetsCount);
            return(Result.Succeeded);
        }
Esempio n. 7
0
        /// <summary>
        /// Получает листы из всех открытых документов
        /// </summary>
        /// <param name="commandData"></param>
        /// <returns></returns>
        public static Dictionary <string, List <MySheet> > GetAllSheets(ExternalCommandData commandData, YayPrintSettings printSets)
        {
            Dictionary <string, List <MySheet> > data = new Dictionary <string, List <MySheet> >();
            Document mainDoc      = commandData.Application.ActiveUIDocument.Document;
            string   mainDocTitle = GetDocTitleWithoutRvt(mainDoc.Title);

            List <RevitLinkInstance> links = new FilteredElementCollector(mainDoc)
                                             .OfClass(typeof(RevitLinkInstance))
                                             .Cast <RevitLinkInstance>()
                                             .ToList();

            List <MySheet> mainSheets = GetSheetsFromDocument(mainDoc, printSets);

            data.Add(mainDocTitle, mainSheets);

            foreach (RevitLinkInstance rli in links)
            {
                Document linkDoc = rli.GetLinkDocument();
                if (linkDoc == null)
                {
                    continue;
                }
                string linkDocTitle = GetDocTitleWithoutRvt(linkDoc.Title);
                if (data.ContainsKey(linkDocTitle))
                {
                    continue;
                }

                RevitLinkType  rlt       = mainDoc.GetElement(rli.GetTypeId()) as RevitLinkType;
                List <MySheet> curSheets = GetSheetsFromDocument(linkDoc, printSets);

                data.Add(linkDocTitle, curSheets);
            }

            return(data);
        }
Esempio n. 8
0
        public static PrintSetting CreatePrintSetting(Document doc, PrintManager pManager, MySheet mSheet, YayPrintSettings printSettings, double offsetX, double offsetY)
        {
            PrintSetup pSetup = pManager.PrintSetup;

            IPrintSetting   ps  = pSetup.InSession as IPrintSetting;
            PrintParameters pps = ps.PrintParameters;

            pps.HideCropBoundaries       = true;
            pps.HideReforWorkPlanes      = true;
            pps.HideScopeBoxes           = true;
            pps.HideUnreferencedViewTags = false;
            pps.ZoomType = ZoomType.Zoom;
            pps.Zoom     = 100;

            pps.PaperPlacement     = PaperPlacementType.Margins;
            pps.MarginType         = MarginType.UserDefined;
            pps.UserDefinedMarginX = offsetX;
            pps.UserDefinedMarginY = offsetY;

            //RasterQualityType rqt =(RasterQualityType)Enum.Parse(typeof(RasterQualityType), printSettings.rasterQuality);
            pps.RasterQuality = printSettings.rasterQuality;

            //HiddenLineViewsType hlvt = (HiddenLineViewsType)Enum.Parse(typeof(HiddenLineViewsType), printSettings.hiddenLineProcessing);
            pps.HiddenLineViews = printSettings.hiddenLineProcessing;

            ColorDepthType cdt = ColorDepthType.Color;

            if (printSettings.colorsType == ColorType.Monochrome)
            {
                cdt = ColorDepthType.BlackLine;
            }
            if (printSettings.colorsType == ColorType.GrayScale)
            {
                cdt = ColorDepthType.GrayScale;
            }
            pps.ColorDepth = cdt;



            if (mSheet.revitPaperSize == null)
            {
                string msg = "Не найден размер формата для листа "
                             + mSheet.sheet.SheetNumber + " : " + mSheet.sheet.Name + ". Назначен формат по умолчанию.";
                Autodesk.Revit.UI.TaskDialog.Show("Error", msg);

                foreach (PaperSize curPsize in pManager.PaperSizes)
                {
                    if (curPsize.Name.Equals("A4"))
                    {
                        ps.PrintParameters.PaperSize = curPsize;
                        mSheet.IsVertical            = true;
                    }
                }
            }
            else
            {
                try
                {
                    ps.PrintParameters.PaperSize = mSheet.revitPaperSize;
                }
                catch (Exception ex)
                {
                    string msg = "Не удалось назначить формат бумаги " + mSheet.revitPaperSize.Name
                                 + "\nНазначен формат по умолчанию. Попробуйте запустить печать еще раз."
                                 + "\nИнформация об ошибке: " + ex.Message;
                    Autodesk.Revit.UI.TaskDialog.Show("Error", msg);
                }
            }

            if (mSheet.IsVertical)
            {
                pps.PageOrientation = PageOrientationType.Portrait;
            }
            else
            {
                pps.PageOrientation = PageOrientationType.Landscape;
            }

            pSetup.CurrentPrintSetting = ps;
            string printSetupName = "YayPrint" + DateTime.Now.ToShortTimeString() + "x" + (offsetX * 25.4).ToString("F0");

            pSetup.SaveAs(printSetupName);
            // pManager.Apply();

            doc.Regenerate();

            PrintSetting yayPs = new FilteredElementCollector(doc)
                                 .OfClass(typeof(PrintSetting))
                                 .Where(i => i.Name == printSetupName)
                                 .Cast <PrintSetting>()
                                 .First();

            return(yayPs);
        }
Esempio n. 9
0
 private void buttonReset_Click(object sender, EventArgs e)
 {
     Colors = YayPrintSettings.GetStandardExcludeColors();
     RefreshColors();
 }
Esempio n. 10
0
        public FormPrint(Dictionary <string, List <MySheet> > SheetsBase, YayPrintSettings printSettings)
        {
            InitializeComponent();
            //labelVersion.Text = System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString();
            this.AcceptButton = btnOk;
            this.CancelButton = btnCancel;

            sheetsBaseToPrint = SheetsBase;

            //заполняю treeView
            foreach (var docWithSheets in sheetsBaseToPrint)
            {
                TreeNode docNode     = new TreeNode(docWithSheets.Key);
                bool     haveChecked = false;
                foreach (MySheet sheet in docWithSheets.Value)
                {
                    string   sheetTitle = sheet.ToString();
                    TreeNode sheetNode  = new TreeNode(sheetTitle);
                    sheetNode.Checked = sheet.IsPrintable;
                    if (sheet.IsPrintable)
                    {
                        haveChecked = true;
                    }
                    docNode.Nodes.Add(sheetNode);
                }
                if (haveChecked)
                {
                    docNode.Expand();
                }
                treeView1.Nodes.Add(docNode);
            }

            //заполняю параметры печати
            _printSettings = printSettings;
            textBoxNameConstructor.Text = printSettings.nameConstructor;
            txtBoxOutputFolder.Text     = printSettings.outputFolder;
            checkBoxMergePdfs.Checked   = printSettings.mergePdfs;


            List <string> printers = new List <string>();

            foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            {
                printers.Add(printer);
            }
            if (printers.Count == 0)
            {
                throw new Exception("Cant find any installed printers");
            }
            comboBoxPrinters.DataSource = printers;

            if (printers.Contains(_printSettings.printerName))
            {
                comboBoxPrinters.SelectedItem = printers.Where(i => i.Equals(_printSettings.printerName)).First();
            }
            else
            {
                string selectedPrinterName = PrinterUtility.GetDefaultPrinter();
                if (!printers.Contains(selectedPrinterName))
                {
                    throw new Exception("Cant find printer " + selectedPrinterName);
                }
                comboBoxPrinters.SelectedItem = printers.Where(i => i.Equals(selectedPrinterName)).First();
            }



            radioButtonPDF.Checked   = comboBoxPrinters.SelectedItem.ToString().Contains("PDF");
            radioButtonPaper.Checked = !radioButtonPDF.Checked;


            if (_printSettings.hiddenLineProcessing == Autodesk.Revit.DB.HiddenLineViewsType.VectorProcessing)
            {
                radioButtonVector.Checked = true;
                radioButtonRastr.Checked  = false;
            }
            else
            {
                radioButtonVector.Checked = false;
                radioButtonRastr.Checked  = true;
            }

            List <Autodesk.Revit.DB.RasterQualityType> rasterTypes =
                Enum.GetValues(typeof(Autodesk.Revit.DB.RasterQualityType))
                .Cast <Autodesk.Revit.DB.RasterQualityType>()
                .ToList();

            comboBoxRasterQuality.DataSource = rasterTypes;
            try
            {
                comboBoxRasterQuality.SelectedItem = _printSettings.rasterQuality;
                //rasterQualityTypes.Where(i => Enum.GetName(typeof(Autodesk.Revit.DB.RasterQualityType), i).Equals()).First();
            }
            catch { }

            List <ColorType> colorTypes = Enum.GetValues(typeof(ColorType))
                                          .Cast <ColorType>()
                                          .ToList();

            comboBoxColors.DataSource        = colorTypes;
            comboBoxColors.SelectedItem      = _printSettings.colorsType;
            textBoxAlwaysColorParamName.Text = _printSettings.alwaysColorParamName;

            checkBoxExportDwg.Checked      = _printSettings.exportToDwg;
            textBoxDwgNameConstructor.Text = _printSettings.dwgNameConstructor;
            List <string> dwgExportSettingsList = _printSettings.dwgProfiles.Select(i => i.Name).ToList();

            comboBoxDwgProfiles.DataSource = dwgExportSettingsList;
            if (dwgExportSettingsList.Contains(_printSettings.selectedDwgExportProfileName))
            {
                comboBoxDwgProfiles.SelectedItem = _printSettings.selectedDwgExportProfileName;
            }
        }