Creating and Storing Scripts

Old Content - visit

Parent page: Scripting

Altium Designer scripts are normally created and stored in a Script Project (*.PrjScr), but can be added to or stored in any type of Altium Designer project.

To begin writing scripts, the logical place to start is by creating a new script project and adding script files to that project.

Creating Script Projects and Scripts

A Script Project helps you to manage your scripts, and can be created by selecting File » New » Project » Script Project from the main Altium Designer menu.

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 name and select Add New to Project from the context menu, or choose File » New » Script Files from Altium Designer's main menu.

With a new script project established, add a new script or form unit in the language of choice.

Use File » Save Project As to save the project as the desired name. Similarly, use File » Save As to save and rename the new script.

Along with the scripting language choices that are presented when creating a new script, there are basically 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.

A DelphiScript Unit with DelphiScript code.

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.

A DelphiScript Form with a Code and a Form tab.

Add a Script to a Design Project

A new (or existing) script can be added to a design project such as a PCB project (*.PrjPCB).

With the PCB Project selected in the Projects dialog, navigate to the File » New » Script Files menu and choose a suitable script type. When added, the new script will appear in the currently focused project.

Adding a new script to a design project other than a script project

Add an existing Script to a Project

To add an existing scripts to a script project (or any other project type), right click on the project name in the Projects panel and select Add Existing to Project from the context menu.

In the Choose Documents to Add to Project dialog, navigate to and select the desired script file to add. You can multi-select a number of scripts files to add into the script project. For design projects (as opposed to script projects), change the dialog's file name filter menu to the 'All files' option so you can choose script files.

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 therefore 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.

Global Projects

Script projects can be installed in Altium Designer using the Global Projects feature so that they are preloaded and available when Altium Designer starts. As the name implies, these script projects are seen as global to Altium Designer, so 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 folder via the DXP » Preferences menu and select the Global Projects page. Use the Install button to navigate to and select a project from the Select Script Project File dialog. Repeat this process for all script projects that you would like to make globally available to Altium Designer.

Use the Global Projects Preferences page to install scripts that need to be globally available.

Global Project allow scripts from a local project of the same type (DelphiScript, EnableBasic, VBScript and JScript) to use routines from the installed global script projects.

Also, when the Select item to Run dialog is invoked (DXP » Run Script), the installed script projects (even if they are not loaded in Altium Designer) will appear along with other script projects currently open in the Projects panel.


You are reporting an issue with the following selected text and/or image within the active document: