# Context

A context is an OML script for defining variables in a diagram.

A context is an OML script associated at each level of the hierarchy of a model. A model includes a main diagram with its own context. If the main diagram includes super blocks, each super block can have its own context. Contexts are semi-global, meaning a variable defined in a diagram applies to that diagram and in diagrams at all levels below unless the context of a lower-level diagram is defined.

Because a model can be hierarchical and variables can be defined at different levels, the software offers the Available Variables option which lets you navigate in a diagram and get a report of all variables that are known or defined at a current level.

## Define a Context

Define a context inside of a diagram.

The Diagram Context tab contains an OML text editor for defining variables in a script for use in the definition of block parameters. All OML functions available in OML libraries are valid to enter into the script. All the variables that you define in the script are placed in the scope of the diagram and can be used to define block parameters in that diagram in addition to offspring diagrams and their contexts, as long as those variables are not redefined by another context.

For example, if you enter in a script a=3, then the variable a can be used to define the gain parameter of a Gain block as “2*cos(a)” in a diagram.

1. From the ribbon, select the Diagram tool:

The Diagram dialog displays two tabs, Context and Available Variables. By default the dialog opens to the Context tab which includes an OML text editor to define variables for the diagram.
2. Define the variables in the context as required for your diagram.
Important: All OML commands and syntax are supported. However, when naming variables, avoid using an underscore "_" at the beginning of the variable name. The underscore is reserved for internal use to hide temporary variables.