Finding the family and family type name of an element

Hello,

I know this is a very basic question, but I cant find an appropriate answer anywhere (this maybe a result of my non understanding of the theory behind it).

I have filtered out all of the instances of walls in a given project.

I then want to loop over those walls and find both the type name and the family name.

I have tried to use .WallTypes and .GetType, but they return Autodesk.Revit.DB.Wal, but i would like the literal name.-

Thankyou

Hi @ssw9UZNL,

You can find the type name and family name of system families like this :

Sorry I mean through python and the API. thanks

Here is a start for Python:
This gets all wall types, and then the name of those types, and the family name of the walls.

Since these are system families, what are you needing the Family for?

2 Likes

@SeanP

Thankyou, but the scipt tells me that Element and Element Type are not defined.

And regarding the system families, I would just like to know how to get them as I can then apply it to items that are not walls.

Thankyou

Do you have all the correct Imports as shown below?

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])
WallTypes = []
names = []
FamilyNames = []
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

wallTypes = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType()

for wallType in wallTypes.ToElements():
	WallTypes.append(wallType)

	names.append(Element.Name.__get__(wallType))
	FamilyNames.append(ElementType.FamilyName.__get__(wallType))

TransactionManager.Instance.TransactionTaskDone()

OUT = WallTypes,names,FamilyNames
1 Like

I am not passing anything into the node, as I thought the FilteredElementCollector would collect all of the walls anyway.

Can you explain where Element and ElementType comes from within the for loop, are they part of the API?

In this example, I am just collecting all the wall types in the project. If you are wanting to collect all walls (instances) then yes that is a little different for the Collector. Is that what you are wanting?

yes, sorry,

I am collecting all of the wall instances in the project, then when I have them (which I do) I then want to just find out what the name of the type is and what the name of the family is (eg. basic wall or curtain wall etc).

Thanks

Try this.

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB 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

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

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

walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType()

for wall in walls.ToElements():
	wType = doc.GetElement(wall.GetTypeId())
	WallTypes.append(wType)
	TypeNames.append(Element.Name.__get__(wType))
	FamilyNames.append(ElementType.FamilyName.__get__(wType))

OUT = WallTypes,TypeNames,FamilyNames
3 Likes

Thanks,

I am still having issues with Element within this line:

(TypeNames.append(Element.Name.get(wType))

it throws an error saying element is not defined, can you explain where this is coming from?

Thanks

Make sure the formatting is correct:

Element.Name.get(wType)

there are 2 underscores before and after the get

Can you show an image of the graph with the error and the preceding node with preview?

I believe you did not add the imports as @SeanP mentioned.

I’d have a look into the Revit Lookup tool to search your specific parameters within Revit. Play around with it to get a better understanding of the API.


image

I changed SeanPs code a bit to show how to find the information based on Revit Lookup. SeanPs code works and should be considered as solution.

import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument

WallTypes = []
TypeNames = []
FamilyNames = []
WallKind = []

walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType()

for wall in walls.ToElements():
	wType = wall.WallType
	WallTypes.append(wType)
	TypeNames.append(wType.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString())
	FamilyNames.append(wType.FamilyName)
	WallKind.append(wType.Kind)

OUT = WallTypes,TypeNames,FamilyNames, WallKind
3 Likes

it does not work for me

AttributeError: 'List[Element]' object has no attribute 'get_Parameter'

Sounds like you’re trying to get the parameter of a list, not an element. Try using a for loop on the list and get_Parameter on each element.

1 Like

I did this, I just want to get the name of the family types list, simple as that

doc = DocumentManager.Instance.CurrentDBDocument
fam_symb_lst=FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements()
fam_symb_lst_name=fam_symb_lst.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()

SOMETHING LIKE THAT? DO YOU KNOW HOW TO GET A FAMILY TYPE NAME WITHOUT CRSH THE MEMORY ram?

Looks OK at face value, if you’re hitting RAM issues it’s probably too many elements for Dynamo to deal with. Test it on a small model to see if it works in principle, then if it does then it’s the element count which is the limitation. Aside from breaking up the workflow into stages it will probably be difficult to process a large outcome without addins/C#.

This is the leanest it can be written short of oneliners and importing specific objects:

# Boilerplate text
import clr

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

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

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

# Do some action in a Transaction
famsymbs = FilteredElementCollector(doc).OfClass(FamilySymbol).ToElements()

nameList = []

for i in famsymbs:
	fn = i.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()
	nameList.append(fn)

# Preparing output to Dynamo
OUT = nameList

You can also try passing the element collector to Dynamo and feeding it into the Element.Name node. Not sure how much faster that is though.

name

1 Like