where objectSet is a list of all object types that the user can select (think of it as a mask), layerSet is a list of all layers that objects can be selected on (yet again, a mask), and statusBarText is the text you want to display in the status bar while the user selects the objects.

The TObjectSet variable is normally made by calling the function MkSet(), which makes a set from the passed in object(s) (this only required when scripting in Delphi, as Delphi doesn’t natively support sets). The objects you can pass into MkSet() are part of the TObjectID enumeration and include:

Check That A PCB Board Is Selected

You commonly need to check that when a script is run, the active window is the right thing for the script to act on. The following code shows how to check if a PCB board file is loaded (.Pcb), and it feature at the start of lots of the other code examples. If a PCB board is not currently selected, the script quietly exits.

The Generate A Straight Section Of A Region

Use the following function to create a line segment and add it to a contour (which will be used once all the segments have been added to generate the region). Note that it is slightly simpler to add a line segment to a contour than an arc, basically because for a line all you have to do is define the start and end points.

contour.AddPoint(x : interger, y : integer);

How To Finally Add The Region To The PCB

Once you have defined a region by using the contour object, you can add it to the PCB with the following code. This assumes

To Update The PCB Window

Use the Client object to update the PCB window. This will update the PCB to show any changes that have been made to it by preceding code (it is not updated automatically). It is useful to call this at the end of a script to update the PCB and show the user the changes that have been made. If you don’t call this, the the user will only see the changes once this method is called by another process.

Undo

Make sure that you call PCBServer.PreProcess and PCBServer.PostProcess after doing any action that would change the PCB in anyway. If you are losing Undo functionality, it is likely due to the fact you are calling PreProcess without calling PostProcess. Essentially, any action done on the PCB between these two function calls is counted as one ‘Undo’. The code below shows how to use these two functions correctly.

Sub UsingUndoProperly()
PCBServer.PreProcess
' Put script code that changes the PCB here
' All of this will be one 'Undo'
PCBServer.PostProcess
PCBServer.PreProcess
' All PCB changes done here will be another 'Undo' operation
PCBServer.PostProcess
End Sub

You can get the following error when trying to save if you haven’t called PCBServer.PostProcess and equal number of times as PCBServer.PostProcess. So far, if this does occur, I haven’t worked out how to save the document (all changes since last save are lost!).

You might get this error in Altium when trying to save because you have run a script which hasn't called PSBServer.PostProcess an equal number of times as PCBServer.PostProcess.

Updating Component Links

You can open the “Edit Component Links” window by running the following commands (VBscript):

Zoom

PCB Layer Info

You can get the currently selected PCB layer with the code:

Board.CurrentLayer

On a valid IPCB_Board object.

You can use the LayerToString() and StringToLayer() functions to convert a PCB layer object into a human readable string and back again. For example, if the PCB was currently on the top copper layer, you could do the following:

ShowMessage(LayerToString(Board.CurrentLayer))
' This will display the current layer to the user, if say, the top
' copper layer was currently selected, it would display "Top Layer".

PCB Components

PCB Components have a child object called Name, which refers the the designator.

The Name Object

The confusing thing is, while the parameter Width refers to its width, the parameter Size refers to the designator height.