Python script doesnt recognize string

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??

http://imgur.com/FhObB47

http://imgur.com/iszS0Cx

http://imgur.com/nljsE72

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.

1 Like

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.

1 Like

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[0][0]

Edit: beat me to it :slight_smile:

2 Likes

I’d also suggest using a dictionary for that task instead of conditional statements. If this is your final goal of course:

edit:
That way you take care of list inputs as well:

2 Likes

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[0],IN[1]))
default = IN[2]
output=[]
if isinstance(IN[3], list):
	for i in IN[3]:
		output.append(dict1.get(i,default))
else: 
	output = dict1.get(IN[3],default)

OUT = output

2 Likes