Determine if an element is visible in a view

Determine if an element is visible in a view

Anonymous
Not applicable
6,128 Views
7 Replies
Message 1 of 8

Determine if an element is visible in a view

Anonymous
Not applicable

I am trying to find out if there is a way to see if a specific element is in a view. Not if it is hidden or visible, but actually in the view range/crop region/etc.

 

I tried using CanBeHidden, wondering if that would return false if it wasn't in the view, but even if I can't see it, it still returns true if it CAN be hidden, which makes sense.

 

Any way to do this? Working in 2014.

0 Likes
6,129 Views
7 Replies
Replies (7)
Message 2 of 8

ollikat
Collaborator
Collaborator
Hi

I'm not sure whether there is an easy and short solution for this. But at least you could...

- Fetch and store all elements/element ids of certain view to some list/dictionary. You can use FilteredElementCollector.OwnedByView to achieve this.
- Then you can check whether certain element can be found from the list/dictionary. This tells you whether the element belongs to view.
Message 3 of 8

Anonymous
Not applicable

Thanks. This definitely got me on the right path. Using FilteredElementCollector.OwnedByView was a little too granular. The OwnedByView gave me elements that were exclusive for that view (Sun Path and things like that) but I was able to dial back to just the FiltereElementCollector and give it the arguments of view and that gave me the collection of all the elements in that view. Thanks!

0 Likes
Message 4 of 8

arnostlobel
Alumni
Alumni

Unfortunately, it is not as simple. I have just talked to the developer who is in charge of this, and I was told that it I actually not always possible to simply inquire whether an element is actually visible in a view or not. He recommends the programmer asks for the element’s Geometry with the view given in the method’s options. That may work for most of cases.

Another option, from my experience, would be to utilize a very simple export context for a CustomExporter. The context would not do anything except it would monitor which elements are coming into the context. Only elements currently and actually visible in the exported view will be sent there. In a sense, such a context would act like an element iterator.

 

Arnošt Löbel

Sr. Principal Engineer

Autodesk, Revit R&D

Arnošt Löbel
Message 5 of 8

boostyourbim
Advocate
Advocate

Hi Arnost,

 

CustomExporters can only be used with 3D views, right? So how would you recommend determining if an element is visible in a 2D view if get_Geometry does not provide the desired results?

 

Thanks

Harry

0 Likes
Message 6 of 8

Anonymous
Not applicable

How many has used the overload of FilteredElementCollector where you specify the viewid?

I've tested it now and I must say it looks like it work. I allways thought that it was only for elements owned by the view.

Any known drawbacks with using this method?

Message 7 of 8

dnenov
Contributor
Contributor

Hi erikeriksson5686,

 

Have you tested it with linked document and active view? I'm getting an error:

 

image.png

 

It works with the document object, same code, same view id. So the error is misleading in that sense. 

 

Any feedback will be appreciated.

0 Likes
Message 8 of 8

matthew_taylor
Advisor
Advisor

I can confirm this appears to work also.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes