Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Exporting ViewSheet element through ExportContext2D

pmeigneux
Advocate
Advocate

Exporting ViewSheet element through ExportContext2D

pmeigneux
Advocate
Advocate

Hello,

 

I am trying the use the ExportContext2D to export a ViewSheet type element.

 

I am receiving the following error:

pmeigneux_0-1605200654000.png

 

Here is a sample of code that I use:

            FilteredElementCollector colS = new FilteredElementCollector(Doc).OfClass(typeof(ViewSheet));

            foreach (ViewSheet sheet in colS)

            {

                            try

                            {

                                ExporterAdnMeshDS_UPS.ExportContext2D context = new ExporterAdnMeshDS_UPS.ExportContext2D(Doc);

                                CustomExporter exporter = new CustomExporter(Doc, context);

                                exporter.Export(vs);

                                exporter.Dispose();

                            }

                            catch (ArgumentNullException e)

                            {

                            }

                            catch (ArgumentException e)

                            {

                            }

                            catch (InvalidOperationException e)

                            {

                            }

}

 

Do you know an alternate way to realize the export of a ViewSheet? I was maybe thinking to convert it into another view type. Any best recommendation on it?

 

Thanks

0 Likes
Reply
Accepted solutions (1)
1,195 Views
9 Replies
Replies (9)

jeremytammik
Autodesk
Autodesk

You are looping over all the ViewSheet elements that you encounter, without checking anything further.

 

I believe you should always check for and eliminate template views, for instance.

 

I would suggest that you export the view sheets one by one and determine exactly which one causes a problem.

 

Maybe it is one that you should be skipping anyway.

 



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

0 Likes

pmeigneux
Advocate
Advocate

I don't see anything special on my views (see attachments).

0 Likes

pmeigneux
Advocate
Advocate

suite..

0 Likes

pmeigneux
Advocate
Advocate

suite..

0 Likes

pmeigneux
Advocate
Advocate

is it possible to export by CustomExporter2D viewsheets other than templates?

the viewsheets that I want to export, exort correctly with Doc.Export in dwg.

 

philippe

0 Likes

jeremytammik
Autodesk
Autodesk
Accepted solution

I tried to implement a test and encountered no problem whatsoever.

   

Here is the result of exporting the Level 1 view with a trivial 2D custom exporter implementation:

   

Sample view:

    

Screenshot 2020-11-18 at 16.48.00.png

    

Source code:

   

#region Namespaces
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
#endregion

namespace CustomExport2d
{
  [Transaction( TransactionMode.Manual )]
  public class Command : IExternalCommand
  {
    class CustomExport2dContext : IExportContext2D
    {
      public void Finish()
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public bool IsCanceled()
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return false;
      }

      public RenderNodeAction OnCurve( CurveNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return RenderNodeAction.Proceed;
      }

      public RenderNodeAction OnElementBegin( ElementId elementId )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return RenderNodeAction.Proceed;
      }

      public RenderNodeAction OnElementBegin2D( ElementNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return RenderNodeAction.Proceed;
      }

      public void OnElementEnd( ElementId elementId )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public void OnElementEnd2D( ElementNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public RenderNodeAction OnFaceBegin( FaceNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return RenderNodeAction.Proceed;
      }

      public RenderNodeAction OnFaceEdge2D( FaceEdgeNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return RenderNodeAction.Proceed;
      }

      public void OnFaceEnd( FaceNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public RenderNodeAction OnFaceSilhouette2D( FaceSilhouetteNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return RenderNodeAction.Proceed;
      }

      public RenderNodeAction OnInstanceBegin( InstanceNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return RenderNodeAction.Proceed;
      }

      public void OnInstanceEnd( InstanceNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public void OnLight( LightNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public void OnLineSegment( LineSegment segment )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public RenderNodeAction OnLinkBegin( LinkNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return RenderNodeAction.Proceed;
      }

      public void OnLinkEnd( LinkNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public void OnMaterial( MaterialNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public RenderNodeAction OnPolyline( PolylineNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return RenderNodeAction.Proceed;
      }

      public void OnPolylineSegments( PolylineSegments segments )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public void OnPolymesh( PolymeshTopology node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public void OnRPC( RPCNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public void OnText( TextNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public RenderNodeAction OnViewBegin( ViewNode node )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return RenderNodeAction.Proceed;
      }

      public void OnViewEnd( ElementId elementId )
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
      }

      public bool Start()
      {
        Debug.Print( System.Reflection.MethodBase.GetCurrentMethod().Name );
        return true;
      }
    }

    public Result Execute(
      ExternalCommandData commandData,
      ref string message,
      ElementSet elements )
    {
      UIApplication uiapp = commandData.Application;
      UIDocument uidoc = uiapp.ActiveUIDocument;
      Application app = uiapp.Application;
      Document doc = uidoc.Document;
      View view = doc.ActiveView;

      CustomExport2dContext c = new CustomExport2dContext();

      CustomExporter ce = new CustomExporter( doc, c );

      ce.Export( view );

      return Result.Succeeded;
    }
  }
}

    

Output result:

    

Start
IsCanceled
OnViewBegin
IsCanceled
OnElementBegin2D
IsCanceled
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
OnInstanceBegin
IsCanceled
OnInstanceEnd
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
OnInstanceBegin
OnInstanceEnd
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
OnInstanceBegin
OnInstanceEnd
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
OnElementEnd2D
OnViewEnd
IsCanceled
OnViewBegin
OnViewEnd
IsCanceled
OnViewBegin
IsCanceled
OnElementBegin2D
IsCanceled
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
OnInstanceBegin
OnCurve
OnCurve
OnCurve
OnCurve
OnCurve
IsCanceled
OnInstanceEnd
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
OnInstanceBegin
OnInstanceEnd
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
OnInstanceBegin
OnInstanceEnd
OnElementEnd2D
IsCanceled
OnElementBegin2D
IsCanceled
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
IsCanceled
OnFaceBegin
OnFaceEnd
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnFaceEdge2D
OnElementEnd2D
IsCanceled
OnElementBegin2D
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnElementEnd2D
IsCanceled
OnElementBegin2D
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnElementEnd2D
IsCanceled
OnElementBegin2D
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnElementEnd2D
IsCanceled
OnElementBegin2D
OnPolylineSegments
OnPolylineSegments
OnElementEnd2D
IsCanceled
OnElementBegin2D
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnElementEnd2D
IsCanceled
OnElementBegin2D
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnPolylineSegments
OnElementEnd2D
OnViewEnd
IsCanceled
OnViewBegin
OnViewEnd
Finish

    

Sample code attached.

   



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

0 Likes

pmeigneux
Advocate
Advocate

don't work with my document (in attachment).

0 Likes

pmeigneux
Advocate
Advocate

can no one help?

 

0 Likes

jeremytammik
Autodesk
Autodesk

Sure.

   

I tried using the custom exporter that I implemented above (attached) on your sample model and see that you are trying to export a sheet view.

 

I can reproduce the behaviour you describe:

  

custom_export_2d_view_not_exportable.png

 

Please read the documentation on the IExportContext2D interface; it clearly states: An interface that is used in custom export to export 2D views of a Revit model. I am sorry to have to point out that a sheet is not a 2D view of the model. That is presumably the reason why this exception is triggered: the view is not exportable, indeed.

    



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

0 Likes