Input a dictionary from dynamo (DesignScript.Builtin.Dictionary) to a custom ZeroTouch node

Hi Everyone,

I am trying to feed a dictionary that comes out of a python node (type: DesignScript.Builtin.Dictionary) into a zerotouch node that I am developing in C#.

How can I cast or convert this input to a normal C# dictionary that I can then use in my code?

I think you’d need to get the key/value pairs from the DesignScript dictionary and put them in a new Dictionary<string, object> in your ZT node.

1 Like

Thank you for the reply.
But how do I access the pair in my code?
Using dictionary type as the input type does not work.

you can just reference the Dynamo dictionary type, it’s in the designscriptbuiltin.dll which is part of the dynamocore nuget package.

2 Likes

it also looks like IDictionary should be converted automatically, or Dictionary for that matter so a code repro case would be useful.

1 Like

I was able to use System.Collections.IDictionary and it worked fine.
Thank you!

1 Like

I solve that using this methodology.

  1. Your Node Input must be an IDictionary.

  2. Then, inside in your Node logic you need to convert the IDictionary to a strong typed Dictionary.

This allows you to consume your input data as you wish.

See images below showing how I implement that.

Node Method

Generic extension method to convert IDictionary to the strong typed Dictionary

Dynamo Graph

1 Like