Created: June 06, 2016 | Updated: September 26, 2016
| Applies to versions: 3.1, 3.2, 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.
Please note that this documentation was last updated for an older version of Altium NEXUS. 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.
System API: Server Processes and Routines
Copy LinkCopied
The System API Server Processes Reference includes the following sections and content:
A server provides its services in the Altium NEXUS environment. The Client module within the Altium NEXUS interprets the tasks in terms of server processes and then delegates these processes to the appropriate servers.
For example when a user is clicking on the Schematic menu to place a wire, the Client module interprets this action as a 'PlaceWire' process and delegates the process to the Schematic Editor server. The Schematic server responds by executing the process. The functionality of a server that is installed in the Altium NEXUS is exposed by that server's processes and its exposed functions.
Generally a process is executed by selecting a command which is a packaged process launcher (such as clicking on a toolbar button, or pressing a hot key or selecting a menu item) in Altium NEXUS. Up to three different types of process launchers can be used to launch the same process.
You can manually run a process by going to the Run Process menu item in the System menu within
Server Processes
Each server process has a process identifier. The process identifier is made up of two parts separated by a colon. The first part of the process identifier indicates the server that defines the process, and the second part is the process name.
For example, the process Sch:ZoomIn is provided by the Schematic Editor server. When this process is launched, either by selecting a menu item, pressing a hot key or activating a toolbar button (which are all defined as process launchers in the Altium NEXUS), it will perform the task of zooming in on the currently active schematic sheet.
A process is implemented as a server name:server process name string. Processes are stored in a command launcher table maintained by the server. Every time you execute a process via the user interface, it consults the appropriate server’s command table to fetch the process string and then sends this string over to the server for the server to determine which process to execute. These processes are stored in corresponding server installation text files with an INS extension.
Parametric Processes
A parametric server process allows the information, a process needs, to be passed when the process is called. This ability to be able to pass process parameters allows direct control over the operation of a process. For parametric processes, each parameter has a value assigned and this parameter / value block is represented as Parameter = Name.
For example FileName = C:\Program Files\TestFile.Txt.
To concatenate several parameters as a whole string, each parameter / value block is separated by the pipe | symbol.
For example Parameter1 = Name1 | Parameter2 = Name 2 etc.
Manipulating Server Processes
Copy LinkCopied
There are server process functions and a TParameterList class in the parameters part of the Altium NEXUS API that do the manipulation of process strings much more easily.
TParameterList Class
Overview
The TParameterList class stores parameter name = value blocks separated by the Pipe symbols in a single null terminated string easily. For example, Orientation=1|Location.X=10000000|Location.Y=20000000 is a typical parameter string.
To add parameters in the TParameterlist object, you use one of the following SetState_AddParameterX methods. Normally the SetState_AddParameterAsString method is used in this case.
To retrieve a specially formatted null terminated string from the TParameterList object, you can invoke one of the GetState_ParameterX methods. The GetState_ToString or GetState_ParameterAsPChar methods are used in this case.
You create an instance of the TParameterList class and invoke the ClearAllParameters method to reset it.
TParameterList Methods
Constructor Create; Destructor Destroy; Override;
SetState_FromString and GetState_ToString methods
Procedure SetState_FromString (Const S : TDynamicString); Function GetState_ToString : TDynamicString;
Function GetState_ParameterAsString (Const Name : TDynamicString; Var Value : TDynamicString ) : Boolean; Overload; Function GetState_ParameterAsString (Const Name : TDynamicString; Var Value : TString ) : Boolean; Overload; Function GetState_ParameterAsPChar (Const Name : TDynamicString; Var Value : PChar ) : Boolean; Function GetState_ParameterAsLongInt (Const Name : TDynamicString; Var Value : LongInt) : Boolean; Function GetState_ParameterAsInteger (Const Name : TDynamicString; Var Value : Integer) : Boolean; Function GetState_ParameterAsInt64 (Const Name : TDynamicString; Var Value : Int64 ) : Boolean; Function GetState_ParameterAsSmallInt (Const Name : TDynamicString; Var Value : SmallInt) : Boolean; Function GetState_ParameterAsWord (Const Name : TDynamicString; Var Value : Word ) : Boolean; Function GetState_ParameterAsBoolean (Const Name : TDynamicString; Var Value : Boolean) : Boolean; Function GetState_ParameterAsWordBool (Const Name : TDynamicString; Var Value : WordBool) : Boolean; Function GetState_ParameterAsReal (Const Name : TDynamicString; Var Value : Single ) : Boolean; Function GetState_ParameterAsDouble (Const Name : TDynamicString; Var Value : Double) : Boolean;
Other methods
Function GetState_ParameterByName (Const AName : TDynamicString) : TParameter; Function SetState_RemoveByName (Const AName : TDynamicString) : Boolean; Procedure ClearAllParameters; Procedure SetState(P : PChar); Procedure GetState(P : PChar); Scripting Notes
In Scripting, we can only use the following methods SetState_FromString (Const S : TDynamicString); and GetState_ToString to process strings. The SetState and GetState methods cause problems in the scripting engine.
Function GetState_Parameter (P : PChar; Const Name : TString; Var Value : TString) : Boolean; Overload; Function GetState_Parameter (P : PChar; Const Name : TDynamicString; Var Value : TDynamicString) : Boolean; Overload; Procedure SetState_RemoveParameter(P : PChar; Const Name : TDynamicString); Overload; Function GetState_ParameterPChar (P : PChar; Const Name : TDynamicString; Value : PChar) : Boolean; Procedure SetState_ParameterPChar (P : PChar; Const Name : TDynamicString; Value : PChar); Procedure SetState_Parameter (P : PChar; Const Name : TDynamicString; Const Value : TDynamicString); Overload; Function GetState_Parameter (Const S : TDynamicString; Const Name : TDynamicString; Var Value : TDynamicString) : Boolean; Overload; Procedure SetState_Parameter (Var S : TDynamicString; Const Name : TDynamicString; Const Value : TDynamicString); Overload; Procedure SetState_RemoveParameter(Var S : TDynamicString; Const Name : TDynamicString); Overload;
Server Routines from ClientApiReg
Copy LinkCopied
The server process routines are defined in the ClientApiReg part of the Altium NEXUS API.
There are two ways you can execute a process in a script
To execute a server process in a script, you need to use commands such as ResetParameters and RunProcess procedures or invoke the Client.SendMessage function.
Client.SendMessage Example Client.SendMessage('WorkspaceManager:OpenObject','OpenMode=NewFromTemplate | ObjectKind=Project',1024,Nil); See also
Process Parameters Reference online help
Process Examples in \Examples\Scripts\Delphiscript Scripts\Processes\ folder.
AddWordParameter
Declaration Procedure AddWordParameter(Const Name: String; Value: Word); Description
The AddWordParameter procedure defines a parameter with a Word data type to the parameter buffer for use by a server process. Example
Declaration Procedure AddColorParameter(Const Name: String; Red: Integer; Green: Integer; Blue: Integer); Description
This procedure adds a color value parameter to the parameter buffer in Altium NEXUS. This procedure is used to define a color for use by a process that requires a color parameter.
The Color is a value where value = RedVal + 256*(GreenVal + 256*BlueVal) and Name is the name representing this color value. See also
Server Process routines
AddIntegerParameter
Declaration Procedure AddIntegerParameter(Const Name: String; Value: Integer); Description
The AddIntegerParameter procedure defines a parameter with an Integer data type to the parameter buffer for use by a server process. Example
Declaration Procedure AddLongIntParameter(Const Name: String; Value: LongInt); Description
The AddLongIntParameter procedure defines a parameter with a longint data type to the parameter buffer for use by a server process. Example
Declaration Procedure AddSingleParameter(Const Name: String; Value: Single); Description
The AddLongIntParameter procedure defines a parameter with a single data type to the parameter buffer for use by a server process. Example
Declaration Procedure AddStringParameter(Const Name, Value: String); Description
This procedure adds a parameter with a string value to the parameter buffer. The Name parameter represents the name of the process parameter and the Value parameter represents the value of the process parameter. Example
Declaration Procedure GetColorParameter(Const Name: String; Var Red: Integer; Var Green: Integer; Var Blue: Integer); Description
The GetColorParameter procedure retrieves the values of a color parameter as RGB values from the parameter buffer after running a process that returns a color value. See also
Server Process routines
GetIntegerParameter
Declaration Procedure GetIntegerParameter(Const Name: String; Var Value: Integer); Description
The GetIntegerParameter procedure retrieves the value of an integer type parameter from the parameter buffer. This procedure after a process has been executed can return a resultant word value. Example
Declaration Procedure GetLongIntParameter(Const Name: String; Var Value: LongInt); Description
The GetLongIntParameter procedure retrieves the value of a long int type parameter from the parameter buffer. This procedure after a process has been executed can return a resultant long int type value. See also
Server Process routines
GetSingleParameter
Declaration Procedure GetSingleParameter(Const Name: String; Var Value: Single); Description
The GetSingleParameter procedure retrieves the value of a single type parameter from the parameter buffer. This procedure after a process has been executed can return a resultant single type value. See also
Server Process routines
GetStringParameter
Declaration Procedure GetStringParameter(Const Name: String; Var Value: String); Description
The GetSingleParameter procedure retrieves the value of a string type parameter from the parameter buffer. This procedure after a process has been executed can return a resultant string type value. Example
Declaration Procedure GetWordParameter(Const Name: String; Var Value: Word); Description
The GetWordParameter procedure retrieves the value of a word type parameter from the parameter buffer. This procedure after a process has been executed can return a resultant integer value. See also
Server Process routines
ResetParameters
Declaration Procedure ResetParameters; Description
The ResetParameters procedure clears the parameter buffer. Execute the procedure to reset the parameter buffer before setting parameters used by a process in your script or server project.
When you use any of the Add...Parameter procedures, the parameter declared is appended to the parameter buffer. When you run a process, any parameters that need to be passed to the process are read from the parameter buffer.
Running a process, however, DOES NOT clear the parameter buffer. Therefore, it is important to use the ResetParameters procedure to clear the buffer of old values before placing a new series of parameters into the buffer. Example
Declaration Procedure RunProcess(Const Command: String); Description
The RunProcess procedure allows you to execute a server process. If the process invoked by this extension requires parameters to be passed to it, you must add the parameters to the parameter buffer using the AddXXXParameter functions before running the process.
If the process returns values, these will be placed in the return buffer and can be read using the GetXXXParameter functions. Server: Process format
The Command string takes on the following form: Server:Process
where Server is the name of the server the process is supplied by, and Process is the command name of the process. An example is PCB:Zoom. Client Process example
Helper Functions and Objects for the Scripting System
Copy LinkCopied
The Scripting System has provided a few Helper objects which are to help simplify your scripting tasks especially with creating and managing lists of strings or objects.
Useful functions:
CopyFile
Useful classes:
TStringList
TList
TIniFile
Many routines and objects from the Borland Delphi's Run Time Library cannot be used in the scripting system because the scripting system cannot support Int64 type parameters.
For example the TStream and its descendant classes cannot be used in the scripting system because many of the methods use the Int64 parameter type. The other limitations are that you cannot define classes or records because the scripting system is typeless.
CopyFile function
Declaration
The CopyFile function copies a file specified by the original filename to a new file with the new filename. The function returns a true value if the CopyFile fuhnction is successful otherwise a false value is returned.
The FailIfExists parameter controls how an existing target file can be overrwritten or not with the new source file by the CopyFile function.
If this parameter is TRUE and the new file already exists, the function fails.
If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.
Syntax Function CopyFile(SourceFileName, TargetFilename : PChar; FailIfExists : Boolean) : Boolean; DelphiScript Example
The TIniFile object (derived from Borland Delphi's TIniFile class) stores and retrieves application-specific information and settings from a text file with an INI extension. When you instantiate the TIniFile object, you pass as a parameter to the TIniFile's constructor, the filename of the INI file. If the file does not exist, the ini file is created automatically.
You then can read values using ReadString, ReadInteger, or ReadBool methods. Alternatively, if you want to read an entire section of the INI file, you can use the ReadSection method. As well, you can write values using WriteBool, WriteInteger, or WriteString methods.
Each of the Read routines takes three parameters. The first parameter identifies the section of the INI file. The second parameter identifies the value you want to read, and the third is a default value in case the section or value doesn't exist in the INI file. Similarly, the Write routines will create the section and/or value if they do not exist.
Script example
See at the end of this page the example code which creates an INI file. TIniFile Methods DeleteKey(const Section, Ident: String); EraseSection(const Section: String); ReadSection (const Section: String; Strings: TStrings); ReadSections(Strings: TStrings); ReadSectionValues(const Section: String; Strings: TStrings); ReadString(const Section, Ident, Default: String): String; WriteString(const Section, Ident, Value: String); UpdateFile;
//The following code adds an object to TheList container if the object is not in the list.
2
Begin
3
IfTheList.IndexOf(AnObject)=-1Then
4
TheList.Add(AnObject);
5
// do something
6
TheList.Remove(AnObject);
7
End;
See also
Helper Classes and Functions
TStringList object
The TStringList object maintains a list of strings. You can create an instance of a TStringList object and you can add, sort or delete individual strings from this object in your script.
If you need to do a customized sorting of the TStringList container, you need to write your own sorting routine. See examples below.
// The Find method will only work on sorted lists.
14
IfStringsList.Find('Resistor', Index) then
15
Begin
16
ListBox.Items.AddStrings(StringsList);
17
Label.Caption := 'Antennas has an index value of '+ IntToStr(Index);
18
End;
19
Finally
20
StringsList.Free;
21
End;
22
End;
23
End;
Example of a customized sorting routine
Refer to the Netlister script example in the \Examples\Scripts\WSM\ folder of the Altium NEXUS installation. See also
Helper Classes and Functions
If you find an issue, select the text/image and pressCtrl + Enterto send us your feedback.