What is the error in this code please ?
import System
from System import Enum
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
# Define inputs
param_names = IN[0] # List of parameter names
param_types = IN[1] # List of parameter types
param_groups = IN[2] # List of parameter groups
category_name = IN[3] # Name of the category to which the parameters will be assigned
is_instance = IN[4] # Whether the parameters should be instance or type parameters
# Find the category to which the parameters will be assigned
category = None
for c in doc.Settings.Categories:
if c.Name == category_name:
category = c
break
if category is None:
raise Exception("Invalid category name: " + category_name)
# Start a transaction
t = Transaction(doc, 'Add Project Parameters')
t.Start()
# Loop through the input lists and create a new parameter for each one
for name, type_name, group_name in zip(param_names, param_types, param_groups):
# Get the parameter group enum value
group = BuiltInParameterGroup.INVALID
for item in Enum.GetValues(BuiltInParameterGroup):
if item.ToString() == group_name:
group = item
break
if group == BuiltInParameterGroup.INVALID:
raise Exception("Invalid parameter group name: " + group_name)
# Get the parameter type enum value
type = ParameterType.INVALID
for item in Enum.GetValues(ParameterType):
if item.ToString() == type_name:
type = item
break
if type == ParameterType.INVALID:
raise Exception("Invalid parameter type name: " + type_name)
# Create the new parameter
if is_instance:
new_param = InstanceBinding(BuiltInParameterGroup(group))
new_param = doc.FamilyManager.AddParameter(name, type, new_param, BuiltInParameterGroup(group))
else:
new_param = doc.ProjectInformation.AddParameter(name, type, BuiltInParameterGroup(group))
# Associate the parameter with the category
BindingMap = doc.ParameterBindings
cat_set = BindingMap.get_Item(category)
cat_set.Insert(new_param)
BindingMap.ReInsert(category, cat_set)
# Commit the transaction
t.Commit()
# Output a message to confirm completion
OUT = 'Project parameters added successfully!'