So I can create a dictionary with pretty standard Python in a Code Block.
But in a Python Script it fails with IronPythonEvaluator error: ‘string’ does not contain a definition for ‘Key’
All I could find on the issue is: https://github.com/DynamoDS/Dynamo/pull/9296
Did the code block work? When I try to recreate it I am getting an error.
The python code works for me until you try to output the dictionary. Dictionaries in Dynamo are built differently than Python so you cannot always interchange them. It seems the Dynamo dictionary doesn’t allow the same set up as the Python so when you try to output it and Dynamo tries to convert the dictionary to a Dynamo version, it fails.
I believe future versions of Dynamo will support Python dictionaries being passed out of Dynamo. For now, the best solution is to output a list of keys and a separate list of values. Your data structure seems to be a bit more complicated (dictionary of dictionaries) so there will be a fair bit of nesting, but as long as you maintain the hierarchy you should be able to build it back into a Dynamo dictionary.
Note that this is actually Design Script, not Python. Syntax is basically the same. As @cgartland noted the Python node supports Dictionaries as an output in 2.1+.
The code block works perfectly. I wasn’t showing the whole code block as it was quite lengthy. Outputs a proper dictionary.
Then can you please show it?
Thanks. Working with Dynamo 2.0.3 for now.
Seems like that only handles conversions from Dynamo to Python but not the other way around.
You can try the following but if your dict has nested dicts you’ll have to recursively handle those too: