Those Pesky View Templates

A post is coming soon about finding the height of a ceiling above a room which will be done with the ReferenceIntersector. ReferenceIntersector requires a 3D view.

In the previous example, this was done with a simple

(View3D)doc.ActiveView

but this not optimal as it requires that the active view must be a 3d view when the command is run. The class name (View3D) in parenthesis before the variable is a quick way to cast the ActiveView from a View to a View3D.

Here is the code to find all 3D Views in a document.

public void find3DViews()
// find all 3D views in the document
{
    Document doc = this.ActiveUIDocument.Document;

    // create collector
    FilteredElementCollector collector = new FilteredElementCollector(doc);

    // create list of 3D views.
    // the elements in the list are 3D Views, but they are stored as Elements in the list
    IList<Element> list = collector.OfClass(typeof(View3D)).ToList();

    string views = "";

    // loop through list of 3D views (which are still stored as Elements)
    foreach (Element e in list)
    {
        // Name is a property of Element, so we can get the view's name
        // while the view is stored as an element
        views += e.Name + "\n";
    }
    TaskDialog.Show("3D Views", views);
}

But this command in a document created from the default architectural template finds two “views” that aren’t listed in the Project Browser.

3d views

 

“Architectural Presentation 3D” and “Export to Civil Engineering” are view templates. Internally, view templates are Revit views, but they are also invalid input for most situations where a view must be specified. To exclude them, check the View.IsTemplate property.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s