Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VisibleInViewFilter doesn't work unless view is opened

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
michael-coffey
702 Views, 8 Replies

VisibleInViewFilter doesn't work unless view is opened

It seems that this new filter added in 2021 only works if the view was already opened/regenerated.  Was that the intended behavior?  I see no mention of this in the help file.  Below is a macro to test.  Set the name in viewToTest and first run on a view that has not been opened yet.  Then open the view and run again.

		public void TestVisibleInViewFilter()
		{
			Document doc = this.ActiveUIDocument.Document;
			
			string viewToTest = "1ST FLOOR";
			ElementId viewToTestId = new FilteredElementCollector(doc).OfClass(typeof(View)).WhereElementIsNotElementType().Cast<View>().
				Where(q => !q.IsTemplate && q.Name == viewToTest).First().Id;
			
			var vivFilter = new VisibleInViewFilter(doc, viewToTestId);
            var elementsInView = new FilteredElementCollector(doc).WherePasses(vivFilter).ToElementIds();
            
            TaskDialog.Show("Info", elementsInView.Count + " ids found");
		}

It seems that this would hardly be useful then.  Thanks.

Labels (2)
8 REPLIES 8
Message 2 of 9

Have you read the docs?

 

This filter is a quick filter. Quick filters operate only on the ElementRecord, a low-memory class which has a limited interface to read element properties. Elements which are rejected by a quick filter will not be expanded in memory. In some situations (for example, when the element geometry is not yet calculated for the input view) this filter may return true even though the element may not actually be visible when geometry is calculated.

 

Does that explain the behaviour you observe?

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 9

I suppose it explains that it won't work unless the view is already open.  Which still makes it not worth much.

Message 4 of 9
tamas.deri
in reply to: jeremy_tammik

Thanks @jeremy_tammik but I think the quoted paragraph has nothing to do at all with the behaviour of the above mentioned filter. We've also faced the issue what @michael-coffey pointed, and I consider it a bug. The exact behaviour is the following:

- if the view used for filtering has never been opened in the current session since the doc is open: no elements will pass the filter

- if the view is open: elements from the view are passing the filter

- if the view has been open, but closed afterwards, and no changes are made to the document: elements from the view are passing the filter

- if any change is made in the document since the view is closed: no elements will pass the filter

 

For me this behaviour is misleading, confusing, and unacceptable.

If this is the intended behaviour, then fine, but a clear documentation of this behaviour would be expected.

 

 

Message 5 of 9
jeremy_tammik
in reply to: tamas.deri

Thank you for your analysis and explanation. I passed it on to the development team and asked for their opinion on this for you.

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 6 of 9
jeremy_tammik
in reply to: tamas.deri

They answered promptly and say: Looks like it is derived from ElementQuickFilter, so this seems to be intentional behaviour.

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 7 of 9
tamas.deri
in reply to: michael-coffey

ElementOwnerViewFilter is also an ElementQuickFilter, however it doesn't have such limitation.

I've expected this filter to be an alternative of using the FilteredElementCollector(doc, viewid)

but it seems that is not the case. This seems we have to accept the overhead of expanding our input collector with .ToElementIds() and create a new collector with the alternative constructor.

I've noticed that this constructor in fact opens the target view in the background, which takes some time, but would be acceptable in case of the VisibleInView filter, and it would have it's purpose.

Anyways, thanks Jeremy for asking the dev team.

 

PS

I was too optimistic, there is no constructor of FilteredElementCollector that accepts a collection of ElementIds, and a view Id, so it seems that it isn't even an alternative.

 

 

 

 

Message 8 of 9
jeremy_tammik
in reply to: tamas.deri

ElementOwnerViewFilter is also an ElementQuickFilter, however it doesn't have such limitation.

  

Yes. It can work correctly and with the limited set of data available to it. 

  

The view visibility cannot, so, apparently, it only works under the circumstances that you determined and listed. Sorry that is not more clearly documented. It would be very nice to update many details in the Revit API documentation.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 9 of 9
tamas.deri
in reply to: jeremy_tammik

I was able to achieve what I wanted using the following method:

 

 

 

var inputIds = inputCollector.ToElementIds();
var inViewIds = new FilteredElementCollector(doc, viewId).WhereElementIsNotElementType().ToElementIds();
var inputIdsInView = inputIds.Intersect(inViewIds);

 

 

 

 First I've tried the collector's IntersectWith() method but that didn't work. Neither did the LINQ Intersect extension on raw eollections, or Element List, only on ElementId List.

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report