Hi All,
I created a fairly simple batch printing tool that works fine in Revit 2013 but crashes in 2014 after printing with an "An unrecoverable error has occured..." message box.
This is the relevant code (part of a larger class):
PrintManager printManager = doc.PrintManager;
printManager.PrintRange = PrintRange.Select;
printManager.ViewSheetSetting.SaveAs(Guid.NewGuid().ToString());
printManager.PrintSetup.CurrentPrintSetting.PrintParameters.ZoomType = ZoomType.FitToPage;
printManager.SelectNewPrintDriver(_driverName); // _driverName is a string property
printManager.PrintToFile = true;
foreach (WinForms.DataGridViewRow row in form.dgvSheets.SelectedRows)
{
PrintSheet ps = row.DataBoundItem as PrintSheet; // PrintSheet is a class that wraps ViewSheet
ViewSheet vs = ps.AssociatedSheet;
printManager.PrintToFileName = Path.Combine(Destination, ps.NewFileName);
if (File.Exists(printManager.PrintToFileName))
{
if (Overwrite)
File.Delete(printManager.PrintToFileName);
else
continue;
}
printManager.Apply();
bool ok = printManager.SubmitPrint(vs);
}
Any ideas?
Hi Remy,
Thanks for the reply.
It turned out to be the File.Delete() causing some kind of race condition - at least when I removed than part it works fine.
Not sure why it worked in 2013 though
- Sean