Created: January 09, 2020 | Updated: July 21, 2021
| Applies to versions: 4 and 5
Nexus message
This documentation page references Altium NEXUS/NEXUS Client (part of the deployed NEXUS solution), which has been discontinued. All your PCB design, data management and collaboration needs can now be delivered by Altium Designer and a connected Altium 365 Workspace. Check out the FAQs page for more information.
This reference describes the VisualBasic Scripting language used to create scripts in Altium NEXUS. It provides details of the VisualBasic Scripting statements, functions, and extensions that are supported in the scripting system.
The Visual Basic Scripting (or VBScript for short) can be used to create scripts that deal with Altium NEXUS Object Models and Visual Components. In this reference, it's assumed that you are familiar with basic programming concepts and the basic operation of Altium NEXUS.
The Altium NEXUS scripting system supports the VBScript language (along with other scripting languages) which is derived from the Microsoft ActiveX Scripting system. So for instance, you should be able to use CScripts or WScripts which are based on the same ActiveX scripting engine that is used in Altium NEXUS.
All scripting languages supported in Altium NEXUS are typeless or untyped, which means that a script cannot define records or classes and pass pointers as parameters to functions.
The Scripting system supports a subset of the Embarcadero Delphi Run Time Library (RTL) and the Altium NEXUS API.
VBScripts scripts can access several Object Models in Altium NEXUS. For example, the PCB Object Model can be used in VBScripts to deal with PCB objects on a PCB document, or the Workspace Manager Object Model to work with Projects and their documents to extract netlist data.
The Scripting Reference contains information on interfaces with respect to Altium NEXUS Object Models, components, global routines, types, and variables that make up this scripting language. Consult the Microsoft Visual Basic documentation for more information on VBScript functions.
Server Processes
A script can be used to execute server processes, which represent commands in Altium NEXUS.
VBScript Source Files
Copy LinkCopied
A VBScript project is organized to store script documents (script units and script forms). A script can be executed from a menu item, toolbar button, or from the Run Script dialog from the system menu.
PRJSCR, VBS, and DFM files
Scripts are organized into projects with a *.PRJSCR extension. Each VBScript project consists of files with a *.vbs extension. Files can be either script units or script forms — each form has a VBScript script file with *.vbs extension and a corresponding form with a *.dfm extension). A script form is a graphical window (dialog) that hosts different controls that run on top of Altium NEXUS.
It is possible to attach scripts to different projects, and it's highly recommended to organize scripts into different projects to manage the number of scripts and their procedures/functions. Scripts (script units and script forms) consist of functions/procedures that can be called within Altium NEXUS.
VBScript Examples
Copy LinkCopied
The simple examples included in this reference illustrate the basic features of VBScript programming in Altium NEXUS.
For more VBScript examples see the ..\VBScripts folder in the downloadable example scripts collection for Altium NEXUS.
The VBScripts can use script forms, script units, functions, and objects from the Altium NEXUS scripting API, and a subset of functions and objects from the Embarcadero Delphi RTL that are exposed in the scripting system.
Writing VBScript Scripts
Copy LinkCopied
This section covers the basic concepts of writing VBScripts in Altium NEXUS.
VBScript Naming Conventions
VBScript variables are case insensitive — that is, variables in upper and lower case have the same meaning:
Since all scripts have local and global variables, it is important to have unique variable names in your scripts within a script project. If the variables are defined outside any subroutines and functions, they are global and can be accessed by any unit in the same project.
If variables are defined inside a routine, then these local variables are not accessible outside these routines. Since scripts are typeless, variables are not initialized with their types.
The local variables inside a procedure are automatically initialized.
VBScript allows two kinds of procedures; subroutines and functions — a function returns a value only. The syntax of calling a subroutine or function in a script is:
In VBScript, a procedure declaration normally has a list of parameters — note that variables are considered typeless and the scripting system works out automatically what the variable types are. The value used in place of the parameter when you make a procedure call is called an argument.
Note that the use of the Call keyword to invoke a subroutine or a function is optional (maintained for backward compatibility).
Comments in Scripts
In a script, comments are non-executed lines of code that are included for the benefit of the programmer. Comments can be included virtually anywhere in a script.
DocName = Document.Name ' Get name of active document
Splitting a Script Line
In VBScript, each code statement is terminated on the line (by a CR/LF combination) to indicate the end of the statement. VBScript allows you to write a statement on several lines of code, to split a long instruction over two or more lines, using the underscore character (_).
VBScript does not put any practical limit on the length of a single line of code in a script. However, for the sake of readability and ease of debugging, it is good practice to limit the length of code lines so that they can easily be read on-screen or in printed form. If a line of code is very long it can be broken into multiple lines, and this code will be treated by the VB interpreter as if it were written on a single line.
Unformatted code example
1
IfNot(PcbApi_ChooseRectangleByCorners(BoardHandle,"Choose first corner","Choose final corner",x1,y1,x2,y2)) ThenEndIf
The biggest feature of the scripting system is that the Interfaces of Altium NEXUS objects (Object Interfaces) are available to use in VBScripts. For example, you can update design objects on Schematic and PCB documents through the use of Schematic Interfaces and PCB interfaces respectively.
The Altium NEXUS Object Interfaces are available for use in any script. Normally in scripts, there is no need to instantiate an interface. The interface representing an existing Altium NEXUS object is extracted, and from this interface, the embedded or aggregate interface objects can be extracted to get or set their property values.
To access a PCB document and its data objects, you first invoke the PCBServer function. By convention, interface names are prefixed by an I character — for example, IPCB_Board represents an interface for an existing PCB document in Altium NEXUS.
The scripting system supports the VBScript language which is derived from the Microsoft Active Scripting language technology. The reserved words VBScript are:
A, B Abs, Array, Asc, Atn C Call, Case, CBool, CByte, CCur, CDate, CDbl, Chr, CInt, Class, CLng, Const, Conversions, Cos, CreateObject, CSng, CStr D, E DateAdd, DateDiff, DatePart, DateSerial, DateValue, Day, Derived Math, Dim, Do, Each, Erase, Escape, Empty, Eval, Execute, Exit, Exp F, G, H False, Filter, For, FormatCurrency, FormatDateTime, FormatNumber, FormatPercent, Function GetLocale, GetObject, GetRef, Hex, Hour I, L, M If, Is, InputBox, Instr, InStrRev, Int, IsArray, IsDate, IsEmpty, IsNull, IsNumeric, IsObject, Join, LBound, LCase, Left, Len, LoadPicture, Log, LTrim, Maths, Mid, MInute, Month, MonthName, MsgBox N, O Next, Nothing, Now, Null, Oct, On Error P, R Private, Property, Public, Randomize, ReDim, Rem, RTrim, Replace, RGB, Right, Rnd, Round S, T ScriptEngine, ScriptEngineBuildVersion, ScriptEngineMajorVersion, ScriptEngineMinorVersion, Second, Select, Set, SetLocale, Sgn, Sin, Space, Split, Sqr, Stop, StrComp, String, StrReverse, Sub, Tan, Then, Time, Timer, Timeserial, TimeValue, Trim, True, TypeName U, V, W, X, Y UCase, Unescape, While, Wend, With, VarType, Weekday, WeekdayName, Year
If you find an issue, select the text/image and pressCtrl + Enterto send us your feedback.