Declaring a global variable / parameter (Grasshopper or C#) for whole Grasshopper document

Hi,

I’ve been using Grasshopper for a while but I’m trying to be more efficient with wires & components. As a result I’ve started delving more into the C# component.

Is there a way to declare a global variable that can be called throughout the Grasshopper document without pluging it in to all relevant components?

e.g. Can I make an integer of Length = 1000 and call it throughout the rest of my C# components without declaring it in each one?

I’m trying to avoid pluging a number slider into multiple C# components.

Any help would be appreciated, thanks
Dan

I am responding to follow the thread as I am interested in something similar.

What I would like to do is create a counter that will keep record of how many instances of an object type (in my case it would be from a custom class) are present on the canvas. This way I should be able to assign a unique ID to each object.

Between scripting components you cannot communicate because they are compiled at runtime without any common context. I think that this could be supported simply by a static class with editable properties in Grasshopper.dll. Anyway, it’s quite trivial to use the definition with a named parameter to create document variables that you can read and write from code. In case of a text variable, take a panel, assign the value, name it, and search in the forum how to find and edit a GH_Panel.

1 Like

Metahopper!

Maybe compile using Visual Studio rather than C# scripting node?

In visual studio making a library of components is the solution. You can define a static class and access all it’s exposed parameters from anywhere
Gd

1 Like

Hi Martin - Metahopper looks realy useful. I’ll have a good experiment with it. In fact, it looks like it might help me with some other things as well. Many thanks for the suggestion.

1 Like

Visual Studio does look like a good way forward. It looks like I just need to get better at using it. You’ve given me a good starting point - thank you for pointing me in the right direction

Just for completeness, the GHPython component (and the EditPythonScript editor) can read/write to the sticky dictionary. Which enables creating global variables within a Rhino instance:

This thread might also be relevant on the C# side:

2 Likes