Scripting has been a feature of Global Mapper since day one. It is useful for executing repetitive tasks or extensive workflows that don’t require data visualization and allows the user to create custom or batch processes that make use of the functionality built into Global Mapper. Often, larger or repeated workflows do not require visualization. In fact, visualizing data in the workspace and using manual input procedures can slow down some workflows, especially where a prescribed analysis process is to be completed on multiple files. In these situations, scripting a workflow in Global Mapper is an ideal way to increase workflow efficiency.
Global Mapper’s scripting language 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 and optimize workflows in the software. The traditional method of creating a script in Global Mapper required manual text entry, either from scratch or with a text editor. Scripting has been made more accessible with the addition of two new automatic script creation methods in v24. This blog will focus on Global Mapper’s native scripting language, for which the new v24 tools were built. More information about scripting methods in Python, the other available scripting language, can be found here.
To Create a Script:
The original way to create a script in Global Mapper (GM) is to manually type GM’s scripting language as a text file. The vast library of tools and settings gives users complete control over how their data is handled in the software. If you would like to learn how to create scripts from scratch, the Introduction to Scripting webinar from 2021 is a great place to start, you can access it by registering to view past webinars here. While this method hasn’t changed, it has been improved in new versions. The Script Editor was added in v23, allowing users to edit and run scripts from the interface; more on this will be covered later in this blog. On top of that, V24 has introduced two new ways to generate workflows or commands as scripts directly from the interface.
A more accessible way to create a script is to use the Script Builder option from the File menu. The Script Buildertool will record actions taken in the Global Mapper interface as Global Mapper Script commands, and list them in the Script Builder Dialog. Once recorded, you can edit the commands and export them to a Global Mapper script file. This is incredibly useful as it doesn’t require knowledge of Global Mapper’s scripting language. It can import files, or directories of files, execute commands, etc. to fulfill a workflow.
Here’s an example workflow, where a lidar file was imported, gridded with the Elevation Tool, and exported as a grid file. Specific variables for each command can be edited in the right-click menu. This script can be saved as a .gms file to be opened in the Script editor for editing or troubleshooting, expansion and elaborating, or even to simply run it independently.
Another way to generate tool commands is to copy them directly from the Script Builder dialog using the new Copy Script button located at the bottom of the dialog in applicable tools. This copied script will contain all of the settings specified in the dialog, and can be loaded into the script editor for fine-tuning, or to adjust to new datasets.
To run a script file, you can double-click on the gms file without opening Global Mapper, execute it from the File > Run Script option, or load it into the Script Editor tool.
To edit scripts:
Once generated, scripts can be tailored to different workflows and datasets. The Script Editor is a built-in tool to assist with this, as it can be used to create, view, edit, and run scripts in Global Mapper. One of the benefits of using this tool is Syntax Coloring which makes the text easier to read. This tool can, of course, run complete workflows, but it also gives you the ability to run a single command on data that’s already loaded in the workspace.
Scripts can be repurposed to new datasets and files by changing the path names and some data-specific settings. For example, let’s look at this contour script generated from the Copy Script option in the Generate Contours tool. You can change the file path, or add a file directory. When changing files, you may need to adjust some settings to fit the new data. Here in the contour tool, the elevation range is automatically calculated to fit the max and min of the loaded data. If we change the file, and thus change the elevation range, the script would not give a desirable output. For this tool, we can remove this variable, and Global Mapper will use the default value, that is, the max and min values for the file at hand.