2016-09-27 164 views
0

我正在尝试使用Revit API和Idling事件处理程序在Revit 2017中自动执行PDF打印过程。我使用OpenDocumentFile方法打开Revit文档,而不是在任何地方使用ActiveUIDocument。此过程正在生成无效操作异常。我不确定它为什么会提供例外或是否允许使用Revit API。请帮忙。谢谢。Revit转换为PDF格式

杂志输出:

' 1:< 0 <-pushSettingsIntoDriver 
' C 27-Sep-2016 14:45:22.641; 1:< ExportToRequestedFormat() : Pdf Print Exception : InvalidOperationExceptionAt least one view from the view set could not be printed. 
' at Autodesk.Revit.DB.Document.Print(ViewSet views, View viewTemplate, Boolean useCurrentPrintSettings) 
' at Autodesk.Revit.DB.Document.Print(ViewSet views, Boolean useCurrentPrintSettings) 
' at RevitCommandListener.RevitCommandListenerService.ExportToRequestedFormat(UIApplication uiapp) 

代码背后:

using (FilteredElementCollector viewCollector = new FilteredElementCollector(doc)) 
{ 
     ViewSet set = new ViewSet(); 
     ElementClassFilter viewFilter = null; 
     PrintManager pm = PrinterDriverSettings.GetPrintManager(doc, _ifcSaveFile, PrinterDriver.Bullzip); 

     switch (_pdfExportSetting) 
     { 
      case PDFExportOptions.SheetsOnly: 
       viewFilter = new ElementClassFilter(typeof(Autodesk.Revit.DB.ViewSheet)); 
       viewCollector.WherePasses(viewFilter); 

       foreach (Autodesk.Revit.DB.ViewSheet vw in viewCollector) 
       { 
         if (vw.CanBePrinted && !vw.IsTemplate) 
          set.Insert(vw); 
       } 
       break; 

      case PDFExportOptions.ViewsOnly: 
       viewFilter = new ElementClassFilter(typeof(Autodesk.Revit.DB.View)); 
       viewCollector.WherePasses(viewFilter); 

       foreach (Autodesk.Revit.DB.View vw in viewCollector) 
       { 
         if (vw.CanBePrinted && !vw.IsTemplate && !(vw.GetType() == typeof(ViewSheet))) //Skip sheets 
          set.Insert(vw); 
       } 
         break; 


      case PDFExportOptions.ViewsAndSheets: 

       viewFilter = new ElementClassFilter(typeof(Autodesk.Revit.DB.View)); 
       viewCollector.WherePasses(viewFilter); 

       foreach (Autodesk.Revit.DB.View vw in viewCollector) 
       { 
        if (vw.CanBePrinted && !vw.IsTemplate) 
         set.Insert(vw); 
       } 
       break; 

      case PDFExportOptions.Sections: 
       viewFilter = new ElementClassFilter(typeof(Autodesk.Revit.DB.ViewSection)); 
       viewCollector.WherePasses(viewFilter); 
       foreach (Autodesk.Revit.DB.ViewSection vw in viewCollector) 
       { 
         if (vw.CanBePrinted && && !vw.IsTemplate !(vw.ViewType == ViewType.Elevation)) 
         set.Insert(vw); 
       } 

       break; 

      case PDFExportOptions.Elevations: 
       viewFilter = new ElementClassFilter(typeof(Autodesk.Revit.DB.ViewSection)); 
       viewCollector.WherePasses(viewFilter); 

       foreach (Autodesk.Revit.DB.ViewSection vw in viewCollector) 
       { 
         if (vw.CanBePrinted && !vw.IsTemplate && vw.ViewType == ViewType.Elevation) 
         { 
          set.Insert(vw); 
         } 

        } 
        break; 

      case PDFExportOptions.Schedules: 
        viewFilter = new ElementClassFilter(typeof(ViewSchedule)); 
        viewCollector.WherePasses(viewFilter); 

        foreach (ViewSchedule vw in viewCollector) 
        { 
         if (vw.CanBePrinted && !vw.IsTemplate) 
          set.Insert(vw); 
        } 
        break; 
       } 

       if (_pdfExportSetting != PDFExportOptions.None && set.Size > 0) 
       { 
        Transaction tr = new Transaction(doc, "tr_pdf_print"); 

         try 
         { 
          tr.Start(); 
          doc.Print(set, true); 
          tr.Commit(); 
         } 
         catch(Autodesk.Revit.Exceptions.InvalidOperationException iopex) 
         { 
           uiapp.Application.WriteJournalComment("ExportToRequestedFormat() : Pdf Print Exception : InvalidOperationException" + iopex.Message + Environment.NewLine + iopex.StackTrace, true); 
         } 
          catch(Autodesk.Revit.Exceptions.ArgumentNullException argsex) 
         { 
           uiapp.Application.WriteJournalComment("ExportToRequestedFormat() : Pdf Print Exception : ArgumentNullException" + argsex.Message + Environment.NewLine + argsex.StackTrace, true); 
         } 
          catch(Autodesk.Revit.Exceptions.ArgumentException arex) 
         { 
           uiapp.Application.WriteJournalComment("ExportToRequestedFormat() : Pdf Print Exception : ArgumentException" + arex.Message + Environment.NewLine + arex.StackTrace, true); 
         } 
          catch(Autodesk.Revit.Exceptions.ApplicationException appex) 
         { 
           uiapp.Application.WriteJournalComment("ExportToRequestedFormat() : Pdf Print Exception : ApplicationException" + appex.Message + Environment.NewLine + appex.StackTrace, true); 
         } 
         finally 
         { 
          set.Dispose(); 
          viewFilter.Dispose(); 
          viewCollector.Dispose(); 
          pm.Dispose(); 
          tr.Dispose(); 
         } 

       } 

回答

2

除了IsPrintable场,其他的事情你需要检查是查看是否实际上是一个视图模板。使用IsTemplate来检查。

+0

感谢您的建议。我编辑了我的问题,包括检查模板,但它没有效果。有没有其他的失踪? – amit

+0

只是为了帮助专注 - 它是否会导致所有_pdfExportSetting案件都失败?或只是特定的? – Matt

+0

这是具体案件失败。 – amit

1

这对我来说太复杂了,也可能是Revit。

您有一个过滤元素收集器。

在您对这些元素的迭代中,您尝试启动事务加打印。

Keep it simple and smart!

首先,单独的过滤元件迭代中,交易和印刷成三个完全独立的操作。

然后计算这三者如何互动。

尽量减少交互作用,解决问题。