Python - ViewFamilyType Return Names?

Hello
I am trying to get a list of FamilyViewType names using Python.
Revit API suggest Name is a property of FamilyViewType.

https://www.revitapidocs.com/2018/e372092e-ff47-71c2-1272-50ab08e5a41d.htm


dynamo is throwing an attribute error?.
Can anyone help me with how to use python to get a list of ViewFamilyType Names?


import clr

# import RevitNodes


# import Revit Services 
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

doc = DocumentManager.Instance.CurrentDBDocument
viewFamilyTypes=FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()

viewNames = [viewFamily.Name   for viewFamily in viewFamilyTypes]

OUT=viewNames 

@Justin_Wright If you take a closer look at the description of the Name property, it can only be used to SET the name and NOT GET the name. So instead use can use the FamilyName property or try other options suggested below.

Here are your options:

Option-1
import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager

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

doc = DocumentManager.Instance.CurrentDBDocument
viewFamilyTypes = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()
viewNames = [viewFamily.FamilyName for viewFamily in viewFamilyTypes]

OUT = viewNames

Option-2
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

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

doc = DocumentManager.Instance.CurrentDBDocument
viewFamilyTypes=FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()

viewNames = [viewFamily.ViewFamily for viewFamily in viewFamilyTypes]

OUT=viewNames

Option-3
import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager

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

doc = DocumentManager.Instance.CurrentDBDocument
viewFamilyTypes = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()
viewNames = [viewFamily.LookupParameter("Type Name").AsString() for viewFamily in viewFamilyTypes]

OUT = viewNames

4 Likes

Thank you. I did try all of those. However it is the type I’m looking for.

If I connect the list of ViewTypeFamilys in to a Dynamo element.Name node it returns the type name.

@Justin_Wright Not sure what’s going on on your end but Option-3 gives me the exact same result as Element.Name node.

Thank you!.
Option 3 is correct. I was send out the wrong list from my Python Block.

Hello
this is a limitation of Python (IronPython or PythonNet) with inheritance when only the setter of property has been overridden

Among the solutions, converting to a Dynamo object can solve the problem
myRevitElement.ToDSType(False).Name

1 Like