Fologram Docs

Functions and Global Variables

Grasshopper definitions typically consist of interconnected components with a large number of inputs defined by sliders or references to Rhino geometry. If a component or input to a grasshopper definition is updated, anything connected to the output of this component will also update. If you want a change in one part of your parametric model to update some other part, the two must be connected. This is very convenient if your parametric model is conceptually a single program that performs one task. However if your want to perform multiple tasks within a single parametric model, for instance to switch between drawing and editing a collection of curves in mixed reality, this paradigm can be challenging to work with.
 

Event-based modelling

When using Grasshopper to build mixed reality applications with multiple modes or tools, it usually makes sense to break up your definition into isolated groups (or functions) that perform specific tasks. Fologram includes a State Gate component that can enable or disable target groups of components based on the current state of your mixed reality application. For instance, the state gate can check the state of a button and enable a group of components that should only run when the button is pressed, or check whether a user is performing a particular gesture in mixed reality and run a group of components that use that gesture for a particular modelling task. The state gate will disable groups of components that are not required by the current state of the application to reduce application complexity and latency.

Global Variables

When a grasshopper component is disabled, it doesn’t output any data and components downstream do not update. This means that when we use the state gate to enable and disable groups of components in our definition we can no longer use grasshoppers parametric connections to pass data between them. For instance, in our scenario above, we imagine creating a new curve when we ‘press’ and then adding control points to the curve when we drag. If we have a point component that defines the start of our curve in the group of components that is enabled when we ‘press’, and connect this to a merge component in our ‘drag’ group to add another point, we will find that the original point is an empty value and our merge will not update.
To solve this problem Fologram adds support for global variables that are stored on the grasshopper document rather than within individual components.

Creating a global variable

A global variable is created with the Set Global component. The variable must be given a name by right-clicking on the component and entering a name into the text field. When an input is first connected to the Set Global component, a variable of that name is created and assigned the value of the input. If another Set Global component in the definition uses the same variable name it can be used to update the value of the variable with new data. Disabling a Set Global component does not prevent the variable from being accessed elsewhere in the definition, and so global variables can be used within groups that are enabled and disabled by the State Gate.

Getting global variables

Global variables can be retrieved using the Get Global component. The variable to be retrieved is defined by right-clicking on the component and specifying the exact variable name. Be default, the Get Global component will display a refresh button if the value is updated. This button can be manually pressed to pull the latest value and trigger an update to any connected components. However the Get Global component also works slightly differently to other grasshopper components in that it will also retrieve the latest value if the component it is connected to updates. This is useful for ensuring that you are always getting the latest value of a global when required by the rest of your definition.
You can also force a global variable to update whenever a new value is set (regardless of whether the connected component updates) by right clicking the Get Global component and enabling Dynamic Updates.
⚠️
If a Get Global component has a Set Global component downstream that updates the same variable, enabling dynamic updates will create an infinite loop.