GDL Basics 5 – Using Global Variables

26 September 2013 Andrew Watson No Comments
ArchiCAD, Tip of the Day

Often a GDL object may need to know something about the environment into which it is placed. GDL offers a bunch of requests and global variables that can provide this information.

Go to ArchiCAD’s Help menu, and open the GDL Reference Guide.


Under Miscellaneous > Global Variables you’ll find a list of all the global variables you can use.

As an illustration, I’ll use three global variables to force my North Pointer symbol to consistently point to Project North.

First, I’ll open the library part for editing as described here …

Now I’ll click on the 2D Script button.


The current 2D script tells the object to draw the North Pointer symbol. But I want the symbol to automatically rotate so as to always point North.

To make the 2D symbol rotate, I will have to add some lines of script:


Let’s examine these lines of script.

if symb_mirrored then mul2 -1, 1

The first line uses the global variable symb_mirrored. If the North Pointer was placed in a mirrored state, then we need to flip it back to a non-mirrored state, otherwise it might point the wrong direction. The value of symb_mirrored will be 1 if the symbol was placed mirrored, otherwise 0. In this case I’ve used the command mul2 -1, 1 to flip the symbol.

rot2 glob_north_dir – symb_rotangle – 90

The second line tells the 2D symbol to rotate (rot2) about the local origin by the angle specified. In this case we want to rotate by the Project North direction, which is given by the global variable glob_north_dir. But the original symbol was drawn pointing directly up, so we need to subtract 90 degrees (by convention all angles are measured in a counter-clockwise direction from the horizontal). Of course, we must allow for the possibility that the user may have rotated the symbol in plan view, in which case we must rotate back by the same amount – given by the global variable symb_rotangle.

Finally, it’s really important to add comments to the script so that next time you open it for editing, you will be able to understand what is intended by the various commands and variables. To add a comment, simply insert an exclamation mark ! followed by the comment text.


Now when I save the library part, any placed instances immediately turn to point North. If I try to rotate or mirror the symbol, it refuses to change direction and grimly continues to point North (like a magnetic compass, or Dr Suess’s North-going Zax pictured below). If I change the Project North, the symbol quickly rotates to match.


In this example, I used 3 global variables in the space of 2 lines of script (not counting comments as they don’t really do anything):

  • symb_mirrored – 1 if the object is placed into the project in a mirrored state, otherwise 0
  • symb_rotangle – the current rotation angle of the placed object measured counter-clockwise from the x-axis
  • glob_north_dir – the direction of project North measured counter-clockwise from the x-axis

There is a plethora of global variables (perhaps two or three plethoras), and it’s a good idea to be familiar-ish with them. If you need information about the environment of a library part, chances are it may be available as a global variable. If not, your next best guess would be a request, but more on that later…

Tags: , ,