Friday, May 27, 2011

Which of the parameters on the ProjectInfo are built in?

Yesterday I needed to know which of the ProjectInfo parameters are actually built in and can be relied on to be found in any Autodesk Revit Architecture document. Of course I fired up RPS and had a go at finding a solution. Here is what I came up with:

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

doc = __revit__.ActiveUIDocument.Document
pi = doc.ProjectInformation
params = list(pi.Parameters)
builtInParameterIds = set([p.Id.IntegerValue for p in params if p.Id.IntegerValue < 0])
for id in builtInParameterIds:
    parameter = pi.get_Parameter(Enum.ToObject(BuiltInParameter, id))
    name = Enum.GetName(BuiltInParameter, id)
    if parameter:
        print name, ': ', parameter.AsString()
    else:
        print name, ': <NULL>'

There are some aspects of this script I'd like to point out, since they might help you writing your own scripts:

This gives you access to the System.Enum type. The BuiltInParameter enumeration has to be marshalled back and forth to IronPython integers using Enum:

  • Enum.ToObject(BuiltInParameter, id) returns the enum constant that has the integer value id
  • Enum.GetName(BuiltInParameter, id) returns the name of the enum constant (handy for printing to the user)

Also note that all the predefined parameters in Revit have negative ids - that is how we find them:

The output on a test project on my computer is:

PROJECT_ISSUE_DATE :  Projekt Datum
GBXML_EDIT_DATA_PARAM : <NULL>
PROJECT_STATUS :  Projekt  Status
CLIENT_NAME :  Bauherr
PROJECT_ADDRESS :  Projektadresse
PROJECT_NAME :  Projekt Name
PROJECT_NUMBER :  01212

No comments:

Post a Comment