# Get Elements In View(s)

**URL:** <https://forum.dynamobim.com/t/get-elements-in-view-s/98601>\
**Category:** Revit\
**Tags:** revit, python, dynamo\
**Created:** [February 29, 2024, 10:36am UTC](https://forum.dynamobim.com/t/get-elements-in-view-s/98601 "2024-02-29T10:36:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ihouzi](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ihouzi/32/132947_2.png) [@ihouzi](https://forum.dynamobim.com/u/ihouzi)\
**Post date:** [February 29, 2024, 10:36am UTC](https://forum.dynamobim.com/t/get-elements-in-view-s/98601/1 "2024-02-29T10:36:30Z")

</div>

Hello Dynamo Community,

I’m encountering an issue while trying to filter families within a view using Dynamo. Here’s the problem I’m facing:

**Problem Statement:**

I’m working on a project where I need to retrieve families that are visible in a specific view. However, the current script I’m using also retrieves subfamilies that are created within the main/global family. What I actually need is to retrieve only the master family that contains all the subfamilies within it, excluding the subfamilies themselves.

**Current Approach:**

I’ve attempted to filter the families within the view using Dynamo scripting. However, the script I’m using seems to be returning not only the master families but also the subfamilies created within them.

 ![Dynamo elements in View](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/5/85bb9e87be3abc743191d507654d4e6e4f296ba6.jpeg)  
 ![Global Family](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/d/0d18a7babcec3c412cedc3b3dbf452c33975c88e.png)

---

<div class="post-metadata">

**Author:** ![staylor](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/staylor/32/94307_2.png) [@staylor](https://forum.dynamobim.com/u/staylor)\
**Post date:** [February 29, 2024, 1:32pm UTC](https://forum.dynamobim.com/t/get-elements-in-view-s/98601/2 "2024-02-29T13:32:28Z")

</div>

Look at “FamilyInstances.SubComponents” from archilab or “Element.SubComponents” from Clockwork. Use that to get the subcomponents of all the elements and use those results to filter out all matching elements in the main list.

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [February 29, 2024, 4:18pm UTC](https://forum.dynamobim.com/t/get-elements-in-view-s/98601/3 "2024-02-29T16:18:22Z")

</div>

an example with API

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/6/563a3e77d8d3caf761619b0537f7037a9f0769ee.png)

```auto
import clr
import sys
import System

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("System.Core")
clr.ImportExtensions(System.Linq)

toList = lambda x : x if hasattr(x, ' __iter__') else [x]

#Preparing input from dynamo to revit
views = toList(UnwrapElement(IN[0]))

out = []

for v in views:
    elems = FilteredElementCollector(doc, v.Id).OfClass(DB.FamilyInstance).Where(lambda x : x.SuperComponent is None).ToList()
    out.append(elems)
    
OUT = out

```

---

<div class="post-metadata">

**Author:** ![ihouzi](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ihouzi/32/132947_2.png) [@ihouzi](https://forum.dynamobim.com/u/ihouzi)\
**Post date:** [March 1, 2024, 8:43am UTC](https://forum.dynamobim.com/t/get-elements-in-view-s/98601/4 "2024-03-01T08:43:49Z")

</div>

Hi @c.poupin ,

Thanks for your input! I’ve tested the code, and it indeed works well. However, I found that adding some additional filters could enhance the results.
