Using the Altium Designer API
Contents
Parent page: Altium Designer API
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:
- Using the Client and Server API
- Using the Schematic API
- Using the PCB API
- Using the WorkSpace Manager API
- Using the Integrated Library API
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.
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.
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.
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 A Tour 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).
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
andIPCB_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 and Nexar interfaces.