Ejemplo n.º 1
0
        Stream(ArrayList data, PrintSetup prnSetup)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PrintSetup)));

            data.Add(new Snoop.Data.Object("Current print setting", prnSetup.CurrentPrintSetting));
            //data.Add(new Snoop.Data.Enumerable("Paper sizes", prnSetup.PaperSizes));
            //data.Add(new Snoop.Data.Enumerable("Paper sources", prnSetup.PaperSources));
        }
Ejemplo n.º 2
0
        private void PrintViewSheet(ViewSheet viewSheet, string sheetSize, PrintSetting printSetting, string filePath)
        {
            // creates view set
            ViewSet viewSet = new ViewSet();
            viewSet.Insert(viewSheet);
            PrintManager printManager = this.Doc.PrintManager;
            printManager.PrintRange = PrintRange.Select;
            printManager.Apply();

            // make new view set current
            ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;
            viewSheetSetting.CurrentViewSheetSet.Views = viewSet;

            // set printer
            printManager.SelectNewPrintDriver(this._PrinterName);
            printManager.Apply();

            // set file path
            printManager.CombinedFile = true;
            printManager.PrintToFileName = filePath;
            printManager.Apply();

            // set print setting
            this.Transaction.Start();
            PrintSetup printSetup = printManager.PrintSetup;
            printSetup.CurrentPrintSetting = printSetting;
            printManager.Apply();
            this.Transaction.Commit();

            List<Element> viewSets = new List<Element>(new FilteredElementCollector(this.Doc)
                                                       .OfClass(typeof(ViewSheetSet))
                                                       .ToElements());
            foreach (Element element in viewSets)
            {
                if (element.Name == "tempSetName")
                {
                    this.Transaction.Start();
                    this.Doc.Delete(element.Id);
                    this.Transaction.Commit();
                }
            }

            // save settings and submit print
            this.Transaction.Start();
            viewSheetSetting.SaveAs("tempSetName");
            printManager.Apply();
            printManager.SubmitPrint();
            viewSheetSetting.Delete();
            this.Transaction.Commit();
        }
