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.
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.
itCurrent = []
iterator = doc.ParameterBindings.ForwardIterator()
while iterator.MoveNext():
itCurrent.append(iterator.Current.GetType().ToString())
for i in itCurrent:
if 'InstanceBinding' in i:
tests.append('instance')
else:
tests.append('type');
OUT = (tests)
Wow, thanks!! the trick was to replace
instance.append(iterator.Key.GetType() from the code @Andreas_Dieckmann wrote
with your
instance.append(iterator.Current.GetType()
subtle…
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)
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:
bind.append(app.Create.NewInstanceBinding(catset))
else :
bind.append(app.Create.NewTypeBinding(catset))
#parameters aan de project toevoegen
bindmap = doc.ParameterBindings
for p,b,g in zip(parameters,bind,group):
try:
bindmap.ReInsert(p, b, g)
i += 1
except:
continue