PrintManager SaveAs Throws managed exception
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have an application which prints multiple PDF files to file.
This app is using Revits Printmanager to store settings.
foreach print, I get the printmanger to set new settings.
I think the issue may be occuring when trying to print multiple sheet sizes in one print session.
then i create new print settings foreach size.
Have anyone had these kinds of troubles ?
Selecte new printdriver:
var pm = _document.PrintManager;
pm.PrintSetup.CurrentPrintSetting = pm.PrintSetup.InSession;
pm.SelectNewPrintDriver(_pdfPrinter.Name);
pm = TrySaveAs($"Transmittal {new Random().Next().ToString()}", pm);
The try save as :
private PrintManager TrySaveAs(string name, PrintManager pm, int attempt = 1)
{
if (attempt > 10)
throw new Exception($"Could not save print settings. Tried {attempt} times ...");
var saveResult = pm.PrintSetup.SaveAs(name);
if (!saveResult)
return TrySaveAs(name + " " + attempt, pm, attempt += 1);
_lastUsedPrintSetup = name;
var pTTemp = new
FilteredElementCollector(_document).OfClass(typeof(PrintSetting)).ToElement
s().FirstOrDefault(el => el.Name.Equals(name)) as PrintSetting;
pm.PrintSetup.CurrentPrintSetting = pTTemp;
return pm;
}
=== The Exception logged ==
Exception: A managed exception was thrown by Revit or by one of its external applications.
Stack trace: at Autodesk.Revit.DB.PrintSetup.SaveAs(String newName)
at FocusRevitAdvancedTools.Helpers.PDFPrinter.PDFExportHandler.TrySaveAs(String name, PrintManager pm, Int32 attempt) in D:\Focu...
at FocusRevitAdvancedTools.Helpers.PDFPrinter.PDFExportHandler.SetViewSpecificAutodeskPrintParameters(IPrintViewItem printViewItem) in D:\Fo..
at FocusRevitAdvancedTools.Helpers.PDFPrinter.PDFExportHandler.PrintPdf(IPrintViewItem printViewItem) in D:\Foc..
at FocusRevitAdvancedTools.Helpers.PDFPrinter.PDFExportHandler.Print(IEnumerable`1 viewsToPrint) in D:\Foc..
at FocusRevitAdvancedTools.Helpers.PDFPrinter.PDFExportHandler.PrintPDFs(IEnumerable`1 printViewItems) in D:\Foc..
at FocusRevitAdvancedTools.Tools.Basis.PDFExportTool.Execute(ExternalCommandData commandData, String& message, ElementSet elements) in D:\Foc..