An error with a python code to create project parameters,

What is the error in this code please ?

import System
from System import Enum
import clr

from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

from Autodesk.Revit.UI import *

from System.Collections.Generic import List

import Revit

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

# 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
if category is None:
    raise Exception("Invalid category name: " + category_name)

# Start a transaction
t = Transaction(doc, 'Add Project Parameters')

# 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
    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
    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))
        new_param = doc.ProjectInformation.AddParameter(name, type, BuiltInParameterGroup(group))

    # Associate the parameter with the category
    BindingMap = doc.ParameterBindings
    cat_set = BindingMap.get_Item(category)
    BindingMap.ReInsert(category, cat_set)

# Commit the transaction

# Output a message to confirm completion
OUT = 'Project parameters added successfully!'

What is the error?

All the parameters exist in your project’s shared parameter file?
Personally, i hate doing it his way. Who knows what the user has set in the project? Or where the SP even is? Or if it is the right one.

What’s your input into this node/

i need to create a non-shared project parameters

it doesn’t do what it is supposed to do

Parameter Group is looking for a string value of “PG_GEOMETRY” for the Dimension group, etc. Giving it that?

What version of Revit? Parameter Type ended in Revit 2022. 2023 used ForgeTypeeId now. That would give you the error, "Invalid parameter type name: "

i am using this script in revit 2019

Show your graph and input data. The code is solid.

There is no way to create a parameter via the API which isn’t a shared parameter.

Well what does it do?

We need to see the full dataset in action to help, reguardless of which verson. Also note that this Revit build will be more than a year out of support in a few weeks, so you will be somewhat limited in what you can do. Updating to a supported version if not a modern one is advisable from both a productivity standpoint and a security standpoint.

1 Like

many thanks to you because you drew my attention to the issue of revit versions, because yes the dynamo script i was designing didn’t work in revit 22 because what you mentioned, and i had to make some modifications to make it work…

Anyway, it seems that there is no really way to create non-shared parameters so, thanks for your time… i don’t know if i have to consider your reply a solution but i think we can close this topic