I'm creating a Dynamo script to count blank parameters filled in Door category for all the parameters but receiving the following errors "IronPythonEvaluator.EvaluateIronPythonScript"

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Define a function to count blank values
def count_blank_values(param_values):
    count = 0
    for value in param_values:
        if value == '':
            count += 1
    return count

# Define input parameters
project_path = r"C:\Users\panchals\Documents\Shailesh\01. Docs\07. NMP\project1.rvt"
param_names = ["Mark", "Cost Group", "Functional Zone", "NRC", "Package Code", "STC", "Zone Code", "Fire Rating", "Finish"]

# Initialize Revit document
doc = Document.Load(project_path)

# Get all doors in the project
door_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType()
doors = list(door_collector)

# Initialize dictionaries to store parameter values and blank counts
param_values_dict = {}
blank_counts_dict = {}

# Loop through each parameter
for param_name in param_names:
    param_values_dict[param_name] = []
    blank_counts_dict[param_name] = 0

    # Loop through each door and get parameter value
    for door in doors:
        param_value = door.LookupParameter(param_name).AsString()
        param_values_dict[param_name].append(param_value)

# Count blank values for each parameter
for param_name in param_names:
    blank_counts_dict[param_name] = count_blank_values(param_values_dict[param_name])

# Print blank counts for each parameter
for param_name, blank_count in blank_counts_dict.items():
    print(f"{param_name}: {blank_count} blanks")

# Close the document
doc.Close(False)
import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
#Define a function to count blank values

def count_blank_values(param_values):
count = 0
for value in param_values:
if value == "":
count += 1
return count
#Define input parameters

project_path = r"C:\Users\panchals\Documents\Shailesh\01. Docs\07. NMP\project1.rvt"
param_names = ["Mark","Cost Group", "Functional Zone", "NRC", "Package Code", "STC", "Zone Code", "Fire Rating", "Finish"]
#Initialize Revit document

doc = Document.Load(project_path)
#Get all doors in the project

door_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType()
doors = list(door_collector)
#Initialize dictionaries to store parameter values and blank counts

param_values_dict = {}
blank_counts_dict = {}
Loop through each parameter

for param_name in param_names:
param_values_dict[param_name] =
blank_counts_dict[param_name] = 0

# Loop through each door and get parameter value
for door in doors:
    param_value = door.LookupParameter(param_name).AsString()
    param_values_dict[param_name].append(param_value)

#Count blank values for each parameter

for param_name in param_names:
blank_counts_dict[param_name] = count_blank_values(param_values_dict[param_name])
Print blank counts for each parameter

for param_name, blank_count in blank_counts_dict.items():
print(f"{param_name}: {blank_count} blanks")
#Close the document

doc.Close(False)

use

</> 

As Andreas mentioned, please use preformatted text (</>) when pasting code. Otherwise it does not format properly. Also, make sure you include an image of the inputs you are providing your code and any errors you are getting when running it.

2 Likes

Hi @shaileshpanchal251 welcome,
Here are some tips on your code to keep going (you can also use three backticks ``` at the start and finish to get a code block)

Formatting is important - I use Visual Studio Code to do most of my coding as I can auto format and have better auto completion than Dynamo. PyCharm is also popular. Then cut and paste

Since you are working with a document you will need to load in the Dynamo Revit Services API - documents are always loaded to the application for access

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager

uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application
doc = app.OpenDocumentFile(filepath)

The filtered element collector is an iterable collection so you don’t need to cast to a list. I personally always add .ToElements() to the end (or .FirstElement() when I’m testing code)

The thing with Revit Families is that there are instances and type parameters - you have filtered out the Door Type elements, so access to the Type parameters may not be straightforward.

Rather than printing, send the result to the ‘OUT’ variable OUT = f"{param_name}: {blank_count} blanks" so that the Python node returns the result. Note f-strings are not available in IronPython used in older versions of Dynamo

I highly recommend you read through the Dynamo Python Primer and use the available API documentation here Revit API Docs. Good luck!

1 Like

this very looks a lot like a ChatGPT answer, it would be nice to mention it when such a tool is used

  • the title of the topic must be short and explicit

  • the problem must be described in the body of the post (and not in the Title)

for info Ironpython3 implements f-string too

@shaileshpanchal251
Please read the forum rules (How to get help on the Dynamo forums ) and the community guidelines (https://forum.dynamobim.com/faq )

2 Likes