Revit API Parameters

Imports & Variables

Imports & Variables

Imports & Variables

This is the base imports and variables that you might need for code snippets belowโ€ฆ

This is the base imports and variables that you might need for code snippets belowโ€ฆ

This is the base imports and variables that you might need for code snippets belowโ€ฆ

# -*- coding: utf-8 -*-

#โฌ‡๏ธ IMPORTS
#โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import ISelectionFilter, Selection, ObjectType

#๐Ÿ“ฆ VARIABLES
#==================================================
doc       = __revit__.ActiveUIDocument.Document #type:Document
uidoc     = __revit__.ActiveUIDocument          

# Class for selection methods...
selection = uidoc.Selection                     #type: Selection
# -*- coding: utf-8 -*-

#โฌ‡๏ธ IMPORTS
#โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import ISelectionFilter, Selection, ObjectType

#๐Ÿ“ฆ VARIABLES
#==================================================
doc       = __revit__.ActiveUIDocument.Document #type:Document
uidoc     = __revit__.ActiveUIDocument          

# Class for selection methods...
selection = uidoc.Selection                     #type: Selection
# -*- coding: utf-8 -*-

#โฌ‡๏ธ IMPORTS
#โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import ISelectionFilter, Selection, ObjectType

#๐Ÿ“ฆ VARIABLES
#==================================================
doc       = __revit__.ActiveUIDocument.Document #type:Document
uidoc     = __revit__.ActiveUIDocument          

# Class for selection methods...
selection = uidoc.Selection                     #type: Selection

Get Parameter

Get Parameter

Get Parameter

โ€ฆ

โ€ฆ

โ€ฆ

# Get Built-In Parameters
comments = picked_object.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
mark     = picked_object.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)
el_type  = picked_object.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM)
#๐Ÿ’ก You can check BuilltInParameter wit RevitLookup under Parameters -> Definition -> BuiltInParameter (p.Definition.BuiltInParameter)

# Get Shared/Project Parameters (by name)
custom_p1 = picked_object.LookupParameter("P_NAME_1")
custom_p2 = picked_object.LookupParameter("P_NAME_1") 

#Pro Tip: Ensure shared parameter exists...
if custom_p1:
    # Do Something...
    pass
# Get Built-In Parameters
comments = picked_object.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
mark     = picked_object.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)
el_type  = picked_object.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM)
#๐Ÿ’ก You can check BuilltInParameter wit RevitLookup under Parameters -> Definition -> BuiltInParameter (p.Definition.BuiltInParameter)

# Get Shared/Project Parameters (by name)
custom_p1 = picked_object.LookupParameter("P_NAME_1")
custom_p2 = picked_object.LookupParameter("P_NAME_1") 

#Pro Tip: Ensure shared parameter exists...
if custom_p1:
    # Do Something...
    pass
# Get Built-In Parameters
comments = picked_object.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
mark     = picked_object.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)
el_type  = picked_object.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM)
#๐Ÿ’ก You can check BuilltInParameter wit RevitLookup under Parameters -> Definition -> BuiltInParameter (p.Definition.BuiltInParameter)

# Get Shared/Project Parameters (by name)
custom_p1 = picked_object.LookupParameter("P_NAME_1")
custom_p2 = picked_object.LookupParameter("P_NAME_1") 

#Pro Tip: Ensure shared parameter exists...
if custom_p1:
    # Do Something...
    pass

Read Parameter

Read Parameter

Read Parameter

โ€ฆ

โ€ฆ

โ€ฆ

# Read Parameter Value
param = ... #Get parameter
    
# Choose One depending on StorageType!
value = param.AsString()        # for StorageType.String
value = param.AsInteger()       # for StorageType.Integer
value = param.AsDouble()        # for StorageType.Double
value = param.AsElementId()     # for StorageType.ElementId
value = param.AsValueString()   # Useful for StorageType.ElementId as it will give you its name instead of id

# ๐Ÿง  In general it's very logical. 
# If you work with text paramtert -> AsString
# if it's Whole number or Yes/No -> AsInteger
# ...

# Read Parameter Value
param = ... #Get parameter
    
# Choose One depending on StorageType!
value = param.AsString()        # for StorageType.String
value = param.AsInteger()       # for StorageType.Integer
value = param.AsDouble()        # for StorageType.Double
value = param.AsElementId()     # for StorageType.ElementId
value = param.AsValueString()   # Useful for StorageType.ElementId as it will give you its name instead of id

# ๐Ÿง  In general it's very logical. 
# If you work with text paramtert -> AsString
# if it's Whole number or Yes/No -> AsInteger
# ...

# Read Parameter Value
param = ... #Get parameter
    
# Choose One depending on StorageType!
value = param.AsString()        # for StorageType.String
value = param.AsInteger()       # for StorageType.Integer
value = param.AsDouble()        # for StorageType.Double
value = param.AsElementId()     # for StorageType.ElementId
value = param.AsValueString()   # Useful for StorageType.ElementId as it will give you its name instead of id

# ๐Ÿง  In general it's very logical. 
# If you work with text paramtert -> AsString
# if it's Whole number or Yes/No -> AsInteger
# ...

Set Parameter

Set Parameter

Set Parameter

โ€ฆ

โ€ฆ

โ€ฆ

#๐ŸŸ  Set Parameter Values
# Parameter should not be IsReadOnly!
# Make sure you use Transaction to allow changes in the project
# Provide values in the correct StorageType. You can check p.StorageType Property. (String/Integer/Double/ElementId)

with Transaction(doc, __title__) as t:
    t.Start()

    comments.Set('EF-Comment')  #StorageType.String
    mark.Set('EF-Mark')         #StorageType.String
    custom_p1.Set(69)           #StorageType.Integer

    t.Commit()
#๐ŸŸ  Set Parameter Values
# Parameter should not be IsReadOnly!
# Make sure you use Transaction to allow changes in the project
# Provide values in the correct StorageType. You can check p.StorageType Property. (String/Integer/Double/ElementId)

with Transaction(doc, __title__) as t:
    t.Start()

    comments.Set('EF-Comment')  #StorageType.String
    mark.Set('EF-Mark')         #StorageType.String
    custom_p1.Set(69)           #StorageType.Integer

    t.Commit()
#๐ŸŸ  Set Parameter Values
# Parameter should not be IsReadOnly!
# Make sure you use Transaction to allow changes in the project
# Provide values in the correct StorageType. You can check p.StorageType Property. (String/Integer/Double/ElementId)

with Transaction(doc, __title__) as t:
    t.Start()

    comments.Set('EF-Comment')  #StorageType.String
    mark.Set('EF-Mark')         #StorageType.String
    custom_p1.Set(69)           #StorageType.Integer

    t.Commit()

Scan All Element Parameters

Scan All Element Parameters

Scan All Element Parameters

โ€ฆ

โ€ฆ

โ€ฆ

#๐ŸŸง Pick Object to work with parameters
ref_picked_object = selection.PickObject(ObjectType.Element)
picked_object     = doc.GetElement(ref_picked_object)

#--------------------------------------------------
#๐ŸŸ  Get All Instance/Type Parameters
# Keep in mind that you can't get Type parameters from an Instance.
#     You can get Instance Parameters from an Instance
# And You can get Type     Parameters from a  Type
# You can always get a type with .GetTypeId()

instance_params = picked_object.Parameters

# Get Type Parameters from Type!
picked_object_type = doc.GetElement(picked_object.GetTypeId())
type_params        = picked_object_type.Parameters

#--------------------------------------------------
#๐ŸŸ  Read Parameter Properties
def get_param_value(param):
    """Get a value from a Parameter based on its StorageType."""
    value = None
    if param.StorageType == StorageType.Double:      value = param.AsDouble()
    elif param.StorageType == StorageType.ElementId: value = param.AsElementId()
    elif param.StorageType == StorageType.Integer:   value = param.AsInteger()
    elif param.StorageType == StorageType.String:    value = param.AsString()
    return value

# Read All Instance Parameters of an Element
for p in picked_object.Parameters:
    print("Name: {}".format(p.Definition.Name))
    print("ParameterGroup: {}".format(p.Definition.ParameterGroup))
    print("BuiltInParameter: {}".format(p.Definition.BuiltInParameter))
    print("IsReadOnly: {}".format(p.IsReadOnly))
    print("HasValue: {}".format(p.HasValue))
    print("IsShared: {}".format(p.IsShared))
    print("StorageType: {}".format(p.StorageType))
    print("Value: {}".format(get_param_value(p)))
    print("AsValueString(): {}".format(p.AsValueString()))
    print('-'*100)
#๐ŸŸง Pick Object to work with parameters
ref_picked_object = selection.PickObject(ObjectType.Element)
picked_object     = doc.GetElement(ref_picked_object)

#--------------------------------------------------
#๐ŸŸ  Get All Instance/Type Parameters
# Keep in mind that you can't get Type parameters from an Instance.
#     You can get Instance Parameters from an Instance
# And You can get Type     Parameters from a  Type
# You can always get a type with .GetTypeId()

instance_params = picked_object.Parameters

# Get Type Parameters from Type!
picked_object_type = doc.GetElement(picked_object.GetTypeId())
type_params        = picked_object_type.Parameters

#--------------------------------------------------
#๐ŸŸ  Read Parameter Properties
def get_param_value(param):
    """Get a value from a Parameter based on its StorageType."""
    value = None
    if param.StorageType == StorageType.Double:      value = param.AsDouble()
    elif param.StorageType == StorageType.ElementId: value = param.AsElementId()
    elif param.StorageType == StorageType.Integer:   value = param.AsInteger()
    elif param.StorageType == StorageType.String:    value = param.AsString()
    return value

# Read All Instance Parameters of an Element
for p in picked_object.Parameters:
    print("Name: {}".format(p.Definition.Name))
    print("ParameterGroup: {}".format(p.Definition.ParameterGroup))
    print("BuiltInParameter: {}".format(p.Definition.BuiltInParameter))
    print("IsReadOnly: {}".format(p.IsReadOnly))
    print("HasValue: {}".format(p.HasValue))
    print("IsShared: {}".format(p.IsShared))
    print("StorageType: {}".format(p.StorageType))
    print("Value: {}".format(get_param_value(p)))
    print("AsValueString(): {}".format(p.AsValueString()))
    print('-'*100)
#๐ŸŸง Pick Object to work with parameters
ref_picked_object = selection.PickObject(ObjectType.Element)
picked_object     = doc.GetElement(ref_picked_object)

#--------------------------------------------------
#๐ŸŸ  Get All Instance/Type Parameters
# Keep in mind that you can't get Type parameters from an Instance.
#     You can get Instance Parameters from an Instance
# And You can get Type     Parameters from a  Type
# You can always get a type with .GetTypeId()

instance_params = picked_object.Parameters

# Get Type Parameters from Type!
picked_object_type = doc.GetElement(picked_object.GetTypeId())
type_params        = picked_object_type.Parameters

#--------------------------------------------------
#๐ŸŸ  Read Parameter Properties
def get_param_value(param):
    """Get a value from a Parameter based on its StorageType."""
    value = None
    if param.StorageType == StorageType.Double:      value = param.AsDouble()
    elif param.StorageType == StorageType.ElementId: value = param.AsElementId()
    elif param.StorageType == StorageType.Integer:   value = param.AsInteger()
    elif param.StorageType == StorageType.String:    value = param.AsString()
    return value

# Read All Instance Parameters of an Element
for p in picked_object.Parameters:
    print("Name: {}".format(p.Definition.Name))
    print("ParameterGroup: {}".format(p.Definition.ParameterGroup))
    print("BuiltInParameter: {}".format(p.Definition.BuiltInParameter))
    print("IsReadOnly: {}".format(p.IsReadOnly))
    print("HasValue: {}".format(p.HasValue))
    print("IsShared: {}".format(p.IsShared))
    print("StorageType: {}".format(p.StorageType))
    print("Value: {}".format(get_param_value(p)))
    print("AsValueString(): {}".format(p.AsValueString()))
    print('-'*100)

Check Loaded Parameters

Check Loaded Parameters

Check Loaded Parameters

Often time you need to ensure that project has certain parameter loaded to run automation.
You can use this function to provide a list of required parameter names and It will scan and find if any of them are missing in the project. You can add an extra step to load them up using your SharedParameterFile.

#๐ŸŸ  Check Loaded Parameters / Ensure SharedParameter Loaded

def check_loaded_params(list_p_names):
    """Check if any parameters from provided list are missing in the project
    :param list_p_names: List of Parameter Names
    :return:             List of Missing Parameter Names"""
    # ๐Ÿ“ƒ Get Parameter Bindings Map.
    bm = doc.ParameterBindings

    # ๐Ÿ’ก Create a forward iterator
    itor = bm.ForwardIterator()
    itor.Reset()

    #ITerate over the map
    loaded_parameters = []
    while itor.MoveNext():
        try:
            d = itor.Key
            loaded_parameters.append(d.Name)
        except:
            pass

    # โœ… Check if Parameters are loaded:
    missing_params = [p_name for p_name in list_p_names if p_name not in loaded_parameters]

    # ๐Ÿ‘† This is same as this ๐Ÿ‘‡ just one-liner vs multi-line.

    # missing_params = []
    # for p_name in req_params:
    #     if p_name not in loaded_parameters:
    #         missing_params.append(p_name)

    return missing_params
#๐ŸŸ  Check Loaded Parameters / Ensure SharedParameter Loaded

def check_loaded_params(list_p_names):
    """Check if any parameters from provided list are missing in the project
    :param list_p_names: List of Parameter Names
    :return:             List of Missing Parameter Names"""
    # ๐Ÿ“ƒ Get Parameter Bindings Map.
    bm = doc.ParameterBindings

    # ๐Ÿ’ก Create a forward iterator
    itor = bm.ForwardIterator()
    itor.Reset()

    #ITerate over the map
    loaded_parameters = []
    while itor.MoveNext():
        try:
            d = itor.Key
            loaded_parameters.append(d.Name)
        except:
            pass

    # โœ… Check if Parameters are loaded:
    missing_params = [p_name for p_name in list_p_names if p_name not in loaded_parameters]

    # ๐Ÿ‘† This is same as this ๐Ÿ‘‡ just one-liner vs multi-line.

    # missing_params = []
    # for p_name in req_params:
    #     if p_name not in loaded_parameters:
    #         missing_params.append(p_name)

    return missing_params
#๐ŸŸ  Check Loaded Parameters / Ensure SharedParameter Loaded

def check_loaded_params(list_p_names):
    """Check if any parameters from provided list are missing in the project
    :param list_p_names: List of Parameter Names
    :return:             List of Missing Parameter Names"""
    # ๐Ÿ“ƒ Get Parameter Bindings Map.
    bm = doc.ParameterBindings

    # ๐Ÿ’ก Create a forward iterator
    itor = bm.ForwardIterator()
    itor.Reset()

    #ITerate over the map
    loaded_parameters = []
    while itor.MoveNext():
        try:
            d = itor.Key
            loaded_parameters.append(d.Name)
        except:
            pass

    # โœ… Check if Parameters are loaded:
    missing_params = [p_name for p_name in list_p_names if p_name not in loaded_parameters]

    # ๐Ÿ‘† This is same as this ๐Ÿ‘‡ just one-liner vs multi-line.

    # missing_params = []
    # for p_name in req_params:
    #     if p_name not in loaded_parameters:
    #         missing_params.append(p_name)

    return missing_params

ยฉ 2023-2026 EF Learn Revit API

ยฉ 2023-2026 EF Learn Revit API

ยฉ 2023-2026 EF Learn Revit API