Using the Altium Design Software API

Now reading version 18. For the latest, read: Using the Altium Design Software API for version 22
 

Parent page: Altium Designer API

Please note that this documentation was last updated for an older version of Altium Designer. While many of the principles and approaches will remain the same, be aware that interfaces, objects, methods, properties, and the like will have changed since then, and will not reflect the entirety of those found in later versions of the software.

The Altium Designer Application Programming Interface (API) is composed of several sub APIs offering specialized classes and system routines. Each API has an Object Model and in turn, the object model is a hierarchical system of object interfaces. These object interfaces represent actual objects in the Altium Designer.

In the scripting system, we refer to the Object Models because we are only dealing with object interfaces that represent objects in the Altium Designer. An object model is a subset of the relevant API. For example, the PCB Object model is part of the PCB API.

The major APIs from the Altium Designer API are: Client/Server API, Workspace Manager API, PCB API, Schematic API and Integrated Library API.

For information on using the interfaces from specific Altium Designer APIs in scripts see:

DXP Software Technology platform

Altium Designer's open architecture is the DXP platform which allows scripters and third party developers to write and integrate their modules into the environment, with API access to the Schematic editor, PCB editor and other server extensions.

Several major software technologies are used in Altium Designer: the client/server architecture technology, APIs, DXP Object Models, and object oriented technologies.

Altium Designer provides a hybrid interface model, which exposes the functionality of a dynamic linked library (DLL) module to both a user and the client executable system. The servers themselves are built using the Altium Designer API.

Client - Executable /Server - DLL paradigm
Client - Executable /Server - DLL paradigm

The Client executable is a standalone executable system that collaborates with loaded DLL servers within Altium Designer. The Client module controls the user interface and delegates tasks (sends commands) to appropriate servers, while servers (as dynamic linked library files) concentrate solely on providing specific functionality based on the Altium Designer commands invoked by the user.

Editor Server services

An editor server provides its services within Altium Designer. The DXP platform interprets the tasks in terms of commands and then delegates these commands to the appropriate server.

The server responds by activating its required functionality on the currently focused design document.


The server responds to the process by the Client module and acts on the current document.

For example, when a user clicks on the Schematic menu to place a wire, the system interprets this action as a Sch:PlaceWire command and delegates the command to the Schematic Editor.

The Schematic server responds by executing the command. The functionality of a server that is installed in Altium Designer is exposed by that server's processes and its exposed functions.

Main Altium Designer Servers

The Workspace Manager module is a system extensions server coupled tightly with the client module within Altium Designer. The Workspace Manager server deals with projects and their associated documents, and provides compiling, multi sheet design support, connectivity navigation tools, multi-channel support, multiple implementation documents and so on. It also manages output generators such as netlisters.

A project and its design documents in Altium Designer. A document can be represented by two ways - as seen by the Workspace Manager and as seen by the Editor (Server).
A project and its design documents in Altium Designer. A document can be represented by two ways - as seen by the Workspace Manager and as seen by the Editor (Server).

The Schematic server and PCB server are two main document editors which have their own document types (design and library documents).

Managing the locations of footprints or symbols from the library documents is performed by the Integrated Library server.

There are two representations of a design document in Altium Designer: projects and documents dealt with by the Workspace Manager, and the server documents dealt with by the associated servers (as shown in the above image).

Using the Altium Designer API in scripts

The scripting engine in Altium Designer supports PCB, Schematic and Workspace Manager APIs which enables you to write scripts that act on PCB or Schematic documents, or invoke one of the file management routines to massage the documents in a project.

Altium Designer API is automatically exposed to be used in scripts, so you can code API statements in the scripts with appropriate parameter values using one of the supported scripting languages. Altium Designer supports scripting languages such as EnableBasic, Visual Basic, Javascript and as well as commonly used DelphiScript (which is very much like Delphi). DelphiScript scripts are the most common scripts used in Altium Designer.

