Revit Dynamo Python Get Family View Types

Revit 2022 - Get Family View Types - This is a great way to organize the project browser without additional parameters. The View types when combined with the two digit NCS discipline designators establishes a way to organize and filter the project browser by family type 
AND 
allows for isolation filtering by NOT=*AE* then hide...

R22 has an issue in the ViewFamilyTypes.Name does NOT work hence the "GLOBAL
def GetNameByID(oID): ##Get Broken Element.Name as work around GLOBAL ByID.Name return doc.GetElement(oID).get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString()




Core code for ViewFamilyTypes 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): ##Get Broken Element.Name as work around GLOBAL ByID.Name return doc.GetElement(oID).get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString() def GetViewTypeByName(clsViewFamilyType, ViewTypeName=""): ##Returns Default "Drafting View" ViewType or name as specified or creates ViewType by DraftViewTypeName ##Trans_GDVBTN = Transaction (doc, 'Drafting View Type') ##MUST Be in traqnsaction to Create/Name! ViewTypes = [ x for x in FilteredElementCollector(doc).OfClass(ViewFamilyType) if x.ViewFamily == clsViewFamilyType ] found=False ##Found as false if not ViewTypeName == "": ##If view name is not null for ViewType in ViewTypes: ##Looking for Viewtype name amongst ViewFamily'ies #return GetNameByID(v.Id) ##<<<<<<<<<<<<<<<<<THIS WORKS TO GET THE NAME #return v.Name ##<<<<<<<<<<<<<<<<<<<<<<<<<<<<THIS BREAKS #return type(v),dir(v) ##<<<<<<<<<<<<<<<<<<<<List all methods / Properties if GetNameByID(ViewType.Id) == ViewTypeName: ##Get name by ID as FamilyViewType.Name BROKEN - 2022-09-15 check furture versions! found=True break if not found: ViewType = None ##Clear remnants from loop if not (found) if ViewType == None: ##If no DraftingViewType found ViewTypes = ViewTypes[0] ##Set to base type ViewType = ViewTypes.Duplicate(ViewTypeName) ##(strName) as ViewFamilyType ##Trans_GDVBTN.Commit() ##Commit transaction - will see if we can do paralell with another transaction per API return ViewType ##Return Viewtype ############## t = Transaction (doc, 'Create Drafting View Type') t.Start() DVT=GetViewTypeByName(ViewFamily.Drafting,"Test6") ## GetDraftingView_AllTypes() OUT=DVT t.Commit()

Comments

Popular posts from this blog

Revit area plans adding new types and references (Gross and rentable)

Powerpoint countdown and current time in slides VBA

Revit Python in Visual Studio Revit Stubs 2022 for Python Revit Intellisense