Many elements of the graphics and display options for views are exposed via the API.
Because setting a view's display style to raytrace enters a special restricted mode with limited capabilities, it is not permitted to directly assign the display style to this value.
The View.DetailLevel property uses the ViewDetailLevel enumeration and corresponds to the detail level options available at the bottom of the Revit window as shown below.
The ViewDetailLevel enumeration includes Undefined in the case that a given View does not use detail level.
The Thin Lines option, available in the Revit UI on the Graphics panel of the View tab, controls how lines are drawn in a view. Typically, when you zoom in on a model in a small scale view, element lines appear much thicker than they actually are. When Thin Lines is enabled, all lines are drawn as a single width regardless of zoom level. This option is made available via the ThinLinesOptions utility class, which has a property called AreThinLinesEnabled. It is a static property which affects the entire Revit session.
The View class allows for control of temporary view modes. The View.EnableRevealHiddenMode() method turns on the reveal hidden elements mode for the view. View.EnableTemporaryAnalyticalDisplayMode() enables temporary display of Analytical Model categories only. And the View.DisableTemporaryViewMode()will disable the specified temporary view mode. The DisableTemporaryViewMode() method takes a TemporaryViewMode enum. The possible options are shown below.
Member Name |
Description |
RevealHiddenElements |
The reveal hidden elements mode |
TemporaryHideIsolate |
The temporary hide/isolate mode |
WorksharingDisplay |
One of the worksharing display modes |
AnalyticalModel |
The mode that isolates the analytical model |
Rayrace |
The mode that shows the model in interactive raytracing |
The View.IsInTemporaryViewMode method can be used to determine whether the view is currently in the specified TemporaryViewMode.
Views keep track of visible elements. All elements that are graphical and visible in the view can be retrieved using a FilteredElementCollector constructed with a document and the id of the view. However, some elements in the set may be hidden or covered by other elements. You can see them by rotating the view or removing the elements that cover them. Accessing these visible elements may require Revit to rebuild the geometry of the view. The first time your code uses this constructor for a given view, or the first time your code uses this constructor for a view whose display settings have just been changed, you may experience a significant performance degradation.
Elements are shown or hidden in a view by category.
A FilteredElementCollector based on a view will only contain elements visible in the current view. You cannot retrieve elements that are not graphical or elements that are invisible. A FilteredElementCollector based on a document retrieves all elements in the document including invisible elements and non-graphical elements. For example, when creating a default 3D view in an empty project, there are no elements in the view but there are many elements in the document, all of which are invisible.
The following code sample counts the number of wall category elements in the active document and active view. The number of elements in the active view differs from the number of elements in the document since the document contains non-graphical wall category elements.
Code Region: Counting elements in the active view |
private void CountElements(UIDocument uiDoc) { StringBuilder message = new StringBuilder(); FilteredElementCollector viewCollector = new FilteredElementCollector(uiDoc.Document, uiDoc.ActiveView.Id); viewCollector.OfCategory(BuiltInCategory.OST_Walls); message.AppendLine("Wall category elements within active View: " + viewCollector.ToElementIds().Count); FilteredElementCollector docCollector = new FilteredElementCollector(uiDoc.Document); docCollector.OfCategory(BuiltInCategory.OST_Walls); message.AppendLine("Wall category elements within document: " + docCollector.ToElementIds().Count); TaskDialog.Show("Revit", message.ToString()); } |
Temporary view modes can affect element visibility. The View.IsInTemporaryViewMode() method can be used to determine if a View is in a temporary view mode. The method View.IsElementVisibleInTemporaryViewMode() identifies if an element should be visible in the indicated view mode. This applies only to the TemporaryHideIsolate and AnalyticalModel view modes. Other modes will result in an exception.