Assistance Request: Issue Creating Shared Parameter via Dynamo – Returning Null Value (Dynamo 2025)

Easier than expected… enjoy. Coming to Crumple in future. Note that you can specify more about the parameter such as Guid, Tooltip etc. in the ExternalDefinitionCreationOptions class:

CreateParametersFromExcel_R23.dyn (21.4 KB)
Parameter data.xlsx (8.9 KB)
TestFile.txt (2.2 KB)

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr

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

clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import ExternalDefinitionCreationOptions

# Current doc/app/ui
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 

# Collect inputs from Dynamo
param_names = IN[0]
group_names = IN[1]
specTypeIds = IN[2]

# Results to append to
results = []

# Get the shared parameters file
definitions_file = app.OpenSharedParameterFile()

# Get existing group names
definitions_groups = definitions_file.Groups
groupNames_ex = [g.Name for g in definitions_groups]

# Add any missing groups
for n in group_names:
    if n not in groupNames_ex:
        definitions_groups.Create(n)

# Recollect groups and group names
definitions_groups = [g for g in definitions_file.Groups]
groupNames_ex = [g.Name for g in definitions_groups]

# For each parameter name, group name and spec type Id...
for p,g,s in zip(param_names, group_names, specTypeIds):
    
    # Get the group by name
    group = definitions_groups[groupNames_ex.index(g)]
    
    # Get the definitions in that group
    groupdefs = group.Definitions
    
    # Construct the options
    options = ExternalDefinitionCreationOptions(p,s)
    
    # Try to add the parameter to the file
    # NOTE: This can be made better by checking all SP names instead
    # as this is typically the only reason this should fail
    try:
        groupdefs.Create(options)
        results.append(True)
    except:
        results.append(False)

# Report the results
OUT = results
4 Likes

It works! thank you all and especially @GavinNicholls :slight_smile:

1 Like

Great!

Just a sneak peek… packaged in Crumple WIP. Will be in the next release.

3 Likes