2016-09-27 12 views
0

Revit APIとIdlingイベントハンドラを使用してRevit 2017でPDF印刷のプロセスを自動化しようとしています。 OpenDocumentFileメソッドを使用してRevitドキュメントを開き、どこでもActiveUIDocumentを使用しません。このプロセスは無効な操作例外を生成しています。私はなぜそれが例外を与えているのか、またはRevit APIを使用して許可されているのかどうかはわかりません。助けてください。ありがとう。Revit to 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!

まず、別個の濾過要素の反復、トランザクション三の完全に独立した操作に印刷。

次に、これらの3つがどのようにやりとりする必要があるかを示します。

相互作用を最小限に抑えて、問題を解決する必要があります。