Visible Elements

I am sitting here cramped up in an economy seat crossing the Atlantic Ocean as I write this.
I should urgently be practicing and preparing for my sessions at AU, but somehow it feels as if writing a blog post requires slightly less space, so here goes.
I would also like to answer some pending comments, but cannot right now due to lack of Internet access…

After revisiting the topic of

selecting all model elements
in the last post,
there is one more important and interesting issue to take into account to determine all the visible model elements.
In that post, we made use of element filtering instead of an iterator over all elements and eliminated a number of unwanted element types and categories.
Once we have thus whittled away the non-model elements, there are still several possibilities to hide elements in a given view through the user interface.
Here are two main methods that can be used to hide elements in a view:

  • Hide an individual element.
  • Hide an entire category of elements.

To determine whether an element is hidden, we need to check for both of these possibilities.
In addition, an element may belong to a subcategory.
If so, it may be hidden either because its subcategory or one of its parent categories is hidden.

The Revit SDK sample VisibilityControl demonstrates how to control visibility by category, and the topic of categories and how they are used is covered in detail in section 5.2.1 Category of the developer guide “Revit 2010 API Developer Guide.pdf”.

The visibility of an element in a view can be queried using the Element.IsHidden( View ) method, the visibility of a category by the Category.Visible property.

Here is the code of a helper method IsHiddenElementOrCategory which takes all these factors into account and can be used to check whether an element ‘e’ is hidden in a given view ‘v’.
It returns true if the given element is hidden in this view, either as an individual element, or because its category or one of its parent categories is hidden:


static bool IsHiddenElementOrCategory(
  Element e,
  View v )
{
  bool hidden = e.IsHidden( v );
 
  if( !hidden )
  {
    Category cat = e.Category;
    while( null != cat && !hidden )
    {
      hidden = !cat.get_Visible( v );
      cat = cat.Parent;
    }
  }
  return hidden;
}

Red Rock Revisited

By the way, some time has passed between starting to write and actually posting this.
I arrived safely in Las Vegas, grabbed a rental car, and went off to un-jetlag by spending the night in a sleeping bag in the desert.
Rather cold, but not freezing, this time around.
Two years ago, it was significantly below freezing and my gallon bottle of water froze solid, all the way down.
Last year, it was warmer and moister and had actually rained just before my arrival.
This year is the most pleasant to date.
Frankly, I prefer the desert to the strip.

I spent my first day here climbing in the

Red Rock
climbing area
with a bunch of crazy guys from Dallas, Texas, namely Karl, Fritz, Gary, Jess and Ellis.
We did several easy routes on the Ultraman wall, including Scent of an Ultraman 5.7, Clutch Cargo 5.7 and Science Patrol 5.8.

We met up early next morning again to go the

Black Corridor
,
which I visited in the previous two years as well.
I led a number of climbs in the morning including The Cel 50′ 5.9, Bon Ez 5.9+, and two of hardest and nicest I’ve ever done, Heavy Hitter and Friend 40′, both 5.10d.
The guys from Dallas left to return home at midday and I teamed up with Sonja & Jean-Francois from Quebec in the afternoon to climb two more routes led by Jean-Francois, Crude Street 5.9+ and Dance with a God 5.10a.

I am now sitting in the Barnes and Noble book store on West Charleston Boulevard and gratefully using the free Internet access they provide to finish off and post this.
This is the road that I keep going up and down to get to Red Rock.


Comments

13 responses to “Visible Elements”

  1. Hello Jemery,
    if i select one element and right click it,
    from the pop-up menu “Hide in View”->”By Filter”,
    add one filter to hide the element,
    then the method “IsHiddenElementOrCategory” doesn’t work.
    that is, the filter has no influence to
    method “IsHiddenElementOrCategory”.
    what i wanted is to obtain all the elements hidden via “By Filter”, not from by “Elements” or by “Category”.
    i saw REVIT2011 API provides new class ParameterFilterElement and FilterRule.
    the method FilterRule.ElementPasses(Element) can be used to determine if the element is hidden “By Filter”,
    but the filter can be disabled by uncheck it in the view Visibility/Graphic dialog.
    is it able to get the filter visibility in selected view?
    i can iterate all the filters and all the rules, but i can’t get the visibility of the filters.
    thanks!

  2. Dear Benson,
    I am sorry to say that the Revit 2011 API classes that you mention above all have to do with the filtered element collectors, and nothing at all with filters related to visibility in views.
    As far as I know, there is corrently no API access to the functionality you are asking for, and we have an open wish list item for it. I added a note of your reqeust to it to make the development team aware of its importance.
    Cheers, Jeremy.

  3. Dear Jemery,
    In Revit2010/Revit2011, the user can set the
    primary design option from the menu
    Manage->Design Options,
    my question is how can i obtain the primary
    design option via Revit2010 api?
    in Revit2011 api, we can use the static
    method:
    DesignOption.GetActiveDesignOptionId(Document)
    to get the primary design option,
    but Revit2010 api not provides such method.
    thanks in advance!
    BTW:
    in Revit2010, the Document.Elements
    not contains those elemnts which design option
    are not primary design option.
    but in Revit2011, when i use the code:
    FilteredElementCollector collector = new
    FilterElementCollector(documnet);
    FilteredElementIterator it =
    collector.WhereElementIsNotElementType()
    .GetElementIterator()
    the iterator “it” contains all the elements
    even their design option are not primary
    design option.

  4. Dear Benson,
    Sorry, I am not aware of any method to retrieve the primary design option programmatically in Revit 2010.
    And yes, you can use the Element.DesignOption property to filter for elements in a specific design option or the main model in Revit 2011. There is presumably a parameter that you can use as well to optimise the filtering.
    Cheers, Jeremy.

  5. Dear Benson,
    Have you looked at the method DesignOption.GetActiveDesignOptionId, which gets the ‘active’ design option id for the current design option set. Is that the primary design option?
    Cheers, Jeremy.

  6. Dear Jeremy,
    Thanks for your reply!
    yes, you are right, the method DesignOption.GetActiveDesignOptionId
    exists in Revit2011 api, this method can get ‘active’ design option id,
    however it is not the primary design option id.
    class property DesignOption.IsPrimary indicates if the design option is primary id.
    so, we can iterate all design option and then get the primary option.
    but in Revit2010 api,it not provides the method ‘GetActiveDesignOptionId’
    and property ‘IsPrimary’, so, it seems impossible to get the active design
    option and primary option.
    fortunately, i don’t need to consider the design option in Revit2010 so far,
    just need to consider it in Revit2011,
    so, it is not a problem for us currently.
    thanks again!
    Best regards,
    Benson

  7. Hi Jeremy,
    I’d like to hide an element in a dependent view but when i query the OwnerViewId of the element it returns the view id of the primary view. Is there a way to determine the id of the dependent view?
    Thanks for your very informative blog.

  8. Dear Mike,
    Thank you for your appreciation!
    The first thing I would do is an exhaustive analysis of the relationships between the views using RevitLookup. Make sure to look at all the built-in parameters as well using the built-in enum snoop. Maybe you can dig up some parameter or other data item that will help you track down the dependencies. Good luck!
    Cheers, Jeremy.

  9. Dear Mike,
    Here is an update on your question after a chat with the development team:
    The API currently does not provide any list of views dependent on a given view.
    Can you try to check the Dependency parameter of all views to find the ones that are dependent on the OwnerView?
    I hope this helps. Please let us know what your solution ends up looking like. Thank you!
    Cheers, Jeremy.

  10. Hi Jeremy,
    Thanks for your replies.
    I think your suggestion is similar to what i did. Because I want to hide a particular element in all views including dependent views I first query the elements OwnerViewId. Then I check the VIEW_DEPENDENCY of that view. If it is ‘Primary’ I search for all views that are dependent of this view. In each of these views I hide the selected element. This method certainly would not work if I wanted to hide the element in only 1 dependent view however. I have thought about the possibility of trying to locate the elements within bounding boxes however I’m not sure if that would be possible, I’ll have to check again, I don’t remember if I can get the box of the dependent view in the API.
    Thanks very much for your help.
    ps. I use RevitLookup all the time, it’s great!

  11. Dear Mike,
    I heard back from the development team. The issue is resolved and will become available in the intermediate release. Obviously no guarantee, but that’s the plan. Quick action, eh! Thank you for reporting the problem!
    Cheers, Jeremy.

  12. Hi Jeremy,
    Thanks for the code sample. However, I encountered some weird issue running the code today. After some digging, it seems before calling someCategroy.get_Visible(someView), one might want to check someCategory.get_AllowsVisibilityControl(someViwe) is true first.

  13. Dear Le Zhang,
    Thank you for the appreciation and the improvement.
    That definitely makes sense.
    Did you notice this way to detect element visibility, which is probably currently the most reliable approach?
    http://thebuildingcoder.typepad.com/blog/2013/08/determining-absolutely-all-visible-elements.html
    Cheers, Jeremy.

Leave a Reply