Creating & Storing Scripts in Altium Designer
Altium Designer scripts are usually created and stored in a Script Project (*.PrjScr
), but can be added to or stored in any type of project.
To begin writing scripts, start by creating a new script project and adding script files to that project.
Creating Script Projects and Scripts
A Script Project helps you manage your scripts, and can be created by selecting File » New » Project » Script Project from the main menus.
A new project (Script_Project1.PrjScr
) to store scripts will be listed in the Projects panel.
To add a new script to the project, right click on the project name and select Add New to Project from the context menu.
When creating a new script, there are two script types to choose from depending on your project requirements – Script Units and Script Forms.
Script Types
Script Units
A script unit is a script document with specific language syntax, for example DelphiScript.
Script Forms
A Script Form is a window that can host a range of controls such as buttons, memos and list boxes that can have event handlers. In the editor, a Script Form has two views that are selectable with the Code and Form tabs, as can be seen at the bottom of the script document shown below.
Script relationships within a Project
When multiple scripts are in a project, any script (using the same language set) within that project has access to global variables and procedures. All scripts in a project are 'visible' in effect, so a procedure in one script can call another procedure in different script within the same script project.
It is important to have unique procedure and global variable names for scripts within the same project. One approach is to move all the common procedures/functions that are used in different scripts to one new script within the same project. This allows the procedures and functions in this new common script to be reused easily for different script projects.
► Refer to Writing Scripts for an example of calling a procedure from another script.
Global Projects
Script projects can be installed using the Global Projects feature so that they are preloaded and available when the software starts. The global variables and procedures from these scripts are available for use in other open script projects.
To make a script project global, navigate to the Scripting System - Global Projects page via the Preferences dialog, accessed by clicking on the control button at the top-right of the workspace. Use the Install button to navigate to and select a project from the file or server. Repeat this process for all script projects that you would like to make globally available.
Global Projects allow scripts from a local project of the same type to use routines from the installed global script projects. When the Select item to Run dialog is launched (File » Run Script), the installed script projects will appear along with other script projects currently open in the Projects panel.