Extracting Parameters in Door Family

Hello Everybody!

Thanks for this amazing tool. I just got started with Revit API and pyRevit. I have been in a bit of an issue for the past 4 hours. Any help would be appreciated!

def doors_in_document(): # Definition to Get all the Doors in the Document
    door_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsElementType().ToElements()
    return door_collector


def get_element_shared_parameter(element, parameter):  # Definition to extract a shared parameter value from an element
    param = element.LookupParameter(parameter).AsString()
    return param
#
# some code in between
#

door_collector = doors_in_document()

# Definition to Check the Acquired Door Parameters against the Code Requirements
# Run though the loop and create a list of Doors Unique IDs that do not meet the necessary requirement
failed_doors = []
for door in door_collector:
    # Check if the Door is Single Panel or More
    if get_element_shared_parameter(door, "Leaf_Number") == 1:
        # Check Width and Height Requirements
        door_width = get_element_shared_parameter(door, "Width")
        door_height = get_element_shared_parameter(door, "Height")

Now the issue that I get is that the get_element_shared_parameter function returns a null type. Not sure where I am going wrong.

Is there some other way to access the parameters of the door types in my Revit file?

Once again, any help would be greatly appreciated!
Cheers!:beers:

@prajwalbkumar
Maybe the problem is in the type of parameter value? You are using .ToString().
When I am looking in revitlookup, then for doors width and height probably you should use .AsValueString() or .AsDouble()
image

In addition to the above if any of your doors don’t have these parameters you will get an exception. You can either wrap the whole thing in a try/except statement or better yet add a check to your definition to only run if the parameter exists:

def get_element_shared_parameter(element, parameter):  # Definition to extract a shared parameter value from an element
    param = element.LookupParameter(parameter)
    if param:
        return param.AsValueString()
    else:
        return None

if you’re getting a null type then you catch it first and skip it like this:

  if not get_element_shared_parameter(door, "Leaf_Number"):
      continue
  elif get_element_shared_parameter(door, "Leaf_Number") == 1:
      door_width = get_element_shared_parameter(door, "Width")
      door_height = get_element_shared_parameter(door, "Height")

or

if get_element_shared_parameter(door, "Leaf_Number") is None:
      continue

or just straight up try and except

def get_element_shared_parameter(element, parameter):  
    try:
        param = element.LookupParameter(parameter)
        if param:
            return param.AsString()
        else:
            return param.AsValueString()
    except:
        pass