I have tried direct and unwrapping a ViewFamilyType to get the x.Name property but keep getting the error:
Warning: TypeError : property cannot be read [’ File “”, line 112, in \n’, ’ File “”, line 87, in GetDraftingViewTypeByName\n’]
Pulled many references from View Family Types selection
CORE PY CODE for reference below:
# Load the Python Standard and DesignScript Libraries
import sys
import clr
##https://forum.dynamobim.com/t/collecting-all-elements-of-family-types-in-active-view/19838/2
from Autodesk.Revit.DB import FilteredElementCollector
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Drafting Views
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, BuiltInParameter
from Autodesk.Revit.DB import ViewFamilyType, ViewDrafting, Element
from Autodesk.Revit.DB import ViewFamily
from Autodesk.Revit.DB import Transaction
doc = DocumentManager.Instance.CurrentDBDocument
#######################################################
########################################################
def GetNameByID(oID): ##GenericAnnotationFamilyType".Name"
return doc.GetElement(oID).get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()
########################################################
def GetDraftingViewTypeByName(DraftViewTypeName=""): ##Returns Default "Drafting View" ViewType or name as specified or creates ViewType by DraftViewTypeName
##Trans_GDVBTN = Transaction (doc, 'Drafting View Type')
##Trans_GDVBTN.Start()
##Get all View_Family_Types from Drafting Views:
DraftViewTypes = [ x for x in FilteredElementCollector(doc).OfClass(ViewFamilyType) if x.ViewFamily == ViewFamily.Drafting ]
found=False ##Found as false
if not DraftViewTypeName == "": ##If view name is not null
for v in DraftViewTypes: ##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<DEBUG
#return GetNameByID(v.Id) ##<<<<<<<<<<<<<<<<<THIS WORKS TO GET THE NAME
return v.Name ##<<<<<<<<<<<<<<<<<<<<<<<<<<<<THIS BREAKS LINE 87
return type(v),dir(v) ##<<<<<<<<<<<<<<<<<<<<List all methods / Properties
if v.Name == DraftViewTypeName:
found=True
break
##FAILS##viewfamily_types = [v for v in viewfamily_types if v.Name == strName] ##Return Drafting view for each Drafting view eq. Name
if not viewfamily_types: ##If no drafting view found
drafting_type_id = get_drafting_type().Id ##Get TYPE ID
DraftingView = ViewDrafting.Create(doc, drafting_type_id) ##Create View
##After creating view-
if not strName=="" : ##IF string is not null set the name of the new view
DraftingView.Name = strName
##Trans_GDVBTN.Commit() ##Commit transaction - will see if we can do paralell with another transaction per API
return DraftViewTypes ##Return list
##############
t = Transaction (doc, 'Create Drafting View Type')
t.Start()
DVT=GetDraftingViewTypeByName("Test2") ## GetDraftingView_AllTypes()
#DVT=GetDraftingView_AllTypes()
#DVT[1].Name="Test2" ##Works... but cannot read DVT[1].Name???
#DVT = [I.Name for I in DVT]
##OUT =DVT[0].Name ##[v.Name for v in DVT] ##Cannot Read?
#OUT=GetDraftingViewTypeByName ("NewType")
##GetDraftingView ()
OUT=DVT
t.Commit()