# Collect Elements in View using Python

**URL:** <https://forum.dynamobim.com/t/collect-elements-in-view-using-python/2180>\
**Category:** Packages\
**Created:** [September 17, 2015, 12:01am UTC](https://forum.dynamobim.com/t/collect-elements-in-view-using-python/2180 "2015-09-17T00:01:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke\_Johnson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luke_johnson/32/9473_2.png) [@Luke\_Johnson](https://forum.dynamobim.com/u/Luke_Johnson)\
**Post date:** [September 17, 2015, 12:01am UTC](https://forum.dynamobim.com/t/collect-elements-in-view-using-python/2180/1 "2015-09-17T00:01:14Z")

</div>

I want to feed a node a single view element and get a list of elements visible in that view, specifically Revit links. This is easy for the active view, because there is the built in node “All Elements in Active View”. But I can’t set the active view programmatically and would prefer to iterate the views with a collector and return the elements that are visible.

This is the snippet of code I can’t get to work. I nkow that the [viewElem.Id](http://viewElem.Id) is right, but I’m guess something about my category statement is wrong:

listed = list()  
listed.append(FilteredElementCollector(doc,[viewElem.Id](http://viewElem.Id)).WhereElementIsNotElementType().OfCategory(BuiltInCategory(OST\_RvtLinks)).ToElementIds())

&nbsp;

Full code:

import clr  
clr.AddReference(‘ProtoGeometry’)  
from Autodesk.DesignScript.Geometry import \*

# Import DocumentManager

clr.AddReference(“RevitServices”)  
import RevitServices  
from RevitServices.Persistence import DocumentManager

# Import RevitAPI

clr.AddReference(“RevitAPI”)  
import Autodesk

# Import ToDSType(bool) extension method

clr.AddReference(“RevitNodes”)  
import Revit  
from Autodesk.Revit.DB import \*  
clr.ImportExtensions(Revit.Elements)

import System

viewElem = IN[0]

doc = DocumentManager.Instance.CurrentDBDocument  
uiapp = DocumentManager.Instance.CurrentUIApplication  
app = uiapp.Application

listed = list()  
listed.append(FilteredElementCollector(doc,[viewElem.Id](http://viewElem.Id)).WhereElementIsNotElementType().OfCategory(BuiltInCategory(OST\_RvtLinks)).ToElementIds())

OUT = listed

&nbsp;

&nbsp;

\<span style=“color: #f92672; font-weight: bold;”\> \</span\>

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [September 17, 2015, 12:31am UTC](https://forum.dynamobim.com/t/collect-elements-in-view-using-python/2180/2 "2015-09-17T00:31:49Z")

</div>

Hi Luke. I’m not sure that this will work with the built in category filter. You could try using an “.OfClass(Autodesk.Revit.DB.RevitLinkInstance)” filter instead.

---

<div class="post-metadata">

**Author:** ![Luke\_Johnson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/luke_johnson/32/9473_2.png) [@Luke\_Johnson](https://forum.dynamobim.com/u/Luke_Johnson)\
**Post date:** [September 17, 2015, 6:46pm UTC](https://forum.dynamobim.com/t/collect-elements-in-view-using-python/2180/3 "2015-09-17T18:46:44Z")

</div>

Thanks Dimitar. I actually found what I was looking for in the “Elements in View(s)” package. \<span style=“color: #75715e;”\>Marc Tavenier\</span\> method was:

for view in views:  
collector = FilteredElementCollector(doc, [view.Id](http://view.Id))  
elementlist.append(collector.ToElements())

In this case, I think the define collector, then ToElements steps were necessary? I couldn’t seem to get the same to work in one expression.

---

<div class="post-metadata">

**Author:** ![Viraj\_Voditel1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/viraj_voditel1/32/17254_2.png) [@Viraj\_Voditel1](https://forum.dynamobim.com/u/Viraj_Voditel1)\
**Post date:** [December 23, 2015, 10:49am UTC](https://forum.dynamobim.com/t/collect-elements-in-view-using-python/2180/4 "2015-12-23T10:49:01Z")

</div>

Hello Luke,

I want to do the exact same thing as you, unfortunately I have no background in coding. Can you please write out the final code for me which worked for you? Or maybe you could upload your dynamo file in which this works for you.

Thanks.
