Family Naming Control with Dynamo and Python

Family Naming Control with Dynamo and Python

Family Naming Control with Dynamo and Python

Updates

Updates

Updates

×

×

×

February 28, 2022

February 28, 2022

February 28, 2022

Introduction

Revit is a software that is frequently used in the BIM (Building Information Modeling) process. In this process, it is important to name the various objects (families) correctly. In this article, we will learn how to use the Revit Dynamo API in Python to check if a family name conforms to a certain rule.

Step 1: Importing the Required Libraries First, we need to import the libraries required to use regular expressions in Revit Dynamo API and Python. You can import the necessary libraries using the code below:

import clr 
clr.AddReference('RevitAPI') 
from Autodesk.Revit.DB import *
import re

Step 2: Define the naming convention The naming convention defines which format the family names should follow. In this example, names should follow the format "C1020.10_Door". According to this format, the name must start with a capital letter, followed by four digits, a period, two digits, an underscore and then any word character (letter, digit or underscore).

pattern = r'^[A-Z]{1}[0-9]{4}\.[0-9]{2}_\w+$'

Step 3: Creating the Naming Check Function In this step, we will create a function that will check if a given family name conforms to the given rule. You can define the function using the following code:

def check_family_name(family_name):
   	if re.match(pattern, family_name):
    	return "İsimlendirme kuralına uygun."
    else:
      	return "İsimlendirme kuralına uymuyor."

Step 4: Family Name Checking and Printing the Result In the last step, we will write a piece of code that will take a given family name and check if it matches the given rule. You can perform this step using the code below:

family_name = "C1020.10_Door" 
result = check_family_name(family_name) 
print(result)

By following the steps above, you can use the Revit Dynamo API to check if the family names conform to a specific rule with Python. If the family name conforms to the specified rule, you will receive the message "Conforms to naming convention", if not, you will receive the message "Does not conform to naming convention".

This blog post provides Revit users and developers with a starting point for automating family naming checks. I hope this information helps you!

About the author

I write about tech and my life updates. Also, you can follow me in social networks.

About the author

I write about tech and my life updates. Also, you can follow me in social networks.

About the author

I write about tech and my life updates. Also, you can follow me in social networks.

About the author

I write about tech and my life updates. Also, you can follow me in social networks.

See Also

See Also

See Also

See Also