Add categories to existing parameter

Hey everybody

I am currently working on a Dynamo script that checks if an element have a parameter and if that parameter is filled correctly. If the element doesn’t have the parameter, but the parameter exist for other elements, I want Dynamo to add the category of my element to the list of categories that the parameter is created for.

An example could be if the parameter “BIM7AATypecode” was set to columns (see picture) but not ceilings, because the creator of the revit file have forgotten to check the box, then I want Dynamo to “check” the box.

I have been toying a bit with python, but I haven’t been able to find a way to find a way to add categories to the parameters “database”.

You will need to use Python for this. This is the method that you need:

Thanks for your reply, and I think I am partly there.

I have managed to produce the following code, which returns false and doesn’t add the category to the parameter:

import clr

import Autodesk.DesignScript.Geometry

# Import Element wrapper extension methods
import Revit


# Import geometry conversion extension methods

# Import DocumentManager and TransactionManager
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import RevitAPI
from Autodesk.Revit.DB import *

import System
from System import Array
from System.Collections.Generic import *

import sys

pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'

#categories to add to parameter
cat1 = UnwrapElement(IN[0])
cat2 = UnwrapElement(IN[1])

#Parameter name
param = "test"

iter = doc.ParameterBindings.ForwardIterator()

setCat = None

categorySet = doc.Application.Create.NewCategorySet()

while iter.MoveNext():
	definition = iter.Key
	elemBind = iter.Current
	if definition.Name == param:
		out = elemBind.GetType()
		instanceBinding = doc.Application.Create.NewInstanceBinding(categorySet)
		setCat = doc.ParameterBindings.ReInsert(definition, instanceBinding,BuiltInParameterGroup.PG_TEXT)

OUT = setCat

@krbr I believe what you are trying to achieve is to add a category to a shared parameter, which is a project parameter, correct?

I did some digging into the API and used your code as an inspiration.

My code seems to work, but I have only attempted to add one category and for a single parameter.
But I hope you will have a look at it and maybe it can help you to move forward :grinning:
By the way, I am using Dynamo 2.0 which I now realize might have been silly…

My approach is:

  1. Get the external definition from the SharedParameterFile
  2. Loop through the ParameterBindings
  3. Insert the missing category into the binding
  4. ReInsert the binding into the external definition.


Hey @lsmm, looks like that is the way to go, I am however, getting “null” from the app.OpenSharedParameterFile().

I have tried looking it up in the API, but so far I have been unable to make it work…

I will give you an update if I have any luck.

@krbr Can you check the Application.SharedParametersFilename property? Perhaps setting it manually before attempting the app.OpenSharedParameterFile() method could fix it. I will look into it later, unless someone else comes up with a fix.

@krbr I tried to add a function, that should set the path of your sharedparameterfile based on a filepath node. It currently only does so, if the path is null. I guess one could just always overwrite the path, unless you change it frequently. However, I do not know if it solves the problem as I am not able to reproduce it.


I am afraid I don’t quite understand what the filepath is leading to? Is it a notepad file with some names or?
Your help is much appreciated.

@krbr the filepath is leading to your SharedParameterFile. Basically, my idea was to exchange your SharedParameterFile with itself, since you said app.OpenSharedParameterFile returns null. I dont know if it works, but thought it might be worth a shot.

It’s a .txt file, probably located somewhere on your network drive or maybe locally. You should be able to find that path under “Manage” -> “Shared Parameters”.

Hey again, thanks for all the help, it is much appreciated!
Unfortunately I haven’t been able to work out how to fix the problem, but I am confident that your solution is the solution to the original problem.


Did you figure out a solution for this one?

Hey Jannis

No I haven’t found a solution yet.


Hey :slight_smile:
This one should work for you:
_add_current_selection_to_projectparameter.dyn (34.9 KB)

Unfortunately it does not solve my problem of adding subcategories via the Orchid Node :frowning:
If anyone has a solution for this, please help me ;D