Create a Dictionary in Grasshopper, reference it (un-wired)

I have a dictionary that controls my Grasshopper definition. I have this set up because I have different configurations which are defined from csv files, which are read and transformed to a dictionary to be used across my Grasshopper definition.

A simplified example of dictionary definition below:

My actual definition is pretty large, with the values being read from the dictionary across the document in the 100s of times. This forces to carry out this dictionary object to all the components in the definition, creating quite of a spaghetti mess.

I was wondering if there is a way to reference this dictionary without wiring, which will help keeping everything tidy:

You can do this by using the gh doc sticky dictionary.

import scriptcontext as sc

KEY = "My_Global_Dictionary_xyz"

# write
sc.sticky[KEY] = Dict
import scriptcontext as sc

KEY = "My_Global_Dictionary_xyz"

# read
Dict = sc.sticky[KEY]

EDIT: Note that any downstream components that read the dictionary won’t update automatically if the dictionary is modified. If you want to keep automatic updates, you’re probably better off just using hidden wires.

1 Like