Advertisement

Saturday, November 25, 2017

Detecting Empty Views with the Revit API

From The Building Coder:

By Jeremy Tammik
November 9, 2017

Detecting Empty Views

On another related topic, my colleague Philipp Kast, Principal Engineer at Autodesk, shared an approach to detect empty views, i.e., views which do not display any visible object, and his research steps leading up to his current approach:

I am working on the Revit Extractor. We are creating so-called master views, which are views for each phase in the Revit model.

Recently we fixed an issue concerning empty views for phases that have no content.
So, we added the following code to detect whether a given view is empty:

  private bool IsEmptyMasterView( View view )
  {
    using( FilteredElementCollector collector 
      = new FilteredElementCollector( doc, view.Id ) )
    {
      return !collector.Any();
    }
  }

That worked well. But then a model came along that had empty views again, because it contained division and curtain elements that are not visible.

So, we adapted this code, basically skipping those categories:

  using( FilteredElementCollector collector
    = new FilteredElementCollector( doc, view.Id ) )
  {
    var invisibleCategories = new HashSet<ElementId>
    {
       new ElementId(BuiltInCategory.OST_Divisions),
       new ElementId(BuiltInCategory.OST_CurtaSystemFaceManager)
    };
    return collector.All(
      element => element.Category != null
      && invisibleCategories.Contains(
        element.Category.Id ) );
  }

Now again, yet another model includes other invisible elements.

So, I came up with the following check, by experimenting around:

  using( FilteredElementCollector collector
    = new FilteredElementCollector( doc, view.Id ) )
  {
    return collector.All(
      element => element.Category != null
      && !element.Category.get_AllowsVisibilityControl(
        view ) );
  }

This seems to work, but I’m not sure if it makes sense.

Any comment or input would be appreciated.

Thank you!

And thanks to Philipp for sharing this!



There's more information available on The Building Coder.

No comments: