Filter for elements hidden in a view

Filter for elements hidden in a view

PaulCollins7972
Advocate Advocate
3,194 Views
7 Replies
Message 1 of 8

Filter for elements hidden in a view

PaulCollins7972
Advocate
Advocate

Hi

 

Please can someone advise on how to construct a filter that will find elements that have been "hidden by element" in a view?

 

I have some working code that finds all elements in the current design option and then iterates through each to find which are hidden, but there must be a way to construct an element parameter filter that will be quicker but I can't figure out how to build using the element.ishidden(vw) parameter.

 

Dim doc As Autodesk.Revit.DB.Document = commandData.Application.ActiveUIDocument.Document

Dim vw As Autodesk.Revit.DB.View = doc.ActiveView

 

Dim CollectorView As FilteredElementCollector = New FilteredElementCollector(doc)

Dim activeOptId As ElementId = Autodesk.Revit.DB.DesignOption.GetActiveDesignOptionId(doc)

'create an ElementDesignOption filter

Dim Filter_Option As New ElementDesignOptionFilter(activeOptId)

CollectorView.WherePasses(Filter_Option)

Dim Iter_Elements As IEnumerator = CollectorView.GetElementIterator

'iterate through all the elements to find hidden elements

Do While Iter_Elements.MoveNext()

If (Not (Iter_Elements.Current) Is Nothing) Then

Dim e As Element = Iter_Elements.Current

If e.CanBeHidden(vw) Then

If e.Id <> vw.Id Then 'don't include the view border if hidden

If e.IsHidden(vw) Then

 

Thanks!

0 Likes
Accepted solutions (1)
3,195 Views
7 Replies
Replies (7)
Message 2 of 8

jeremytammik
Autodesk
Autodesk

Does this help?

 

http://thebuildingcoder.typepad.com/blog/2014/10/is-a-given-element-hidden-in-a-view.html

 

I hope so!

 

Please let us know how it goes and how you can make use of ti.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 8

PaulCollins7972
Advocate
Advocate

Jeremy

 

I am writing an add-in that finds all the elements that have been "hidden by element" in the active view.

We have a few user that are prone to hide elements in view and this is a pain to sort out.

 

My code  scans the model and if anything is found presents a dialog which shows what is hidden and lets the user "unhide" selectively.

The code that I have works ok but iterates over everything in the model to build a list of hidden elements.

I was hoping to use something like this to speed things up as your blog encourages us to filter not iterate over everyting!

 

Dim Rule1 As FilterRule = New FilterStringRule(pvp, Eval, RuleString, True)

Filter_Param = New ElementParameterFilter(Rule1)

' Create a logic And filter for category and parameter

Dim Filter_Select As LogicalAndFilter = New LogicalAndFilter(Filter_Cat, Filter_Param)

CollectorDoc.WherePasses(Filter_Select).WhereElementIsNotElementType.ToElements()

Iter_Element = CollectorDoc.GetElementIdIterator()

 

 

I can't figure out how to get the e.ishidden(viewname) into the above. There doesn't seem to be a built in parameter that I can use.

Sorry don't think your example helps, and I have been looking at your blog (which is great) trying to find some help.

 

0 Likes
Message 4 of 8

Anonymous
Not applicable
Accepted solution

Hi Paul.

 

Use linq, something like

 

ICollection<ElementId> collector= new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).WhereElementIsNotElementType()
.Where(x =>x.IsHidden(Vy)).
Select(x => x.Id).Cast<ElementId>().ToList();

 

good Luck!

 

/Martin

Message 5 of 8

PaulCollins7972
Advocate
Advocate

Thanks Martin

 

That's just what I was looking for.

 

Paul

0 Likes
Message 6 of 8

Anonymous
Not applicable

Hello Paul,

 

I am having a look at your code but for some reason I am not being able to run it appropiately. Would it be much to ask if you cold post your solution in this post? 

 

I would really appreciate it as it would be a very useful tool for me.

 

Thank you.

 

Luis

0 Likes
Message 7 of 8

PaulCollins7972
Advocate
Advocate

Hi Luis

 

This is what I ended up with. It finds all elements in the active design option and uses LINQ to see if they are hidden by element in the current view.

My code then loads these into a ListView. When the user chooses an item in the list it is temporarily unhidden as a preview, when the dialog is OK'd then all selected elements are unhidden. I had to check for worksets and phases to see if each element should be visible in the current view, view filters still to do!

 

Dim doc As Autodesk.Revit.DB.Document = commandData.Application.ActiveUIDocument.Document

Dim vw As Autodesk.Revit.DB.View = doc.ActiveView

 

Dim collector As FilteredElementCollector = New FilteredElementCollector(doc)

Dim activeOptId As ElementId = Autodesk.Revit.DB.DesignOption.GetActiveDesignOptionId(doc)

 

'create an ElementDesignOption filter

Dim Filter_Option As New ElementDesignOptionFilter(activeOptId)

 

collector.WherePasses(Filter_Option)

 

'create a LINQ query

Dim query = From item As Element In collector Where item.IsHidden(vw) Select item

For Each e As Element In query

If e.IsHidden(vw) Then

...

 

Works OK in 2013, 2014 and 2015

 

Hope that is useful.

 

Paul

Message 8 of 8

Anonymous
Not applicable

Thank you Paul!

0 Likes