Ejemplo n.º 3
0
        CollectEvent(object sender, CollectorEventArgs e)
        {
            // cast the sender object to the SnoopCollector we are expecting
            Collector snoopCollector = sender as Collector;

            if (snoopCollector == null)
            {
                Debug.Assert(false);    // why did someone else send us the message?
                return;
            }

            // see if it is a type we are responsible for
            Document doc = e.ObjToSnoop as Document;

            if (doc != null)
            {
                Stream(snoopCollector.Data(), doc);
                return;
            }

            Selection sel = e.ObjToSnoop as Selection;

            if (sel != null)
            {
                Stream(snoopCollector.Data(), sel);
                return;
            }

            Settings settings = e.ObjToSnoop as Settings;

            if (settings != null)
            {
                Stream(snoopCollector.Data(), settings);
                return;
            }

            Category cat = e.ObjToSnoop as Category;

            if (cat != null)
            {
                Stream(snoopCollector.Data(), cat);
                return;
            }

            PaperSize paperSize = e.ObjToSnoop as PaperSize;

            if (paperSize != null)
            {
                Stream(snoopCollector.Data(), paperSize);
                return;
            }

            PaperSource paperSource = e.ObjToSnoop as PaperSource;

            if (paperSource != null)
            {
                Stream(snoopCollector.Data(), paperSource);
                return;
            }

            PrintSetup prnSetup = e.ObjToSnoop as PrintSetup;

            if (prnSetup != null)
            {
                Stream(snoopCollector.Data(), prnSetup);
                return;
            }

            PrintParameters prnParams = e.ObjToSnoop as PrintParameters;

            if (prnParams != null)
            {
                Stream(snoopCollector.Data(), prnParams);
                return;
            }

            PlanTopology planTopo = e.ObjToSnoop as PlanTopology;

            if (planTopo != null)
            {
                Stream(snoopCollector.Data(), planTopo);
                return;
            }

            PlanCircuit planCircuit = e.ObjToSnoop as PlanCircuit;

            if (planCircuit != null)
            {
                Stream(snoopCollector.Data(), planCircuit);
                return;
            }

            PrintManager printManager = e.ObjToSnoop as PrintManager;

            if (printManager != null)
            {
                Stream(snoopCollector.Data(), printManager);
                return;
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates print settings usable for the paper sizes of selected print set.
        /// </summary>
        private void button3_Click(object sender, EventArgs e)
        {
            List <ViewSheet> viewSheetList = new List <ViewSheet>();

            if (selectedSheetSet == "Current sheet only")
            {
                Autodesk.Revit.DB.View view = doc.ActiveView;
                viewSheetList.Add((ViewSheet)view);
            }
            else
            {
                FilteredElementCollector col = new FilteredElementCollector(doc);
                var sheetSet = col.OfClass(typeof(ViewSheetSet))
                               .Where(x => x.Name == selectedSheetSet)
                               .Cast <ViewSheetSet>().FirstOrDefault();
                foreach (ViewSheet vs in sheetSet.Views)
                {
                    viewSheetList.Add(vs);
                }
            }

            PrintManager pm = doc.PrintManager;
            PrintSetup   ps = pm.PrintSetup;

            pm.SelectNewPrintDriver("Bluebeam PDF");
            pm = doc.PrintManager;
            ps = pm.PrintSetup;
            var paperSizes = pm.PaperSizes;

            FilteredElementCollector colPs = new FilteredElementCollector(doc);
            var printSettings = colPs.OfClass(typeof(PrintSetting)).Cast <PrintSetting>().ToHashSet();

            using (Transaction trans = new Transaction(doc))
            {
                trans.Start("PrintSettings");
                //PrintManager pm = doc.PrintManager;

                foreach (ViewSheet sheet in viewSheetList)
                {
                    FamilyInstance titleBlock =
                        fi.GetElements <FamilyInstance, BuiltInParameter>(doc, BuiltInParameter.SHEET_NUMBER, sheet.SheetNumber).FirstOrDefault();

                    var widthPar = titleBlock.get_Parameter(BuiltInParameter.SHEET_WIDTH);
                    var width    = Convert.ToInt32(widthPar.AsDouble().FtToMm().Round(0));

                    var heightPar = titleBlock.get_Parameter(BuiltInParameter.SHEET_HEIGHT);
                    var height    = Convert.ToInt32(heightPar.AsDouble().FtToMm().Round(0));

                    var nameOfPaperSize = paperSizeDict[height][width];

                    if (printSettings.Any(x => x.Name == nameOfPaperSize))
                    {
                        PrintSetting pset = printSettings.Where(x => x.Name == nameOfPaperSize).FirstOrDefault();
                        printSettings = printSettings.ExceptWhere(x => x.Name == nameOfPaperSize).ToHashSet();
                        doc.Delete(pset.Id);
                        doc.Regenerate();
                    }

                    pm.PrintRange  = PrintRange.Select;
                    pm.PrintToFile = true;

                    PrintSetup pSetup = pm.PrintSetup;
                    pSetup.CurrentPrintSetting = pm.PrintSetup.InSession;
                    PrintParameters pParams = pSetup.CurrentPrintSetting.PrintParameters;

                    pParams.ZoomType        = ZoomType.Zoom;
                    pParams.Zoom            = 100;
                    pParams.PageOrientation = PageOrientationType.Landscape;
                    pParams.PaperPlacement  = PaperPlacementType.Center;
                    if (radioButton1.Checked)
                    {
                        pParams.ColorDepth = ColorDepthType.Color;
                    }
                    else if (radioButton2.Checked)
                    {
                        pParams.ColorDepth = ColorDepthType.GrayScale;
                    }
                    else if (radioButton3.Checked)
                    {
                        pParams.ColorDepth = ColorDepthType.BlackLine;
                    }
                    pParams.RasterQuality                = RasterQualityType.Presentation;
                    pParams.HiddenLineViews              = HiddenLineViewsType.VectorProcessing;
                    pParams.ViewLinksinBlue              = false;
                    pParams.HideReforWorkPlanes          = true;
                    pParams.HideUnreferencedViewTags     = true;
                    pParams.HideCropBoundaries           = true;
                    pParams.HideScopeBoxes               = true;
                    pParams.ReplaceHalftoneWithThinLines = false;
                    pParams.MaskCoincidentLines          = false;

                    var paperSize = (from PaperSize psize in paperSizes where psize.Name.Equals(nameOfPaperSize) select psize).FirstOrDefault();

                    pParams.PaperSize = paperSize ?? throw new Exception("Printer does not have specified paper size! Check paper size configuration.");

                    pm.Apply();

                    try
                    {
                        pm.PrintSetup.SaveAs(paperSize.Name);
                    }
                    catch (Exception)
                    {
                    }
                }

                trans.Commit();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Retrieves print setting created for the specific paper size and prints all sheets in the set.
        /// </summary>
        private void button2_Click(object sender, EventArgs e)
        {
            //string sheetFileName;
            //string fullSheetFileName;
            //IList<string> fileNamesSource = new List<string>();
            //IList<string> fileNamesDefault = new List<string>();

            //Clear the fileNamesDestination
            fileNames.Clear();

            using (Transaction trans = new Transaction(doc))
            {
                //Update status window
                textBox8.Text = "Preparing print";

                trans.Start("Print!");

                List <ViewSheet> viewSheetList = new List <ViewSheet>();

                if (selectedSheetSet == "Current sheet only")
                {
                    Autodesk.Revit.DB.View view = doc.ActiveView;
                    viewSheetList.Add((ViewSheet)view);
                }
                else
                {
                    FilteredElementCollector col = new FilteredElementCollector(doc);
                    var sheetSet = col.OfClass(typeof(ViewSheetSet))
                                   .Where(x => x.Name == selectedSheetSet)
                                   .Cast <ViewSheetSet>().FirstOrDefault();
                    foreach (ViewSheet vs in sheetSet.Views)
                    {
                        viewSheetList.Add(vs);
                    }
                }

                FilteredElementCollector colPs = new FilteredElementCollector(doc);
                var printSettings = colPs.OfClass(typeof(PrintSetting)).Cast <PrintSetting>().ToHashSet();

                PrintManager pm = doc.PrintManager;
                PrintSetup   ps = pm.PrintSetup;
                pm.SelectNewPrintDriver("Bluebeam PDF");
                pm = doc.PrintManager;
                ps = pm.PrintSetup;
                var paperSizes = pm.PaperSizes;

                string title = doc.Title; //<- THIS CAN CAUSE PROBLEMS RECOGNISING THE ORIGINAL FILE NAME

                int sheetCount = 0;

                foreach (ViewSheet sheet in viewSheetList)
                {
                    #region Naming
                    //var revisionType = sheet.GetCurrentRevision();

                    FileNames fileName = new FileNames();
                    fileNames.Add(fileName);

                    Parameter sheetNumberPar = sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER);
                    string    sheetNumber    = sheetNumberPar.AsString();
                    fileName.SheetNumber = sheetNumber;

                    Parameter sheetNamePar = sheet.get_Parameter(BuiltInParameter.SHEET_NAME);
                    string    sheetName    = sheetNamePar.AsString();
                    fileName.SheetName = sheetName;

                    Parameter curRevisionPar = sheet.get_Parameter(BuiltInParameter.SHEET_CURRENT_REVISION);
                    string    revision       = curRevisionPar.AsString();
                    fileName.Revision = revision;

                    Parameter curRevisionDatePar = sheet.get_Parameter(BuiltInParameter.SHEET_CURRENT_REVISION_DATE);
                    string    revisionDate       = curRevisionDatePar.AsString();
                    fileName.RevisionDate = revisionDate;

                    Parameter sheetIssueDatePar = sheet.get_Parameter(BuiltInParameter.SHEET_ISSUE_DATE);
                    string    sheetIssueDate    = sheetIssueDatePar.AsString();
                    fileName.Date = sheetIssueDate;

                    Parameter curScalePar = sheet.LookupParameter("Scale");
                    if (curScalePar != null)
                    {
                        if (curScalePar.AsString() == "As indicated")
                        {
                            Parameter curScaleManualPar = sheet.LookupParameter("Manual skala");
                            if (curScaleManualPar != null)
                            {
                                fileName.Scale = curScaleManualPar.AsString();
                            }
                        }
                        else if (curScalePar.AsString() != "As indicated")
                        {
                            fileName.Scale = curScalePar.AsString();
                        }
                    }

                    Parameter sorting1Par = sheet.LookupParameter("RDK-COM-SHT-SORTING_1");
                    string    sorting1    = sorting1Par.AsString();
                    Parameter sorting2Par = sheet.LookupParameter("RDK-COM-SHT-SORTING_2");
                    string    sorting2    = sorting2Par.AsString();
                    fileName.DrawingListCategory = sorting1 + " - " + sorting2;

                    fileName.GenerateFileName();

                    fileName.FileNameWithPath = pathToExport + fileName.FileName;                                                       //Used to copy files later

                    string printfilename = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + fileName.FileName; //Used to satisfy bluebeam
                    //fileNamesSource.Add(printfilename);

                    //string defaultFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
                    //    + "\\" + title + " - Sheet - " + sheet.SheetNumber + " - " + sheet.Name + ".pdf";
                    //fileNamesDefault.Add(defaultFileName);

                    pm.PrintToFileName = printfilename;
                    #endregion

                    FamilyInstance titleBlock =
                        fi.GetElements <FamilyInstance, BuiltInParameter>(doc, BuiltInParameter.SHEET_NUMBER, sheet.SheetNumber).FirstOrDefault();

                    var widthPar = titleBlock.get_Parameter(BuiltInParameter.SHEET_WIDTH);
                    var width    = Convert.ToInt32(widthPar.AsDouble().FtToMm().Round(0));

                    var heightPar = titleBlock.get_Parameter(BuiltInParameter.SHEET_HEIGHT);
                    var height    = Convert.ToInt32(heightPar.AsDouble().FtToMm().Round(0));

                    var nameOfPaperSize = paperSizeDict[height][width];

                    var printSetting = (from PrintSetting pSetting in printSettings
                                        where pSetting.Name == nameOfPaperSize
                                        select pSetting).FirstOrDefault();

                    ps.CurrentPrintSetting = printSetting ?? throw new Exception($"{sheet.Name} does not have a print setting!");

                    pm.Apply();

                    //Feedback
                    sheetCount++;
                    textBox8.Text = "Sending " + sheetCount;

                    pm.SubmitPrint(sheet);

                    //Also export to DWF
                    DWFExportOptions dwfOptions    = new DWFExportOptions();
                    string           dwfExportPath = pathToExport + "\\DWF";
                    System.IO.Directory.CreateDirectory(dwfExportPath);

                    ViewSet vs = new ViewSet();
                    vs.Insert(sheet);

                    doc.Export(dwfExportPath, fileName.FileName.Remove(fileName.FileName.Length - 4), vs, dwfOptions);

                    System.Threading.Thread.Sleep(3000);
                }



                trans.Commit();
            }
            ////File handling
            //if (WaitForFile(fileNamesSource.Last(), fileNamesDefault.Last()))
            //{
            //    var result = tryOpenFiles(fileNamesSource.Last(), fileNamesDefault.Last());

            //    if (result.Item1)
            //    {
            //        foreach (var files in fileNamesSource.Zip(fileNamesDestination, Tuple.Create))
            //        {
            //            if (File.Exists(files.Item2)) File.Delete(files.Item2);
            //            File.Move(files.Item1, files.Item2);
            //        }
            //    }
            //    else if (result.Item2)
            //    {
            //        foreach (var files in fileNamesDefault.Zip(fileNamesDestination, Tuple.Create))
            //        {
            //            if (File.Exists(files.Item2)) File.Delete(files.Item2);
            //            File.Move(files.Item1, files.Item2);
            //        }
            //    }
            //    else throw new Exception("Filename handling FAILED AGAIN!!!!!!!");

            //}
            //else Shared.BuildingCoder.BuildingCoderUtilities.ErrorMsg("The copying of files failed for some reason!");
        }