Parameter.CreateProjectParameter add Category to existing Parameter

When adding a Project Parameter to a Project, I would like to check if a parameter with that name already exists, if it is instance or type, what unit type, what categories it is bound to, etc. If it does exist, meets my requirements, and is not yet bound to the category I need, I want to add a Category for it instead of creating a double parameter. I found some examples by @Jeremy_Tammik, see below.

I’m having some problems translating these examples to Python. @Andreas_Dieckmann did give me a head start with the new Document.ProjectParameters Node from Clockwork, but I’m not quite there yet.

instance = []
iterator = doc.ParameterBindings.ForwardIterator()
while iterator.MoveNext():
instance.append(iterator.Key.GetType() != typeof( InstanceBinding //results in the error that ‘typeof’ is not defined.
instance.append(iterator.Key.GetType() is InstanceBinding //results in all trues.

It would seem I am in over my head here. Any help?

Or should I just add it as an Issue for the Parameter.CreateProjectParameter Node? It does tend to create surplus parameters as it is now.

Typeof() is C#, not Python. I think clr.GetClrType() or simply GetType() are the Python equivalents.

1 Like

If you are interested in creating shared parameters, you should also check out the RvtMetaProp add-in:

clr.GetClrType() gives me the same result as …is InstanceBinding

GetType still needs to be defined. I guess I’m just getting the syntax wrong. It looks like Python views both ‘typeof’ and ‘GetType’ in this line as a variable that has not been defined yet.

Maybe there is something in the RvtMetaProp add-in code that was missing in the samples. Using a seperate add-in is not my prefeerd solution, I’d like to write a script and store results in a project parameter, and make one if an appropriate parameter doesn’t exist yet.

Is append(iterator.Key.ParameterType) what you’re after? In this case, see here

Unfortunately, no. I’m trying to find if the ElementBinding object for a parameterDefenition is InstanceBinding or TypeBinding.

I had not tried to get the type through Python yet, and it does work perfectly.
Also available as built-in Node: Parameter.ParameterType

This should help:

itCurrent = []

iterator = doc.ParameterBindings.ForwardIterator()

while iterator.MoveNext():

for i in itCurrent:
		if 'InstanceBinding' in i:

OUT = (tests)

Wow, thanks!! the trick was to replace
instance.append(iterator.Key.GetType() from the code @Andreas_Dieckmann wrote
with your
Anyone have a link to an in-depth explanation of the difference?

Ended up with this working code:
#forked from Clockwork Document.ProjectParameters Node
isInstance.append(iterator.Current.GetType() is InstanceBinding)

Parameter.CreateProjectParameter add Category to existing Parameter


Key returns the Internal Definition while Current returns wether the InstanceBinding or TypeBinding object, this is quite clearly understandable in the first link you sent…

Definition d = it.Key as Definition;
Binding b = it.Current as Binding;

Once you know what to look for that is. Thanks Yna_Db

now to see if I can add a Category to a BindingMap. Baby steps…


Have succeed adding categories to a BindingMap?
Anyone has an idea how to do it in Python?

I found the solution is in the c# script of @Jeremy_Tammik … Thank you Jeremy.
So you will need to use ReInsert instead of Insert for the bindings that are already exist.
if its not exist yet the ReInsert doesn’t work.

  • when you use ReInsert you have to include the new categories you want to add with the categories that already been added otherwise the parameters and its values will be deleted from the categories that are already exist in the binding.

    for b in bool:
      	if b == True:
      	else : 
      #parameters aan de project toevoegen
      bindmap = doc.ParameterBindings
      for p,b,g in zip(parameters,bind,group):
      		bindmap.ReInsert(p, b, g)
      		i += 1
1 Like