Advertisement

Monday, August 28, 2017

Using the API to Determine the Starting View

From the The Building Coder blog:

Determining the Starting View

August 17, 2017
By Jeremy Tammik

Skeletank shared an interesting and illuminating solution on StackOverflow showing how to pull the starting view for document using the Revit API:

Question: How can I use the Revit API to get the Starting View for a Document? The equivalent way to access it using the user interface is seen below:


Answer: I used the RevitLookup tool and browsed through the database to find a class called StartingViewSettings with the property ViewId that returns the ElementId of the starting view:


Here is my actual code for getting the view:

  FilteredElementCollector a
    = new FilteredElementCollector( doc )
      .OfClass( typeof( StartingViewSettings ) );

  View startingView = null;

  foreach( StartingViewSettings settings in a )
  {
    startingView = doc.GetElement(
      settings.ViewId ) as View;
  }

Many thanks to skeletank for researching and sharing this, and describing the effective approach to do so!



There's more information available on the The Building Coder website.

No comments: