Get Family Type by Name Instead of Using Family Type Node

HI there, I am making a script that sorts amongst a lot of Family Types and chooses the adequated one based on the case. They annotate families that add details to my view and are placed automatically based on the sizes, etc.
The problem is, every time the project is changed (Someone adds a Family for example) the index order of types change and it brakes the script, as the selected types changes as well.

So I am wondering how to retrieve these types by name since the name will remain the same.

I am sorry if this is basic, but I could not find how to by reading the search results on the Revit API and did not any post here with that subject.

Any help is appreciated, even the Revit API Method, etc.

Thanks!

See this post. Looks like Quasar package has a node that may help.

1 Like

HI, Sean, thanks I will take a look!

I had a partial success with this script:

Figured it out with the help of @SeanP post and reading :slight_smile:
I checkd the Quasar package code, as well it lead me to:
http://www.revitapidocs.com/2018.1/b6d8bc8f-c63b-a3df-db37-cab501e503c1.htm
http://www.revitapidocs.com/2018.1/33042823-a11d-19d4-0d39-f1a4869284a3.htm

from witch I figured what I needed to retrieve the Family Types.

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

 
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)


import System
from System.Collections.Generic import *

# Place your code below this line
doc = doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

 
#Family symbol name to place.
symbName = 'Trail Shiplap Fill'
 
#create a filtered element collector set to Category OST_Mass and Class FamilySymbol 
collector = FilteredElementCollector(doc)
collector.OfCategory(BuiltInCategory.OST_GenericAnnotation)
collector.OfClass(FamilySymbol)
 
famtypeitr = collector.GetElementIterator()
#famtypeitr.Reset()
r=None
re=[]
#Search Family Symbols in document.
for item in famtypeitr:
	famtypeID = item
	
	if symbName in item.FamilyName:
		re.append([item.Family, item.Id, item.FamilyName])
    #If the FamilySymbol is the name we are looking for, create a new instance.
	
	
OUT = re  

I Probably imported more things that I needed but it worked off some sort.
I can’t get the family type though.

If I set to return only the “item” variable it returns an object that contains the family type but I can’t convert it to string or anything.

Any toughts?

Hi,

I may not understand your problem, but why don’t you use the OOTB FamilyType.ByName node ?

Does not work for me.
but with python:

1 Like

I think you can do the same with OOTB Family.ByName and Family.types nodes.

2 Likes

That one worked really good! Sorry for my ignorance. Had no idea!

1 Like

How about?

1 Like

Hi, thanks for your input in this matter. It does look simpler.
I will try it! Have a good weekend!

If using in Player with Inputs…

1 Like

Hello Guys,
Sorry to wake up the topic a year after…
I have a question directly linked to this topic.
What if I want to select all the family loaded in the project as a list ? I know there is a node “Family Types” that gives a scrolling menu with them, but I would want them as a list. I would want to select them all automaticaly whitout creating a list one by one …
Tell me if you have any clue !

Thank you so much

Families or Family Types?

Family Types yes. To get a list of names of all the families that are loaded. (used or unused in the project)

This python will give you families and family Types. You can remove the line for either the fams or famTypes if you don’t want one or the other.

image

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

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

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

fams = FilteredElementCollector(doc).OfClass(Family).ToElements()
famTypes = FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements()

TransactionManager.Instance.TransactionTaskDone()

OUT = fams,famTypes
1 Like

Thank you very much @SeanP

@SeanP Would you also know how to do the same kind of things but with parameters. I am working on a family (.rfa), And to like to have access to its own parameters (names, values, formula). I have achieved to get the names, but I can’t get the value, I got “Null” each times.

import clr

clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference(‘RevitAPIUI’)
from Autodesk.Revit.UI import *

clr.AddReference(‘System’)
from System.Collections.Generic import List

clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

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

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

fams = FilteredElementCollector(doc).OfClass(Family).ToElements()
famTypes = FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements()

param= doc.FamilyManager.GetParameters()

pNames= #list of names of parameters
pS= #similar to param if all parameters are selected, but can be less, depending on the list of names we want

for p in param:
n=p.Definition.Name
pNames.append(n)
pS.append(doc.FamilyManager.get_Parameter(n))

types = doc.FamilyManager.Types #types of the family
famMan = doc.FamilyManager
categ=doc.OwnerFamily.FamilyCategory.Name family category

family TYPES
#add “Default” type in families with no types
familytypecount =
familytypecount.append(types.Size)
if familytypecount < 1:
TransactionManager.Instance.EnsureInTransaction(doc)
new_fam=famMan.NewType(‘Default’)
TransactionManager.Instance.ForceCloseTransaction()

#get assembly code from types

familyTypesItor = famMan.Types.ForwardIterator()
familyTypesItor.Reset()

param_values=

while(familyTypesItor.MoveNext()):
#getcurrentvalue
for n in pNames:
familyParam = famMan.get_Parameter(n)
familyType = familyTypesItor.Current
>param_values.append(familyType.AsString(familyParam))

#TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()
OUT = fams,famTypes,pNames,param_values,familytypecount

Check this revised Python for Family parameters. This is a good start, but isn’t going to cover everything you’ll probably need.

image

import clr

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

run = IN[0]

#Do some action in a Transaction
famTypes = []
pNames = []
pValue = []

types = doc.FamilyManager.Types
params = doc.FamilyManager.Parameters

if run:
	TransactionManager.Instance.EnsureInTransaction(doc)
	for param in params:
		pNames.Add(param.Definition.Name)
	
	for type in types:
		famTypes.Add(type)
		for param in params:
			StoreType = param.StorageType
			if StoreType == StorageType.Double:
				v = type.AsDouble(param)
			elif StoreType == StorageType.Integer:
				v = type.AsInteger(param)
			elif StoreType == StorageType.String:
				v = type.AsString(param)
			elif StoreType == StorageType.ElementId:
				v = type.AsElementId(param)
			
			pValue.Add(v)
	TransactionManager.Instance.TransactionTaskDone()
	OUT = famTypes,pNames,pValue
else:
	OUT = "Set Run to True"
2 Likes