Hi, I have an IExternalCommand that should print some view sheets as .pdf and .plt into files.
I'm getting an "Illegal paper size" exception when I try to set the paper size after changing the printer.
Shouldn't the printMgr.PaperSizes return only valid paper sizes for the selected printer?
printManager.SelectNewPrintDriver(printerName);
foreach (PaperSize ps in printMgr.PaperSizes) { if (ps.Name.Equals(value)) { printMgr.PrintSetup.CurrentPrintSetting.PrintParameters.PaperSize = ps; //throws ArgumentException "Illegal paper size" return true; } }
If I run the method for one printer, then close Revit, change the printer in the code and run for the other printer, it works.
Can anybody help me please? It's driving me crazy...
Solved! Go to Solution.
Hi, I have an IExternalCommand that should print some view sheets as .pdf and .plt into files.
I'm getting an "Illegal paper size" exception when I try to set the paper size after changing the printer.
Shouldn't the printMgr.PaperSizes return only valid paper sizes for the selected printer?
printManager.SelectNewPrintDriver(printerName);
foreach (PaperSize ps in printMgr.PaperSizes) { if (ps.Name.Equals(value)) { printMgr.PrintSetup.CurrentPrintSetting.PrintParameters.PaperSize = ps; //throws ArgumentException "Illegal paper size" return true; } }
If I run the method for one printer, then close Revit, change the printer in the code and run for the other printer, it works.
Can anybody help me please? It's driving me crazy...
Solved! Go to Solution.
Solved by ali.talebi. Go to Solution.
No one? I can't find enything in google when I search for "Illegal paper size" revit...
No one? I can't find enything in google when I search for "Illegal paper size" revit...
cshha, I haven't tried with other print drivers.
This happens when I change from PDFCreator to OCE TDS860 or vice versa.
Have you managed to print with two or more different drivers in the same method into different files?
cshha, I haven't tried with other print drivers.
This happens when I change from PDFCreator to OCE TDS860 or vice versa.
Have you managed to print with two or more different drivers in the same method into different files?
I've got also this error when I'm working with the "in-session" setting. It works if I use a named setting. I think PrintManager is the most buggy thing in Revit...
My code:
// Utility method to find a print setting in the document
public static class DocumentExtensions { public static PrintSetting FindPrintSetting(this Document document, string name) { if (document == null) throw new ArgumentNullException(nameof(document)); if (name == null) throw new ArgumentNullException(nameof(name)); using (var collector = new FilteredElementCollector(document)) { return collector.OfClass(typeof (PrintSetting)).Cast<PrintSetting>().FirstOrDefault(ps => ps.Name == name); } } }
[..] // Use a variable to hold an unique reference because Document.PrintManager returns a copy // each time... PrintManager pm = doc.PrintManager; IPrintSetting initialSetting = pm.PrintSetup.CurrentPrintSetting; const string PRINTER_NAME = "PDFCreator"; PrintSetting setting = doc.FindPrintSetting(PRINTER_NAME); if (setting != null) doc.Delete(setting.Id); pm.PrintSetup.SaveAs(PRINTER_NAME); setting = doc.FindPrintSetting(PRINTER_NAME); pm.PrintSetup.CurrentPrintSetting = setting; pm.SelectNewPrintDriver(PRINTER_NAME); var sheet = (ViewSheet)doc.ActiveView; foreach (PaperSize ps in pm.PaperSizes) { if (ps.Name.Equals(value)) { pm.PrintSetup.CurrentPrintSetting.PrintParameters.PaperSize = ps; break; } } pm.PrintSetup.Save(); pm.SubmitPrint(sheet); pm.PrintSetup.Delete(); if (initialSetting != pm.PrintSetup.InSession) pm.PrintSetup.CurrentPrintSetting = initialSetting;
I've got also this error when I'm working with the "in-session" setting. It works if I use a named setting. I think PrintManager is the most buggy thing in Revit...
My code:
// Utility method to find a print setting in the document
public static class DocumentExtensions { public static PrintSetting FindPrintSetting(this Document document, string name) { if (document == null) throw new ArgumentNullException(nameof(document)); if (name == null) throw new ArgumentNullException(nameof(name)); using (var collector = new FilteredElementCollector(document)) { return collector.OfClass(typeof (PrintSetting)).Cast<PrintSetting>().FirstOrDefault(ps => ps.Name == name); } } }
[..] // Use a variable to hold an unique reference because Document.PrintManager returns a copy // each time... PrintManager pm = doc.PrintManager; IPrintSetting initialSetting = pm.PrintSetup.CurrentPrintSetting; const string PRINTER_NAME = "PDFCreator"; PrintSetting setting = doc.FindPrintSetting(PRINTER_NAME); if (setting != null) doc.Delete(setting.Id); pm.PrintSetup.SaveAs(PRINTER_NAME); setting = doc.FindPrintSetting(PRINTER_NAME); pm.PrintSetup.CurrentPrintSetting = setting; pm.SelectNewPrintDriver(PRINTER_NAME); var sheet = (ViewSheet)doc.ActiveView; foreach (PaperSize ps in pm.PaperSizes) { if (ps.Name.Equals(value)) { pm.PrintSetup.CurrentPrintSetting.PrintParameters.PaperSize = ps; break; } } pm.PrintSetup.Save(); pm.SubmitPrint(sheet); pm.PrintSetup.Delete(); if (initialSetting != pm.PrintSetup.InSession) pm.PrintSetup.CurrentPrintSetting = initialSetting;
Continued in the following thread:
http://forums.autodesk.com/t5/revit-api/illegal-papersize-digital-printer-driver-issue/m-p/5786641
Which in turn was escalated to ADN case 11038513 [Illegal Papersize / digital printer driver issue] and the development issue REVIT-74585 [API insession print setting throws illegal papersize argument exception].
Continued in the following thread:
http://forums.autodesk.com/t5/revit-api/illegal-papersize-digital-printer-driver-issue/m-p/5786641
Which in turn was escalated to ADN case 11038513 [Illegal Papersize / digital printer driver issue] and the development issue REVIT-74585 [API insession print setting throws illegal papersize argument exception].
when setting the new printer, the PrintManager object is changed internally. so it is required to obtain a new PrintManager:
printManager.SetNewPrinter("SomePrinter"); printManager = revitDoc.PrintManager; // the rest of the code
when setting the new printer, the PrintManager object is changed internally. so it is required to obtain a new PrintManager:
printManager.SetNewPrinter("SomePrinter"); printManager = revitDoc.PrintManager; // the rest of the code
thanks. it works!
Thank you for that!
Thank you for that!
Can't find what you're looking for? Ask the community or share your knowledge.