KB: Edit a script to accommodate the latest changes in Altium API

Altium Designer Altium Designer
Starting in version: 18 Up to Current
Due to progressive updates to the Altium Designer API, and therefore the scripting system Interfaces and their methods and properties, some legacy script examples may not work as originally intended, such that some edit on those need to be made to have them work in the latest Altium Designer.

Solution Details

 For many questions & issues, posting on our community forum to see if another user has written a script for a similar function or had a similar issue may get a favorable response:
https://forum.live.altium.com/#/search?searchText=script
Please understand that creating and reviewing your own scripts is outside the scope of our technical support.
 
Upfront, there are few known changes that need to be made to accommodate progressive updates to the Altium Designer API:
• In some variable assignments, you need to prepend set\get to avoid the error "Object doesn't support this property or method".
• It is only starting in AD19 that unlimited number of mechanical layers is supported, such that constants prescribed prior are defined only in the fixed range of [eMechanical1..eMechanical16].

 

Variable Assignments

You need to prepend set\get to avoid the error such as below.

image.png

e.g.
error:
Param = SchServer.SchObjectFactory(eParameter, eCreate_Default)
no error: Set Param = SchServer.SchObjectFactory(eParameter, eCreate_Default)

 

Constant Definition

It is only starting in AD19 that unlimited number of mechanical layers is supported, such that constants prescribed prior are defined only in the fixed range of [eMechanical1..eMechanical16].  A newer, more robust way to access mechanical layer would be as depicted in the following code snippet.

for LayerType := 1 to N do
    begin
        LyrMech := Stack.LayerObject[PCBServer.LayerUtils.MechanicalLayer(LayerType)];
        LayerName := Board.LayerName(PCBServer.LayerUtils.MechanicalLayer(LayerType));
    end;
end;


 

Script Language supported:

For the foreseeable future, Altium continues to support the use of different kinds of scripting languages.  Delphi is recommended, as this is a language for which no additional resources need to be installed on a computer to run it.  Since Version AD18 the support for JavaScript, VisualBasic Script, EnableBasic Script and TCL needs to be enabled in the Preferences ► System ► General ► Advanced section of Altium Designer.  Check the box under the Value column for the Preference Name Legacy.Scripts.SupportOldLanguages.
 

List of Additional Documentation Related to Scripting:

https://www.altium.com/documentation/altium-designer/automating-design-tasks-with-scripting-overview
   (notice there are sub-pages in the left pane)
https://techdocs.altium.com/display/SCRT/Scripting
https://techdocs.altium.com/display/SCRT/Script+Examples+Reference
https://www.altium.com/documentation/altium-designer/more-about-scripting-ad
https://blog.mbedded.ninja/electronics/general/altium/altium-scripting-and-using-the-api/
https://github.com/gbmhunter/AltiumScriptCentral
https://github.com/Altium-Designer-addons/scripts-libraries
https://github.com/Altium-Designer-addons/scripts-libraries/wiki
https://www.altium.com/documentation/altium-designer/writing-scripts
https://resources.altium.com/p/using-chatgpt-altium-scripting
Managed Scripts:
https://www.altium.com/documentation/altium-designer/managed-scripts-ad
https://designcontent.live.altium.com/ReferenceDesignDetail/Scripting_System

 

Participating in SDK Beta Program: 

In contrast to scripting, SDK can be used for larger projects, where Vector manipulation, dictionary, maps, sort, select and group algorithms are needed. Therefore a compiler needs to be installed.  For companies that want to create their own applications, if qualified, we may provide the Altium Software Development Kit (SDK) in the current beta version free of charge.  The technical exchange and questions about the Altium Developer will take place exclusively via the forum provided at that time.

Information and the possibility to request this extension can be found on the following websites:
https://www.altium.com/altium-dxp/overview  (You can begin a participation form from the bottom of this page.)
https://www.altium.com/documentation/altium-dxp-developer/an-overview-of-the-altium-sdk
https://www.altium.com/documentation/altium-dxp-developer/altium-designer-sdk-beta

 

If you find an issue, select the text/image and pressCtrl + Enterto send us your feedback.