Collection of family instances from familytype using python node

Hello Everyone,

I have been trying to get list of “all elements of family type” using python script. But unfortunately an error keep on occurring (can see in the below image). I tried to find a solution but could’t.

This is my python code: (took the code reference from Source code)

import clr
import sys
sys.path.append(r'C:\Program Files\IronPython 2.7\Lib')
import System
from System import Array

clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, BuiltInParameter, ParameterValueProvider, ElementId, ElementParameterFilter, FilterNumericEquals, FilterElementIdRule


doc = DocumentManager.Instance.CurrentDBDocument


family = UnwrapElement(IN[0])
family_type_ids = family.GetFamilySymbolIds()

family_instances = []

for family_type_id in family_type_ids:
	family_instance_filter = FamilyInstanceFilter(doc, family_type_id)
	elements = FilteredElementCollector(doc).WherePasses(family_instance_filter).ToElements()
	family_instances.append(elements)

OUT = family_instances

My project Aim:

I want to go through all the elements of the selected family type and update their instance parameter (based on user input) values with the new value from an Excel sheet.

As a first step, I have been trying to get all the elementes of the family type. Then I will loop through its parameters.

Thanks in advance for any help and comments!!

You are feeding it a FamilySymbol, not a Family.

family_type = UnwrapElement(IN[0])
family = family_type.Family
family_type_ids = family.GetFamilySymbolIds()

Thanks @SeanP for a very quick respose. And it resolved my error also.

However, I have another issue.
If you see the below image the python node retrieving all the associated elements with the family type (in layman terms, I don’t know actual revet terms), but the dynamo node getting only particular family instances.

How to further filter through the list?

family_type = UnwrapElement(IN[0])
family = family_type.Family
family_type_ids = family.GetFamilySymbolIds()

family_instances = []

for family_type_id in family_type_ids:
	family_instance_filter = FamilyInstanceFilter(doc, family_type_id)
	elements = FilteredElementCollector(doc).WherePasses(family_instance_filter).ToElements()
	family_instances.append(elements)

OUT = family_instances

noob here, but my gut instinct says list lacing ?

Because the OOTB node is only selecting instances of that one type, but your getting instances of all types of that family.

Why can’t you just use the OOTB node if your getting what you want from it?

1 Like

I don’t think, so I can use OOTB node. Because what I wanted to is:
I will explain my idea of doing the project

I want to create a very dynamic script. That might have few user inputs such as
IN1: Family Type
IN2: Parameter Name (a dropdown using dataShapes package)
IN3: Excel sheet having new parametric values

In the python node, I want to select the instance of elements for the familyType and go through the parametric values, then match them with excel sheet values and assign the new value from the excel.

Here the challenging part (for me) is reading Excel and comparing the parametric value from an instance and value from excel. I am thinking to use Pandas for Excel as I am familiar them. So I want to do looping, if conditions everything in python instead of using multiple nodes.

Example:
Excel sheet

Revit Instance prop:

No need for a loop; Dynamo will manage that for you just fine with the Element.SetParameterValue node due to it’s lacing capabilities. You can also quickly build a dictionary of the excel data to associate parameter values and types in a readily identifiable way.

1 Like

I got one more idea of doing. I can use python node after OOTB, so I don’t have to go through filtering.
Simply I can compare and change parameter values.

Thanks, @jacob.small, for your response

I will give it a try with my idea for now. If not working, I would go with yours.
Actually, I am much more familiar with python than Dynamo nodes. More number of nodes scares me more :smile: