Skip to content

Instantly share code, notes, and snippets.

@alvpickmans
Last active May 25, 2018 13:57
Show Gist options
  • Save alvpickmans/987c86b7a579b338b8f5e5f992005233 to your computer and use it in GitHub Desktop.
Save alvpickmans/987c86b7a579b338b8f5e5f992005233 to your computer and use it in GitHub Desktop.
Retrieve the ViewFamilyType id by its name. Helpful in order to create new views in Revit.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
import System
doc = DocumentManager.Instance.CurrentDBDocument
def ViewFamilyIdByName(document, name):
type = System.Enum.Parse(ViewFamily, name)
viewFamilyTypes = FilteredElementCollector(document).OfClass(ViewFamilyType).ToElements()
id = -1
for viewType in viewFamilyTypes:
if viewType.ViewFamily == type:
id = viewType.Id
break
return id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment