Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Illegal paper size

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
2415 Views, 8 Replies

Illegal paper size

Anonymous
Not applicable

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...

0 Likes

Illegal paper size

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...

8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

No one? I can't find enything in google when I search for "Illegal paper size" revit...

0 Likes

No one? I can't find enything in google when I search for "Illegal paper size" revit...

Message 3 of 9
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Does this happen with all print drivers or only with certain print drivers?
0 Likes

Does this happen with all print drivers or only with certain print drivers?
Message 4 of 9
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

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?

0 Likes

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?

Message 5 of 9
FRFR1426
in reply to: Anonymous

FRFR1426
Collaborator
Collaborator

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;
Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
0 Likes

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;
Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 6 of 9
jeremytammik
in reply to: Anonymous

jeremytammik
Autodesk
Autodesk

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].



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

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].



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 9
ali.talebi
in reply to: jeremytammik

ali.talebi
Contributor
Contributor
Accepted solution

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

 

Message 8 of 9
dangtrang
in reply to: ali.talebi

dangtrang
Contributor
Contributor

thanks. it works!

0 Likes

thanks. it works!

Message 9 of 9
Anonymous
in reply to: ali.talebi

Anonymous
Not applicable

Thank you for that!

0 Likes

Thank you for that!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report