# An error with a python code to create project parameters,

**URL:** <https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453>\
**Category:** Revit\
**Tags:** python\
**Created:** [March 16, 2023, 9:41pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453 "2023-03-16T21:41:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![faramawy](https://avatars.discourse-cdn.com/v4/letter/f/c57346/32.png) [@faramawy](https://forum.dynamobim.com/u/faramawy)\
**Post date:** [March 16, 2023, 9:41pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453/1 "2023-03-16T21:41:19Z")

</div>

What is the error in this code please ?

```auto
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!'

```

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [March 16, 2023, 10:37pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453/2 "2023-03-16T22:37:15Z")

</div>

What is the error?

---

<div class="post-metadata">

**Author:** ![aaronrumple](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/aaronrumple/32/195292_2.png) [@aaronrumple](https://forum.dynamobim.com/u/aaronrumple)\
**Post date:** [March 17, 2023, 8:37pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453/3 "2023-03-17T20:37:03Z")

</div>

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/

---

<div class="post-metadata">

**Author:** ![faramawy](https://avatars.discourse-cdn.com/v4/letter/f/c57346/32.png) [@faramawy](https://forum.dynamobim.com/u/faramawy)\
**Post date:** [March 17, 2023, 8:38pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453/4 "2023-03-17T20:38:45Z")

</div>

> [@faramawy](#):
>
> ```auto
> # 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
> 
> ```

i need to create a non-shared project parameters

---

<div class="post-metadata">

**Author:** ![faramawy](https://avatars.discourse-cdn.com/v4/letter/f/c57346/32.png) [@faramawy](https://forum.dynamobim.com/u/faramawy)\
**Post date:** [March 17, 2023, 8:39pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453/5 "2023-03-17T20:39:19Z")

</div>

it doesn’t do what it is supposed to do

---

<div class="post-metadata">

**Author:** ![aaronrumple](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/aaronrumple/32/195292_2.png) [@aaronrumple](https://forum.dynamobim.com/u/aaronrumple)\
**Post date:** [March 17, 2023, 8:53pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453/6 "2023-03-17T20:53:46Z")

</div>

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: "

---

<div class="post-metadata">

**Author:** ![faramawy](https://avatars.discourse-cdn.com/v4/letter/f/c57346/32.png) [@faramawy](https://forum.dynamobim.com/u/faramawy)\
**Post date:** [March 17, 2023, 8:55pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453/7 "2023-03-17T20:55:07Z")

</div>

i am using this script in revit 2019

---

<div class="post-metadata">

**Author:** ![aaronrumple](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/aaronrumple/32/195292_2.png) [@aaronrumple](https://forum.dynamobim.com/u/aaronrumple)\
**Post date:** [March 17, 2023, 8:58pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453/8 "2023-03-17T20:58:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [March 17, 2023, 9:01pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453/9 "2023-03-17T21:01:10Z")

</div>

> [@faramawy](#):
>
> i need to create a non-shared project parameters

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

> [@faramawy](#):
>
> it doesn’t do what it is supposed to do

Well what does it do?

> [@faramawy](#):
>
> i am using this script in revit 2019

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.

---

<div class="post-metadata">

**Author:** ![faramawy](https://avatars.discourse-cdn.com/v4/letter/f/c57346/32.png) [@faramawy](https://forum.dynamobim.com/u/faramawy)\
**Post date:** [March 17, 2023, 9:45pm UTC](https://forum.dynamobim.com/t/an-error-with-a-python-code-to-create-project-parameters/87453/10 "2023-03-17T21:45:01Z")

</div>

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