A DelphiScript Script which counts Pad Objects on a PCB document

Procedure PadCount;
Var
    Board     : IPCB_Board;
    Pad       : IPCB_Primitive;
    Iterator  : IPCB_BoardIterator;
    PadNumber : Integer;
Begin
    PadNumber       := 0;
    // Retrieve the current board
    Board := PCBServer.GetCurrentPCBBoard;
    If Board = Nil Then Exit;
    // retrieve the iterator
    Iterator        := Board.BoardIterator_Create;
    Iterator.AddFilter_ObjectSet(MkSet(ePadObject));
    Iterator.AddFilter_LayerSet(AllLayers);
    Iterator.AddFilter_Method(eProcessAll);
 
    // Search and count pads
    Pad := Iterator.FirstPCBObject;
    While (Pad <> Nil) Do
    Begin
        Inc(PadNumber);
        Pad := Iterator.NextPCBObject;
    End;
    Board.BoardIterator_Destroy(Iterator);
 
    // Display the count result on a dialog.
    ShowMessage('Pad Count = ' + IntToStr(PadNumber));
End;

VBScript Script which creates a new via object on a PCB document

Sub ViaCreation
    Dim  Board
    Dim  Via 
 
    Set Board = PCBServer.GetCurrentPCBBoard
    If Board is Nothing Then Exit Sub
 
    ' Create a Via object
    Via           = PCBServer.PCBObjectFactory(eViaObject, eNoDimension, eCreate_Default)
    Via.X         = MilsToCoord(7500)
    Via.Y         = MilsToCoord(7500)
    Via.Size      = MilsToCoord(50)
    Via.HoleSize  = MilsToCoord(20)
    Via.LowLayer  = eTopLayer
    Via.HighLayer = eBottomLayer
 
    ' Put this via in the Board object
    Board.AddPCBObject(Via)
End Sub

See the Overview & Setup of the Scripting System document for a scripting overview.
The downloadable Script Examples collection has a large number of examples that demonstrate how scripts with different API functions work within the Altium Designer framework.

Server development with the Altium Designer API

The Altium Designer scripting system implements a subset of the complete Altium Designer API and its Object Interfaces. The Altium DXP Developer, used for developing Altium Designer server Extensions, has access to the full Altium Designer API via a set of API SDK source units.

Using the Altium Designer Object Models

In Altium Designer, each API (such as the PCB API) has an Object Model and in turn, the object model is a hierarchical system of object interfaces. These object interfaces represent actual objects in the Altium Designer (such as the board, document, PCB objects etc).

An illustration of the relationship between objects in Altium Designer and the Object Interfaces supported by the Altium Designer API.
An illustration of the relationship between objects in Altium Designer and the Object Interfaces supported by the Altium Designer API.

The projects and the corresponding documents are managed by the Workspace Manager. As indicated in the above image, a project open in Altium Designer is represented by the IProject object interface, and the documents from this project are represented by the IDocument interfaces. Also:

  • The PCB documents and PCB design objects are managed by the PCB Editor and its PCB API.
  • The PCB document open in Altium Designer is represented by its IPCB_Board interface.
  • The pad objects and the track objects are represented by IPCB_Pad and IPCB_Track interfaces, respectively.

Object Interfaces

Object Interfaces are implementation independent declarations of functionality. From a developer’s perspective, there are high level object interfaces which encapsulate certain system objects in Altium Designer system such as IProject, IWorkSpace, IClient and IServerModule interfaces, which can be used to extract data for further processing by other servers.

Types of Altium Designer Object Interfaces

  • Client and Server Interfaces – needed for dealing with Server Documents and Client objects.
  • Workspace Manager Interfaces – needed for dealing with projects and documents.
  • Schematic Interfaces – needed for dealing with schematic objects
  • PCB Interfaces – needed for dealing with PCB objects
  • Integrated Library Interfaces – needed for dealing with library links and building model editors.
  • Other interfaces – such as the Output Generator interface.
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