Global Variables

Navigation:  Variables and Related Parametric Tools >

Global Variables

Previous pageReturn to chapter overviewNext page

A global variable is a named value of one of the two types: text (string) or real. Global variables are accessible for editing in the variable editor or via the special functions across all currently open documents. The list of global variables and their values are saved automatically upon exiting the application (in the registry) and are restored upon launching the application.

Global variables are created by the command "SG: Create/Edit Global Variables". The command is called by one of the following means:

 

Icon

Ribbon

Parameters → GUI Control → Global Variables

Keyboard

Textual Menu

<SG>

Parameters > Global Variables

 

Upon calling the command, the dialog box is displayed on the screen where you can create new global variables or delete and edit the existing ones. To create a new variable, press the graphic button [New]. In the coming up dialog box defining the name, value and type of the variable being created. Upon the confirmation, the entered data will be displayed in the command dialog box. Created global variables will be stored until you delete those or update your system installation (the global variables are stored in the system registry). A global variable can be accessed from any document managed by one user. You can retrieve the value of a global variable in any dialog that allows use of variables, by the following special functions:

getg ("Name",N) – gets the value of a real global variable

tgetg ("Name",N) – gets the value of a text global variable

s456

s457

The first argument defines the name of the created global variable. The expression after the comma defines the value to be used in the case if the global variable is not found.

Exercise: create a new variable of a certain type (real or text) in the variable editor within a drawing, and then make a function call for accessing a global variable of this type. If the global variable with the specified name ("L") exists in your user registry, then its value will be displayed in the "Value" column. If the specified global variable  is  not found then the second function argument will be displayed in the "Value" column.

Besides that, a global variable can be created, or its value modified, in the common variable editor or in any dialog that allows use of variables. The following functions are provided for this purpose:

setg ("Name",N) – sets the value of a real global variable

tsetg ("Name",N) – sets the value of a text global variable

s458

 

In this case, the first argument is the name of the global variable, and the expression in the second argument defines the global variable value.

Exercise: create a new variable ("var_2") in the variable editor, and assign it to the function setting the value of a global variable. If a global variable with the specified name already exists, then its value will be modified. If the variable with the specified name does not exist, then it will be created and displayed in the main pane of the Global Variables dialog box.  If a global variable is defined in the drawing by one of the functions, setg or tsetg, then opening this drawing in a different user account (on a different computer) creates the global variable on that account/computer automatically. Note that global variables can be used, for example, for automatic creation of drawing documentation. Suppose, the user creates a global variable - the developer's name. The value of this variable can be entered in the title block of the drawing by using the described functions. Thus, a portion of the title block template will be filled in automatically as you insert the title block.

s459

s460