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 » Script » 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.
Uploading a Script Project to the Connected Workspace
Altium Designer, in conjunction with your connected Workspace, caters for the ability to create and manage Workspace Scripts. Such scripts are created directly within the Workspace, with the relevant script project (*.PrjScr
) uploaded to a revision of a target Workspace Scripts. The process is the following:
- Create a new Script Item in your connected Workspace using the Explorer panel. Refer to the Creating & Editing Content page to learn more about creating Items in the Workspace.
-
Right-clicking on the required Script Item in the Explorer panel and choose the Upload command from the context menu. The standard Windows Open dialog will appear, with which to browse to the required script project file (
*.PrjScr
). -
With the desired file selected, proceed with the upload by clicking the Open button. The project file, along with all files in the same folder, are uploaded to the revision, and will be available on the Details aspect view tab for that revision, in the Explorer panel.
Alternatively, a script project can be uploaded into a new Workspace Script by dragging the selected script project file and related source files from a source folder in your Windows Explorer and dropping into the required folder in the Explorer panel. The Create New Item dialog will appear, with the dragged files listed in the Sources region. The Name of the Item will be the file names, including extension (entries will be separated by a semi-colon). The Description will be in the format Uploaded from <FileNameandPath>, Size <FileSize>, Created on <FileCreationDate>
(entries will be separated by a semi-colon). Change these as required. The Item ID will be in accordance with the Item Naming scheme defined at the folder level. If the folder has no naming scheme defined, naming will follow the $CONTENT_TYPE_CODE-{000000}
scheme.
Editing a Workspace Script
At any stage, you can come back to any revision of a Workspace Script and edit it directly. Right-click on the revision in the Explorer panel and choose the Edit command from the context menu. This will open that revision in Altium Designer, where it can be edited as required, then saved back to the Workspace as the next revision using the Save to server command (shortcut: Ctrl+Alt+S) – available from the right-click context menu associated with the entry for the project in the Projects panel.
If you need to change the project or associated source stored in a Workspace Script, and you have the updated source files, you can upload those files to that Workspace Script – the new files will be stored in the next revision of that Workspace 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. Use the Install button to navigate to and select a project from the file or Workspace. Repeat this process for all script projects that you would like to make globally available.
The installed Workspace Script project will be available to Altium Designer whenever a user is connected to the Workspace. Note that the installed Workspace Script project is listed by its location or 'path' within the Workspace's folder structure and the ID of the Workspace Script containing the script project data.
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.