Hello, I’ve been starting with a Python code to set parameter values according to a global parameter in revit (zoning codes), but I can’t make it recognize the global parameter as a string, when I connect a code block with the same string it works fine, but when it is extracted from the revit model, as a list it doesn’t, what am I doing wrong??
Are you sure the value you are getting is a string? You can check with the Object.Type node. If it’s not a string, convert it with the Object.ToString node.
Yes, I used the “string from object” node but its the same result, I tried the object.Type node and it returns “System String”
I solved it adding a List.FirstItem node, but I don’t really know what was the problem
The problem is that your input is a list and not the string itself.
Your python code is not suited to handle lists.
I think it’s because it’s actually a list. The first item of that list is the string. In the python code try: IN
Edit: beat me to it
I’d also suggest using a dictionary for that task instead of conditional statements. If this is your final goal of course:
That way you take care of list inputs as well:
And since I don’t know how to use a code block dictionary with default value (if the item is not present in the dict) here is a python:
dict1 = dict(zip(IN,IN)) default = IN output= if isinstance(IN, list): for i in IN: output.append(dict1.get(i,default)) else: output = dict1.get(IN,default) OUT = output