/// <summary> /// Находит формат листа /// </summary> /// <param name="pManager"></param> /// <param name="format"></param> /// <returns></returns> //public static PaperSize SearchPaperSize(PrintManager pManager, SheetFormat format) //{ // PaperSizeSet pss = pManager.PaperSizes; // if (format.PrinterPaperSizes == null) return null; // foreach (PaperSize pSize in pss) // { // for (int i = 0; i < format.PrinterPaperSizes.Count; i++) // { // string paperSizeName = format.PrinterPaperSizes[i]; // bool check = StringAwesomeEquals(pSize.Name, paperSizeName); // if (check) // { // return pSize; // } // } // } // return null; //} /// <summary> /// Находит формат листа в Revit по его имени /// </summary> /// <param name="pManager"></param> /// <param name="formatName"></param> /// <returns></returns> public static PaperSize SearchRevitPaperSizeByName(PrintManager pManager, string formatName) { PaperSizeSet pss = pManager.PaperSizes; foreach (PaperSize pSize in pss) { if (pSize.Name == formatName) { return(pSize); } } return(null); }
PaperSize setPaperSize(Document doc) { PrintManager PrintMan = doc.PrintManager; PaperSizeSet myPSize = PrintMan.PaperSizes; Form1 newForm = new Form1(myPSize); newForm.ShowDialog(); PaperSize myPS = newForm.ps; return(myPS); }
public Form1(PaperSizeSet pss) { InitializeComponent(); listBox1.DataSource = pss as IList <PaperSize>; listBox1.DisplayMember = "Name"; //listBox1.ValueMember = "Id"; foreach (PaperSize item in pss) { listBox1.Items.Add(item); } //listBox1.d }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection selection = uidoc.Selection; PrintManager pm = doc.PrintManager; pm.PrintRange = PrintRange.Select; ViewSheetSetting vss = pm.ViewSheetSetting; ICollection <ElementId> id; FilteredElementCollector collector; ElementClassFilter wantedElements; PaperSizeSet paperSize = pm.PaperSizes; List <Element> printElemes = null; using (Transaction trans = new Transaction(doc, "Print ViewSet")) { try { id = selection.GetElementIds(); collector = new FilteredElementCollector(doc, id); wantedElements = new ElementClassFilter(typeof(ViewSheet)); collector.WherePasses(wantedElements); printElemes = collector.ToElements() as List <Element>; } catch (Autodesk.Revit.Exceptions.ApplicationException e) { TaskDialog.Show("Error!", e.Message); return(Result.Cancelled); } catch (Exception e) { TaskDialog.Show("Error!", e.Message); } ViewSet viewSet = new ViewSet(); foreach (var elem in printElemes) { ViewSheet viewSheet = elem as ViewSheet; viewSet.Insert(viewSheet); } trans.Start(); try { vss.CurrentViewSheetSet.Views = viewSet; vss.Save(); pm.SelectNewPrintDriver("Microsoft Print to PDF"); pm.Apply(); //pm.PrintSetup.Save(); pm.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation = PageOrientationType.Landscape; pm.PrintSetup.CurrentPrintSetting.PrintParameters.PaperPlacement = PaperPlacementType.Center; pm.PrintSetup.CurrentPrintSetting.PrintParameters.ZoomType = ZoomType.Zoom; pm.PrintSetup.CurrentPrintSetting.PrintParameters.Zoom = 100; pm.CombinedFile = true; //pm.PrintToFile = true; //pm.PrintToFileName = @"C:\Users\Lenovo\Desktop\file.pdf"; pm.Apply(); //pm.PrintSetup.Save(); pm.SubmitPrint(); } catch (Exception e) { message = e.Message; return(Result.Failed); } trans.Commit(); // return Result.Succeeded; } return(Result.Succeeded); }