Creating & Storing Scripts in Altium Designer

Now reading version 23. For the latest, read: Creating & Storing Scripts in Altium Designer for version 25
 

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.

With a new script project established, add a new script to the project.
With a new script project established, add a new script to the project.

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.

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.

A Script Unit with script code.
A Script Unit with script 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 Script Form with a Code and a Form tab opened.A Script Form with a Code and a Form tab opened.

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:

  1. 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.
  2. 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).

    If the Item has no planned revision, upload will be to the next planned revision, created on-the-fly as part of the upload process.

    Specifying the script project file to be uploaded to the target Script Item.
    Specifying the script project file to be uploaded to the target Script Item.

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

    The uploaded project, along with all files in the same folder, are listed on the Details aspect view tab for the revision of the Script Item.
    The uploaded project, along with all files in the same folder, are listed on the Details aspect view tab for the revision of the Script Item.

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.

Uploading a script project and related files to the initial revision of a newly-created Workspace Script using the drag and drop method.
Uploading a script project and related files to the initial revision of a newly-created Workspace Script using the drag and drop method.

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.

Right-clicking on the top-level entry for a Workspace Script itself will edit the latest revision of that Workspace Script.

Accessing the command to launch direct editing of an existing revision of a script.
Accessing the command to launch direct editing of an existing revision of a script.

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.

To open the project file that is stored in a revision of a Workspace Script, or one of its associated source files, select that file – on the Details aspect view tab for the revision in the Explorer panel – then right-click and choose the Open command from the context menu. The project (all source files too) or source file(s) (as free document(s)) will be opened within Altium Designer.
A Workspace Script can be used indirectly as part of a revision of a Design Preferences Item – when installed as part of those released preferences, through the Scripting System – Global Projects page of the Preferences dialog – in one or more defined Environment Configurations. An environment configuration is used to constrain a designer's working environment to only use company-ratified design elements. Environment configurations are defined and stored within the Team Configuration Center – a service provided through the Workspace. Once you have connected to the Workspace, and chosen (if applicable) from the selection of environment configurations available to you, Altium Designer will be configured with respect to use of preferences. If the chosen environment configuration has a defined Design Preferences Item revision, then that is applied straight away. If the chosen environment configuration applicable to you does not have a Design Preferences Item revision specified, then preferences will remain manually definable. In other words, you are free to manually reuse a revision of a Design Preferences Item, or use a locally saved preferences file. For more information, see Environment Configuration Management (Altium 365 Workspace, Enterprise Server Workspace). Refer to the Accessing, Defining & Managing System Preferences page to learn more about saving design preferences to a connected Workspace.
If you are not connected to your Workspace, you can still work with Altium Designer (under your valid Altium Designer license), but you will not be able to access that Workspace or any other services it provides. You will, therefore, not be able to use any Workspace Scripts. You will only be able to use file-based scripts defined locally.

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.

Use the Scripting System – Global Projects from the Preferences dialog to install scripts.
Use the Scripting System – Global Projects from the Preferences dialog to install scripts.

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.

The Workspace reference links created in the Preferences by an installed Workspace script project are retained and, therefore, will be included if the current Preferences set is also saved to the Workspace. A revision of the resulting Design Preferences Item, if reused, will, therefore, automatically provide the linked Workspace script. Refer to the Accessing, Defining & Managing System Preferences page to learn more about saving design preferences to a connected Workspace.
If you find an issue, select the text/image and pressCtrl + Enterto send us your feedback.
Note

The features available depend on your Altium product access level. Compare features included in the various levels of Altium Designer Software Subscription and functionality delivered through applications provided by the Altium 365 platform.

If you don’t see a discussed feature in your software, contact Altium Sales to find out more.

Content