Creating Global Sticky Variables

Sometimes there is a need to share information between Grasshopper and Rhino.Python. This can be done through a global sticky variable creating a definition wide global sticky variable. Both Rhino.Python and gh.python use the same Python instance, so the Python sticky is shared between the two.

With a global sticky variable all the components in a definition can access the information.

As an example, here is a definition that creates a simple sticky variable and passes it to another component that is not connected:

/images/sticky-ghpython.png
import scriptcontext as rs

rs.sticky["someName"] = x #"x" is the input for the component

The scriptcontext.sticky creates a global variable names “someName”. This can be referenced in another component using this code:

import scriptcontext as rs

a = rs.sticky["someName"] #output the value of the sticky

Within Rhino.Python, the same value can be accessed the same way through Rhino.Python sticky.