Global Mapper Pro’s Script Editor with Syntax Coloring
The user interface of Global Mapper Pro is designed to be intuitive and efficient to use. From customizable toolbars to dockable 2D, 3D, and cross-sectional views of map data, the program user interface provides easy access to the program’s data creation, analysis, and visualization tools. While exploring data and performing visual analysis is an important step in GIS work, larger or repeated processes often do not need the same level of visual and interface interaction. In fact, the rendering and manual input procedures can slow down some workflows where a prescribed analysis process is to be completed on single or multiple files. In these situations, scripting a workflow in Global Mapper Pro is an ideal way to increase workflow efficiency.
Scripts in Global Mapper Pro can be written in Global Mapper Script, a proprietary text-based scripting language specific to the program, or Python, a widely used interpreted scripting language. While scripts can be written, edited, and run outside of the Global Mapper program, a Script Editor tool allows Global Mapper and Python scripts to be created, opened, edited, and run within the application.
Global Mapper Pro’s Script Editor evolved as a way for users to automate processes in the program. Running a created script through this Global Mapper Pro tool allows currently loaded layers to be used in the execution of the script and layers generated by the script to be automatically displayed. This method of automating a workflow with a script through the Script Editor combines the efficiency of scripting with the visual inspection of data after an automated process is complete.
When creating a script in the Script Editor, an option in the Edit Menu allows the script language to be selected, since both Global Mapper Script and Python can be written and run in this interface. With the appropriate language selected, syntax coloring of the script text is enabled to help users differentiate commands, parameters, and values as the script is developed.
Global Mapper’s text-based scripting is easy to learn and use. With a comprehensive knowledge base containing all commands and parameters in Global Mapper Script, users new to scripting can easily automate analysis and execute tasks in order to optimize the use of the program. Syntax coloring in Global Mapper adheres to the following scheme.
Commands – Light blue – This text is the beginning of an action in Global Mapper Script. Commands range from importing a file to creating an elevation grid, editing vector features, and exporting data.
Parameter – Blue – Parameters that specify a needed value for a command are shown in dark blue, making it easy for parameter names to be distinguished from commands.
String Values – Orange – In Global Mapper Script, parameter values are stings typically bounded by single or double quotes. When parameter values carry this string syntax, they are shown in orange. Note that single word parameters can omit the quotation marks, but without these marks, parameter value text will be shown in black.
Variables – Green – Variables in Global Mapper Script are bounded by percent signs (%) and written in green in the Script Editor. Variables often appear as or within parameter values.
Comments – Gray – Comments are used to add supplementary information about a script. In Global Mapper Script, comments appear in gray. Multiline comments in Global Mapper script will show only the first line in grey and the following lines in black.
Python scripts in Global Mapper Pro are not restricted to the Global Mapper library. Third-party Python libraries can be imported to integrate the functionality of other programs and libraries with Global Mapper Pro. The syntax coloring for a Python language script follows default Python coloring with the addition of a dark magenta/purple color.
Statements – Blue – Statements in Python, like import, def, conditional statements, and others are shown in blue in Global Mapper Pro’s Script Editor.
Functions/Methods – Dark Magenta – Functions from the Global Mapper library, other libraries, and Python functions that indicate or begin a specific task are shown in purple.
Strings – Red – Strings, such as file paths, text, and numeric values used in a function or printed to the script results, are shown in red.
Comments – Green – Lines beginning with a # symbol are comments adding context to a Python script. Comment text is shown in green in the Global Mapper Script Editor.
To begin writing any script in Global Mapper Pro, open the Script Editor from the File Menu, load an existing script or set the language from the Edit Menu within the dialog, and begin creating. Completed scripts can then be saved to local files using either a Python (*.py) or Global Mapper Script (*.gms) file extension for later use or editing. While writing in either language, suggested commands, parameters, and functions can be brought up by using the keyboard shortcut Ctrl + Space. Using this shortcut will populate a dropdown list of values to choose from based on a partial string, helping to efficiently create scripts and avoid incorrect, error-causing functions and commands.
If you enjoyed this blog, you may also find these other resources useful: