Welcome

Navigation: Home <Root level>

Welcome

CNCLINK Script Designer

From CNC & Computer Applications for creating scripts for CNCLINK Script Designer.

For latest information and downloads visit www.cnclink.co.uk

Copyright © 2015 i-Logic Software


DNC Scripting

DNC Scripting

Scripting

Three kinds of scripts:

1. Input and Output scripts that are run for every line of text that is received or sent.

2. Send and Receive scripts that are run once every time the Send or Receive button is pressed.

3. Utility scripts that are run from the main menu.

Sometimes the CNC machine does not download the program in exactly the right format that one would like and its necessary to make changes before or afterwards. CNCLINK Script Designer has the ability to perform changes to the text during upload and download. It can change the line that comes through the serial port before it is put in the edit window, and it can change the line before it is sent out through the serial port from the edit window. This allows for any custom format changes to the text that are required by the CNC machine.

This is accomplished through a script that is run for every line of text that is uploaded or downloaded.

In DNC Settings there are tabs for both an Input filter and Output filter script.

For instance:
You are drip feeding a long program and want block numbers in the display of the program in the main window as it is sending, so you know where you are.
But the program is so long that the block numbers go beyond 4 digits, but the machine won't take block numbers beyond 4 digits.

Instead of having to take out all the block numbers from the file beforehand, you could strip them out before the line was sent to the control, and they would still remain in the program file.

How Scripts are Made

Scripts for use in CNCLINK Script Designer are made with the i-Logic Script Designer, available at www.cnclink.co.uk. The Script Designer outputs pre-compiled script files. You then put the filename of the pre-compiled script in the CNCLINK Script Designer settings. See the help file that comes with the Script Designer for information.

Filter Script File

Filter scripts are scripts that operate on every line that is received or sent through the serial port. These scripts would normally be used for processing each line and looking for something and changing it before it is sent along. You have a separate filter file for input and output. These file names are saved for each machine configuration, so you can have different ones for each machine. Use the button to browse for files. The file extension for filter files is ".pcu".

Scripts for the Send and Receive Buttons

Besides a setting for the Input and Output filters, there are places for Send and Receive scripts that are attached to the Send and Receive Buttons. The Send script will run once when you press the Send button and the Receive script will run once when you press the Receive button. These can be handy for executing another Windows program or adding a wait period before the button action.

Scripts on the Main Menu

You can put up to 10 utilities under the File menu. These can either be Windows executable files or Scripts.

You can add a script by opening the DNCUtilities.ini file and adding another entry:

Utility 3 is a script.

[Utilities]

Utility1=Setup Sheet,C:\Program Files\i-logic\inlist\inlist.exe,2

Utility2=Notepad,c:\windows\notepad.exe,2

Utility3=Renumber,C:\Users\Douglas\Documents\Embarcadero\Studio\Projects\DNCScriptDesigner\Renumber.pcu

You could have scripts that act on the text in the editor like renumber, add spaces, reformat etc.

Scripts in Basic or Pascal

You have the choice of writing your scripts in the BASIC lanuage or the Pascal Language. The language of the file is set when you first create a new unit. When you press "New Project" or "New Unit" a dialog will ask which kind. You can change which one you want in the Settings dialog. BASIC scripts will be saved with ".bsc" file extension and Pascal files will be saved with the ".psc" extension. When you load an existing file in the designer to execute, this is how it determins which syntax to use and check.

Compiling Your Scripts for Use in DNC Server

You have to compile your scripts befoare they can be used in DNC Server. When you are finished debugging the script in the designer, go to Main Menu - Save Compiled File. It must have ".pcu" file extension. Then you can enter that filename into DNC Server - Configuration - Scripts.

Projects and Units

A Unit is one file that you can write a script. Normally, most scripts are going to be short that will be in one unit, so you will just start with the New Unit button. A New Project is a collection of multiple units. If you press the New Project button it will automatically create a main unit and a second unit that has a form. This project is meant to have a form for user interaction that you have buttons, edit boxes, etc. on. This will only be good for involved scripts that get user interaction and input. You can have multiple units where a second unit has a lot of procedures and function which are called by the main unit. You can have multiple forms too.


Script Functions

Script Functions

Script Functions

Besides all of the standard BASIC functions, there are specialized functions that would be used for CNC program editing.

Functions

Most of these functions skip anything in the comments. You need to set the comment characters in Settings - General to skip the comments in the CNC program.

Built-in CNC Functions

front(string)

Will add a string to the front of the line.

remove(string)

Will remove the address and its value from the line.

rear(string)

Will add a string to the back of the line.

addspaces

Separates all the addresses on the line with spaces. Operates on selected lines. If not multiple lines selected, operates on current line. Ignores comments

stripcomment

Removes the comment from the line. Looks for the comment characters that are in listed in the Settings pages. Comment character is '(' unless other character is given in Configuration - Comments. Operates on selected lines. If not multiple lines selected, operates on current line.

stripspaces

Removes any spaces in the line. Ignores comments. Operates on selected lines. If not multiple lines selected, operates on current line.

addline(string)

Adds line to end of editor.

insertline(string)

Inserts a line above the current editor line.

islastline

In sending mode, returns true if last line is about to be sent. In receiving mode, returns true when the end of file indicator has been received.

In receiving mode, the cnc control has probably already shut down the connection when this is true, so cannot be used to output to control.

IsLastLine and IsFirstLine are for use in filters. For checking for last line in Utility script use LineCount.

isfirstline

In sending mode, returns true when the first line is to be sent. In receiving mode, returns true when the first line has been received.

getioline

Retrieves the next line that is received from the serial port.

setioline(string)

Sets the current received or sent lone from the serial port.

setline(index,string)

Sets a line in the editor.

changev(address, oldvalue,newvalue, format)

Changes the value of an address. If the value of the address equals oldvalue then it will be changed to newvalue. It goes by the numeric value not the string value. So it will recognize X1.00, X1., X01.000 as the same value.

format=0 // normal
format=1=* 'X* //change all oldvalues of that address to newvalueformat
format=2=< //change any number thats less than oldvalue
format=3=> //change any number thats more than oldvalue
format=4= same as 0 but also looks in comments
format=5= just reformats same number
format=+100 // outputs no decimal - one place
format=+200 // outputs no decimal - two places
format=+300 // outputs no decimal - three places
format=+400 // outputs no decimal - four places
format=+900 // outputs no decimal - zero places

replacevalue(address,value)

If line has this address the value is replaced with this value.

hasaddress(address)

hasaddress will return true if the address is in current line in editor.

stop(string)

Stops outputting the file to the serial port at the current line.
Pressing "Abort" will end sending and receiving. Pressing Ignore will continue.
String is for message box display.

offset(address,value)

If address exists, it will be increased by value. You can subtract by using minus number.

scale(address,value)

If address exists, it will be multiplied by value.

saveprint(filename)

Since the print function does not have any window to print to, it saves the output in a buffer that can be saved to a file.

clearprint

Clears the Print buffer.

sendxon

Send the XON character out the serial port.

sendxoff

Send the XOFF character out the serial port.

Global variables

For a Filter Script, normally all the variables you make in the script will only last for processing one line. If you need to save values over the whole file input or output, you can use the nine global variables. Named Global1 through Global9. You can set and retrieve the values like other variables. These variables are set to 0 or empty each time Sending or Receiving is activated.

currentline

Returns the text of the editor line that the caret in on.

setcurrentline(string)

Sets the text line of the editor that the caret is on.

getline(index)

Returns the text line of the editor at this line number

setline(index,string)

Sets the text line of the editor at this index

linecount

Returns the number of lines in the editor

gotoline(index)

Current line in editor jumps to this line number

currentlinenum

Returns the line number of the current line

cancel

Like pressing the Cancel/Clear button. Stops any sending and clears editor. In AutoServe mode, goes back into waiting for command.

output(string)

Sends a string of characters out the serial port. Add end of line characters yourself.

sendfile(filename)

Opens a text file and outputs it through the serial port. With this you can insert another program file anywhere within the main file. The script is not performed on lines in the secondary file, only on the file in the edit window.

rotate(angle)

Rotates the line by the angle around X0,Y0. Only X,Y plane. Will change X,Y values. Will change I and J values also if present.

wait(millisecods)

This would stop all processing and wait for 5 seconds before the first line is sent..

punchleader(inches)

Output to the serial port empty characters. This is what you would use if you wanted to punch blank leader to a tape punch.

punchmanread(string)

Outputs man readable characters to a tape punch. You would use this if you wanted to put readable text at the beginning of a punched tape.

createfile(filename)

Creates an empty disk file. If it already exists, then it deletes the contents.

openfile(filename)

Opens a disk file for writing. The file must already exist.

writetofile(string)

Writes string to the file that has been opened with openfile(). Each write is one line in the file.

The procedure is always to:

1. use createfile() or openfile() to create new file or open existing file.

2. use writetofile() to add some text to the file.

3. use closefile to close the file.

closefile

Closes the file that was opened with openfile().

executefile(filename,param)

Runs an executable file. Parameters for the program are optional.

exceladd(row,col,string)

In a spreadsheet already open in Microsoft Excel, this will put the string in that cell.

excelget$(row,col)

In a spreadsheet already open in Microsoft Excel, this function will return the value in that cell as a string.

excelcolor(row,col,color)

In a spreadsheet already open in Microsoft Excel, this will change the color of that cell.
In Excel there are 57 colors numbered 0 to 56. For instance, 3=red; 4=green;

changes the cell to green

punch

Starts sending the text in the editor out the serial port. Bypasses any wait for signal settings.

getvalue(address)

Returns the value of this address in the current line. It only returns 0 if the address was found and contains 0. If the address was not found it returns -9999.9999

scriptreset

Stops the script.

getmachinename

Returns the current Machine Name.

note(string)

Shows text on the status line.

showmessage(string)

Shows a dialog box with text.

selectlines(startlinenum,endlinenum)

Selects the lines in the editor from startlinenumber to endlinenumber. Allows operation for those lines with some of the script functions.

String Operations

These functions work the same as their above counterparts, but operate on the given string parameter and return a string.

s=front_s(s,line)

s=remove(address,line)

s=rear(s,line)

s=stripspaces_s(line)

b=hasaddress_s(address)

s=offset_s(address,value,line)

s=scale_s(address,value,line)

s=rotate_s(angle,line)

x=getvalue(address,line)

s=replacevalue_s(address,value,line)

s=addspaces_s(line)

Adds spaces between addresses to a string parameter.

s=stripcomment_s(line)

Removes comment from string parameter.

s=stripspaces_s(line)

Removes spaces from string.

s=changev_s(address, oldvalue,newvalue, format, string)

Same as changev except operates on string parameter.

TriggerAutoSave(filename)

This does the Auto Save command in DNC Server just as if received the command during Receiving. This will set the current Filename and if in Auto Serve mode, will save the file after received.

DNCSetting(item,setting)

Other settings in DNC Server are possible with this command. Currently these two settings are implemented:

DNCSetting(1,1) will set Strip Blank Lines to ON.

DNCSetting(1,0) will set Strip Blank Lines to OFF.

DNCSetting(2,1) will set Select Start to ON.

DNCSetting(2,0) will set Select Start to OFF.

Basic Script Language

The scripting language is compatible with standard Visual Basic. Its compatible with most books and information on the Internet about the Basic Programming Language.

See more on the Language Reference here .

Note: With a large Input script It's possible that the extra processing may require a slower baud rate to be used to make sure that it is able to keep up with the incoming data - depending on the speed of the computer.

Excel Spreadsheet

You can output data to a cell in an Excel spreadsheet. Have Excel running and open to the sheet you want filled in. The excelladd command put the data into the cell at the row and column parameters.

Example script is performed for every incoming line to CNCLINK Script Designer:

' input script for probe

' get speadsheet row number

if hasaddress("C") then

rownum=getvalue("C")

end if

' then get values

if hasaddress("A") then

actual=getvalue("A")

end if

if hasaddress("E") then

errorval=getvalue("E")

end if

if hasaddress("N") then

nominal=getvalue("N")

end if

if hasaddress("T") then

tolerance=getvalue("T")

end if

exceladd(rownum,4,cstr(nominal))

exceladd(rownum,5,cstr(tolerance))

exceladd(rownum,6,cstr(actual))

exceladd(rownum,7,cstr(errorval))

(Whenever you restart Excel you have to restart CNCLINK Script Designer so it will be able to hook up to the sheet)

Silent Command

Method for silent DPRNT commands (only for receiving at CNCLINK Script Designer):
Any incoming line that starts with "///" three block skip characters will be able to be interpreted by the Input script, but wont show up in editor. If CNCLINK Script Designer is in AutoServe mode, it can be always listening for commands from the machine.

The machine could send data commands out to CNCLINK Script Designer which could interpret them with a script and execute files.
Example:
At machine: DPRNT[///END]

At CNCLINK Script Designer Input Script:

if mid(line,1,6)="///END" then

ExecuteFile("c:\MyProgram.exe","/M")

end if

Example:
At machine: DPRNT[///R[#2]C[#3]X[#4]]

if mid(Line,1,3)="///" then

row=getvalue("R")

col=getvalue("C")

x=getvalue("X")

xvalue=excelget(row,col)

x2=cdbl(xvalue)+x

exceladd(row,col+1,cstr(x2))

end if

Event Scripts

It is possible to put a script in a the Send or Receive event. In the DNC.INI file, under the machine name section, add "SendEvent=" and a script filename.

Example:

[Fanuc]

SendEvent=send.pcu

ReceiveEvent=receive.pcu

These scripts will be run when the Send or Receive button is pressed, or when Sending or Receiving is started automatically. For instance, with a script in the SendEvent, you could have a wait command before the sending was activated.


Basic Language

Basic Language

More Filter Script Info

This Basic Script supports Numbers and Strings.

Built-in Basic Functions

 | Numeric functions:
ABS(n) LN(n) EXP(n) RND INT(n) FIX(n) ROUND(n) FRAC(n) SQR(n) SGN(n) SIN(n) COS(n) ATN(n) ASC($) LEN($) | Absolute value Natural logarithm, base e Exponential Random number in the range 0..1 Integer part of n Integer part rounded toward zero Rounding of n Fractional part of n Square root Sign of n, +1 0 -1 Sine of number, radians Cosine Inverse tangent Ascii code of char Length of string

 | String functions:
LCASE($) UCASE($) LTRIM($) RTRIM($) CHR(n) CSTR(n) HEX(n) MID($,n,[n]) LEFT($,n) RIGHT($,n) INSTR($,substring) | Lowercase conversion Uppercase conversion Left blanks deletion Right blanks deletion Ascii to char conversion Number to string conversion Number to hexadecimal Substring extraction Left part of a string Right part of a string Returns position of substring

Reserved words

if
end
for
goto
local
print
end func

or
mod
not
step
while
input
end while

to
else
break
gosub
repeat
continue

and
rem
then
end if
until
return
function

Built-in CNC Functions

addspaces

addline
cancel
changev(address,oldvalue,newvalue,format)

clearprint
closefile
createfile(filename)

currentline
currentlinenum
executefile(filename,param)
exceladd(row,col,string)
excelget(row,col)

excelcolor(row,col,color)
isfirstline
front(string)
hasaddress(address)

getioline
getvalue(address)
getline(index)
gotoline(index)
insertline(string)
islastline
linecount
offset(address,value)
openfile(filename)
output(string)
punchleader(inches)
punchmanread(string)
remove(string)
rear(string)

replacevalue(address,value)
rotate(angle)
setcurrentline(string)
scale(address,value)
saveprint(filename)
sendxon
sendoff

setioline(string)
setline(index,string)
stop(string)
sendfile(filename)
stripcomment
stripspaces
wait(milliseconds)
writetofile(string)

Comments:

REM this is a comment
' and this is too
' but shorter

1# Example: (Pascal-like, recommended style)

for a = 1 to 10
print "Hello"
if a > 5 then break
next
print "the end"

Loop instructions

Basic Script supports three kinds of loop instructions.

For, While and Repeat.
The easiest way to understand a Loop instruction is to look at an example.
The following program prints the numbers 1 to 10, "a" is the control variable:

FOR a = 1 to 10
PRINT(a)
NEXT

FOR-NEXT instruction:
The complete syntax for this command is:

FOR <variable> = <expression> to <expression> [step <constant>]
...
...
NEXT [<variable> (ignored)]

examples:
FOR angle = 1 to 1 step 0.1
PRINT(angle)
NEXT

FOR y = 1 to 200
FOR x = 1 to 320
s = s + x*y
NEXT
NEXT

REPEAT-UNTIL instruction:
This instruction repeats a series of instructions until the condition is True. The block begins with the REPEAT command and ends with the UNTIL command followed by the condition that is evaluated.
Example:

a = 1
REPEAT
PRINT(a)
a = a+1
UNTIL a>10

The Repeat instruction evaluates the condition at the end of the loop, this means that the instructions inside the loop are executed at least once. The Break and Continue instructions can be used in REPEAT-UNTIL cycles just like in the FOR-NEXT cycles.

WHILE-ENDWHILE instruction:
This instruction evaluates a condition at the beginning of the loop. If the condition is false then the cycle stops and execution continues after the Endwhile instruction.
Example:

a = 1
WHILE a <= 10
PRINT(a)
a = a+1
END WHILE

Since the While command evaluates the condition at the beginning of the loop, the instructions inside the loop may be also executed never. The Break and Continue instructions can be used in WHILE-ENDWHILE cycles just like in the FOR-NEXT cycles.

Strings
A string variable contains text. This text may be a single row or a multi-line text. The maximum theoretical size of a string variable is 2 Gbyte.
Example:

a = "Hello" + "World" + "!"

The value of the variable "a" is now "HelloWorld!"
String variables are used with operators to perform string expressions and are used with some functions to Open and Save data from text files.

Numbers

A numeric variable contains a number. The number is internally represented by a floating point value with double precision (64 bit, 15 significant digits).

Numeric variables are used with operators to perform numeric expressions and are used as counters in loop instructions.

Basic functions

A function is defined as set of instructions that computes and returns a value.

The result can be discarded (like C and Delphi) or simply not returned, making it a procedure. Local variables can be defined to support recursive functions.

Syntax:

Function <Name> ( parameters ) [ Local <local variables> ]
...
[Return <result>]
...
End function

Examples:
FUNCTION sum(a,b)
return a+b
END FUNCTION

FUNCTION intpower(a,b) LOCAL t,r
r=1
for t = 1 to b
r = r * a
next
return r
END FUNCTION

FUNCTION hello$(a$)
return "Hello to you " + a$
END FUNCTION

Basic fully supports recursive functions, example:

FUNCTION factorial(n)
if n <= 1 then return 1
return n*factorial(n-1)
ENDFUNC

Conditional instructions

The IF-THEN instruction evaluates a logical expression and determines the flow of the program based on the result of that expression.

Examples of logical expressions:

a > 5 and b > 5
a >= 3 or not b <> 5 and b+3 = c

Precedence of operators:

Higher precedence:

< , > , <= , >= , <> , =
NOT
AND
OR

Lower precedence.

Syntax:

IF <logical expression> THEN
...
...
[ELSE]
...
...
END IF

IF a >= 0 THEN
print( a)
IF a = 12 THEN print( "A prefect number !")
IF a > 1000 THEN
print( "What a big number")
END IF
ELSE
print("Negative numbers not allowed!")
END IF

Identifiers

Identifiers denote variables and functions.
An identifier can be of any length, must begin with a letter and can't contain spaces.

examples of valid identifiers:

counter , temp , pix , n , n2
name , address2 , filename , a

PRINT

Since there is no window to print to in Filter Script, the print function prints to buffer that can be saved to a file.
See SavePrint function.

Print( expression )

Example:

PRINT ("Some math")

Operators

Operators are classified as arithmetic operators and string operators.

Precedence:
Operators with higher precedence are performed before operators with low precedence.
Operators with equal precedence are performed from left to right.

Numeric operators
Numeric operators apply in numeric expressions, Basic supports the following operators:

+
-
*
/
^
MOD

Addition
Subtraction
Multiplication
Division
Power
Modulo

Higher precedence:

- (unary)
^
* , / , MOD
+ , -

Lower precedence.

Examples:

12 + 15 = 27
12 - 4 = 8
2 ^ 8 = 256
7 * 5 = 35
10 / 4 = 2.5
18 MOD 8 = 2

String operators
String operators apply in string expressions, Basic supports the following operators:

+ Addition

Precedence:
String operators have the same precedence and are evaluated from left to right.
Examples:

"Hello" + "World" = "HelloWorld"

Basic syntax

BasicScripter component executes scripts written in Basic syntax. Current Basic syntax supports:

· sub .. end and function .. end declarations

· byref and dim directives

· if .. then .. else .. end constructor

· for .. to .. step .. next constructor

· do .. while .. loop and do .. loop .. while constructors

· do .. until .. loop and do .. loop .. until constructors

· ^ , * , / , and , + , - , or , <> , >=, <= , = , > , < , div , mod , xor , shl , shr operators

· try .. except and try .. finally blocks

· try .. catch .. end try and try .. finally .. end try blocks

· select case .. end select constructor

· array constructors (x:=[ 1, 2, 3 ];)

· exit statement

· access to object properties and methods ( ObjectName.SubObject.Property )

Script structure

Script structure is made of two major blocks: a) function and sub declarations and b) main block. Both

are optional, but at least one should be present in script. Some examples:

SCRIPT 1:

SUB DoSomething

CallSomething

END SUB

CallSomethingElse

SCRIPT 2:

CallSomethingElse

SCRIPT 3:

FUNCTION MyFunction

MyFunction = "Ok!"

END FUNCTION

Like in normal basic, statements in a single line can be separated by ":" character.

Identifiers

Identifier names in script (variable names, function and procedure names, etc.) follow the most

common rules in basic : should begin with a character (a..z or A..Z), or '_', and can be followed by

alphanumeric chars or '_' char. Cannot contain any other character os spaces.

Valid identifiers:

VarName

_Some

V1A2

_____Some____

Invalid identifiers:

2Var

My Name

Some-more

This,is,not,valid

Assign statements

Assign statements (assign a value or expression result to a variable or object property) are built using

"=". Examples:

MyVar = 2

Button.Caption = "This " + "is ok."

New statement

Scripter provides the "new" statement for Basic syntax. Since you don't provide the method name

in this statement, scripter looks for a method named "Create" in the specified class. If the method

doesn't exist, the statement fails. Example:

MyLabel = new TLabel(Form1)

MyFont = new TFont

In the above examples, a method named "Create" for TLabel and TFont class will be called. The

method must be registered. If the method receives parameters, you can pass the parameters in

parenthesis, like the TLabel example above.

Character strings

strings (sequence of characters) are declared in basic using double quote (") character. Some

examples:

A = "This is a text"

Str = "Text "+"concat"

Comments

Comments can be inserted inside script. You can use ' chars or REM. Comment will finish at the end of

line. Examples:

' This is a comment before ShowMessage

ShowMessage("Ok")

REM This is another comment

ShowMessage("More ok!")

' And this is a comment

' with two lines

ShowMessage("End of okays")

Variables

There is no need to declare variable types in script. Thus, you declare variable just using DIM directive

and its name. There is no need to declare variables if scripter property OptionExplicit is set to false. In

this case, variables are implicit declared. If you want to have more control over the script, set

OptionExplicit property to true. This will raise a compile error if variable is used but not declared in

script. Examples:

SCRIPT 1:

SUB Msg

DIM S

S = "Hello world!"

ShowMessage(S)

END SUB

SCRIPT 2:

DIM A

A = 0

A = A+1

ShowMessage(A)

Note that if script property OptionExplicit is set to false, then variable declarations are not necessary in

any of scripts above.

You can also declare global variables as private or public using the following syntax:

SCRIPT 2:

PRIVATE A

PUBLIC B

B = 0

A = B + 1

ShowMessage(A)

Variable declared with DIM statement are public by default. Private variables are not acessible from

other scripts.

Variables can be default initialized with the following syntax

DIM A = "Hello world"

DIM B As Integer = 5

Indexes

Strings, arrays and array properties can be indexed using "[" and "]" chars. For example, if Str is a

string variable, the expression Str[3] returns the third character in the string denoted by Str, while Str[I

+ 1] returns the character immediately after the one indexed by I.

More examples:

MyChar = MyStr[2]

MyStr[1] = "A"

MyArray[1,2] = 1530

Lines.Strings[2] = "Some text"

Arrays

Script support array constructors and support to variant arrays. To construct an array, use "[" and "]"

chars. You can construct multi-index array nesting array constructors. You can then access arrays

using indexes. If array is multi-index, separate indexes using ",".

If variable is a variant array, script automatically support indexing in that variable. A variable is a variant

array is it was assigned using an array constructor, if it is a direct reference to a Delphi variable which

is a variant array (see Delphi integration later) or if it was created using VarArrayCreate procedure.

Arrays in script are 0-based index. Some examples:

NewArray = [ 2,4,6,8 ]

Num = NewArray[1] //Num receives "4"

MultiArray = [ ["green","red","blue"] , ["apple","orange","lemon"] ]

Str = MultiArray[0,2] //Str receives 'blue'

MultiArray[1,1] = "new orange"

If statements

There are two forms of if statement: if...then..end if and the if...then...else..end if. Like normal basic, if

the if expression is true, the statements are executed. If there is else part and expression is false,

statements after else are executed. Examples:

IF J <> 0 THEN Result = I/J END IF

IF J = 0 THEN Exit ELSE Result = I/J END IF

IF J <> 0 THEN

Result = I/J

Count = Count + 1

ELSE

Done = True

END IF

If the IF statement is in a single line, you don't need to finish it with END IF:

IF J <> 0 THEN Result = I/J

IF J = 0 THEN Exit ELSE Result = I/J

while statements

A while statement is used to repeat statements, while a control condition (expression) is evaluated as

true. The control condition is evaluated before the statements. Hence, if the constrol condition is false

at first iteration, the statement sequence is never executed. The while statement executes its

constituent statement repeatedly, testing expression before each iteration. As long as expression

returns True, execution continues. Examples:

WHILE (Data[I] <> X) I = I + 1 END WHILE

WHILE (I > 0)

IF Odd(I) THEN Z = Z * X END IF

X = Sqr(X)

END WHILE

WHILE (not Eof(InputFile))

Readln(InputFile, Line)

Process(Line)

END WHILE

loop statements

Scripter support loop statements. The possible syntax are:

DO WHILE expr statements LOOP

DO UNTIL expr statements LOOP

DO statements LOOP WHILE expr

DO statement LOOP UNTIL expr

statements will be execute WHILE expr is true, or UNTIL expr is true. if expr is before statements, then

the control condition will be tested before iteration. Otherwise, control condition will be tested after

iteration. Examples:

DO

K = I mod J

I = J

J = K

LOOP UNTIL J = 0

DO UNTIL I >= 0

Write("Enter a value (0..9): ")

Readln(I)

LOOP

DO

K = I mod J

I = J

J = K

LOOP WHILE J <> 0

DO WHILE I < 0

Write("Enter a value (0..9): ")

Readln(I)

LOOP

for statements

Scripter support for statements with the following syntax: FOR counter = initialValue TO finalValue

STEP stepValue statements NEXT. For statement set counter to initialValue, repeats execution of

statement until "next" and increment value of counter by stepValue, until counter reachs finalValue.

Step part is optional, and if omitted stepValue is considered 1.

Examples:

SCRIPT 1:

FOR c = 1 TO 10 STEP 2

a = a + c

NEXT

SCRIPT 2:

FOR I = a TO b

j = i ^ 2

sum = sum + j

NEXT

select case statements

Scripter support select case statements with following syntax:

SELECT CASE selectorExpression

CASE caseexpr1

statement1

…

CASE caseexprn

statementn

CASE ELSE

elsestatement

END SELECT

if selectorExpression matches the result of one of caseexprn expressions, the respective statements

will be execute. Otherwise, elsestatement will be executed. Else part of case statement is optional.

Example:

SELECT CASE uppercase(Fruit)

CASE "lime" ShowMessage("green")

CASE "orange"

ShowMessage("orange")

CASE "apple" ShowMessage("red")

CASE ELSE

ShowMessage("black")

END SELECT

function and sub declaration

Declaration of functions and subs are similar to basic. In functions to return function values, use

implicited declared variable which has the same name of the function, or use Return statement.

Parameters by reference can also be used, using BYREF directive.

Some examples:

SUB HelloWord

ShowMessage("Hello world!")

END SUB

SUB UpcaseMessage(Msg)

ShowMessage(Uppercase(Msg))

END SUB

FUNCTION TodayAsString

TodayAsString = DateToStr(Date)

END FUNCTION

FUNCTION Max(A,B)

IF A>B THEN

MAX = A

ELSE

MAX = B

END IF

END FUNCTION

SUB SwapValues(BYREF A, B)

DIM TEMP

TEMP = A

A = B

B = TEMP

END SUB

You can also declare subs and functions as private or public using the following syntax:

PRIVATE SUB Hello

END SUB

PUBLIC FUNCTION Hello

END FUNCTION

Subs and functions are public by default. Private subs and functions are not acessible from other

scripts.

You can use Return statement to exit subs and functions. For functions, you can also return a valid

value.

Examples:

SUB UpcaseMessage(Msg)

ShowMessage(Uppercase(Msg))

Return

' This line will be never reached

ShowMessage("never displayed")

END SUB

FUNCTION TodayAsString

Return DateToStr(Date)

END FUNCTION

Calling dll functions

Overview

Scripter allows importing and calling external DLL functions, by inserting special directives on

declaration of script routines, indicating library name and, optionally, the calling convention, beyond the

function signature.

External libraries are loaded by Scripter on demand, before function calls, if not loaded yet (dynamically

or statically). To load and unload libraries explicitly, functions LoadLibary and FreeLibrary from unit

Windows can be used.

Note: to enable DLL function calls, you must set AllowDLLCalls property to true.

function lib 'libName.dll' [alias ExternalFunctionName] [callingConvention]

functionName(arguments) as resultType;

For example, the following declaration:

function lib "CustomLib.dll" MyFunction(arg as integer) as integer

imports a function called MyFunction from CustomLib.dll. Default calling convention, if not specified, is

stdcall. Scripter also allows to declare a different calling convention (stdcall, register, pascal, cdecl or

safecall) and to use a different name for DLL function, like the following declaration:

function MessageBox lib "User32.dll" alias "MessageBoxA" stdcall (hwnd as pointer,

text as string, caption as string, msgtype as integer) as integer

that imports 'MessageBoxA' function from User32.dll (Windows API library), named 'MessageBox' to

be used in script.

Declaration above can be used to functions and subs (routines without result value).

Basic Language functions

Asc

Atn

CBool

CByte

CCur

CDate

CDbl

Cint

CLng

CreateObject

CSng

CStr

DatePart

DateSerial

DateValue

Day

Fix

FormatCurrency

FormatDateTime

FormatNumber

Hex

Hour

InputBox

InStr

Int

IsArray

IsDate

IsEmpty

IsNull

IsNumeric

LBound

LCase

Left

Len

Log

LTrim

Mid

Minute

Month

MonthName

MsgBox

Replace

Right

Rnd

RTrim

Second

Sgn

Space

StrComp

String

Timer

TimeSerial

TimeValue

UBound

UCase

Weekday

WeekdayName

Year

Functions listed on Pascal System Functions can also be used in Basic Language


Pascal Language

Pascal Language

Pascal syntax

Overview

PascalScripter component executes scripts written in Pascal syntax. Current Pascal syntax

supports:

· begin .. end constructor

· procedure and function declarations

· if .. then .. else constructor

· for .. to .. do .. step constructor

· while .. do constructor

· repeat .. until constructor

· try .. except and try .. finally blocks

· case statements

· array constructors (x:=[ 1, 2, 3 ];)

· ^ , * , / , and , + , - , or , <> , >=, <= , = , > , < , div , mod , xor , shl , shr operators

· access to object properties and methods ( ObjectName.SubObject.Property )

Script structure

Script structure is made of two major blocks: a) procedure and function declarations and b) main block.

Both are optional, but at least one should be present in script. There is no need for main block to be

inside begin..end. It could be a single statement. Some examples:

SCRIPT 1:

procedure DoSomething;

begin

CallSomething;

end;

begin

CallSomethingElse;

end;

SCRIPT 2:

begin

CallSomethingElse;

end;

SCRIPT 3:

function MyFunction;

begin

result:='Ok!';

end;

SCRIPT 4:

CallSomethingElse;

Like in pascal, statements should be terminated by ";" character. Begin..end blocks are allowed to

group statements.

Identifiers

Identifier names in script (variable names, function and procedure names, etc.) follow the most

common rules in pascal : should begin with a character (a..z or A..Z), or '_', and can be followed by

alphanumeric chars or '_' char. Cannot contain any other character os spaces.

Valid identifiers:

VarName

_Some

V1A2

_____Some____

Invalid identifiers:

2Var

My Name

Some-more

This,is,not,valid

Assign statements

Just like in Pascal, assign statements (assign a value or expression result to a variable or object

property) are built using ":=". Examples:

MyVar := 2;

Button.Caption := 'This ' + 'is ok.';

Character strings

Strings (sequence of characters) are declared in pascal using single quote (') character. Double quotes

(") are not used. You can also use #nn to declare a character inside a string. There is no need to use

'+' operator to add a character to a string. Some examples:

A := 'This is a text';

Str := 'Text '+'concat';

B := 'String with CR and LF char at the end'#13#10;

C := 'String with '#33#34' characters in the middle';

Comments

Comments can be inserted inside script. You can use // chars or (* *) or { } blocks. Using // char the

comment will finish at the end of line.

//This is a comment before ShowMessage

ShowMessage('Ok');

(* This is another comment *)

ShowMessage('More ok!');

{ And this is a comment

with two lines }

ShowMessage('End of okays');

Variables

There is no need to declare variable types in script. Thus, you declare variable just using var directive

and its name. There is no need to declare variables if scripter property OptionExplicit is set to false. In

this case, variables are implicit declared. If you want to have more control over the script, set

OptionExplicit property to true. This will raise a compile error if variable is used but not declared in

script. Examples:

SCRIPT 1:

procedure Msg;

var S;

begin

S:='Hello world!';

ShowMessage(S);

end;

SCRIPT 2:

var A;

begin

A:=0;

A:=A+1;

end;

SCRIPT 3:

var S: string;

begin

S:='Hello World!';

ShowMessage(S);

end;

Note that if script property OptionExplicit is set to false, then var declarations are not necessary in any

of scripts above.

Indexes

Strings, arrays and array properties can be indexed using "[" and "]" chars. For example, if Str is a

string variable, the expression Str[3] returns the third character in the string denoted by Str, while Str[I

+ 1] returns the character immediately after the one indexed by I. More examples:

MyChar:=MyStr[2];

MyStr[1]:='A';

MyArray[1,2]:=1530;

Lines.Strings[2]:='Some text';

Arrays

Script support array constructors and support to variant arrays. To construct an array, use "[" and "]"

chars. You can construct multi-index array nesting array constructors. You can then access arrays

using indexes. If array is multi-index, separate indexes using ",".

If variable is a variant array, script automatically support indexing in that variable. A variable is a variant

array is it was assigned using an array constructor, if it is a direct reference to a Delphi variable which

is a variant array (see Delphi integration later) or if it was created using VarArrayCreate procedure.

Arrays in script are 0-based index. Some examples:

NewArray := [ 2,4,6,8 ];

Num:=NewArray[1]; //Num receives "4"

MultiArray := [ ['green','red','blue'] , ['apple','orange','lemon'] ];

Str:=MultiArray[0,2]; //Str receives 'blue'

MultiArray[1,1]:='new orange';

If statements

There are two forms of if statement: if...then and the if...then...else. Like normal pascal, if the if

expression is true, the statement (or block) is executed. If there is else part and expression is false,

statement (or block) after else is execute.

Examples:

if J <> 0 then Result := I/J;

if J = 0 then Exit else Result := I/J;

if J <> 0 then

begin

Result := I/J;

Count := Count + 1;

end

else

Done := True;

while statements

A while statement is used to repeat a statement or a block, while a control condition (expression) is

evaluated as true. The control condition is evaluated before the statement. Hence, if the constrol

condition is false at first iteration, the statement sequence is never executed. The while statement

executes its constituent statement (or block) repeatedly, testing expression before each iteration. As

long as expression returns True, execution continues.

Examples:

while Data[I] <> X do I := I + 1;

while I > 0 do

begin

if Odd(I) then Z := Z * X;

I := I div 2;

X := Sqr(X);

end;

while not Eof(InputFile) do

begin

Readln(InputFile, Line);

Process(Line);

end;

repeat statements

The syntax of a repeat statement is repeat statement1; ...; statementn; until expression where

expression returns a Boolean value. The repeat statement executes its sequence of constituent

statements continually, testing expression after each iteration. When expression returns True, the

repeat statement terminates. The sequence is always executed at least once because expression is

not evaluated until after the first iteration.

Examples:

repeat

K := I mod J;

I := J;

J := K;

until J = 0;

repeat

Write('Enter a value (0..9): ');

Readln(I);

until (I >= 0) and (I <= 9);

for statements

Scripter support for statements with the following syntax: for counter := initialValue to finalValue do

statement

For statement set counter to initialValue, repeats execution of statement (or block) and increment

value of counter until counter reachs finalValue.

Examples:

SCRIPT 1:

for c:=1 to 10 do

a:=a+c;

SCRIPT 2:

for i:=a to b do

begin

j:=i^2;

sum:=sum+j;

end;

case statements

Scripter support case statements with following syntax:

case selectorExpression of

caseexpr1: statement1;

...

caseexprn: statementn;

else

elsestatement;

end

if selectorExpression matches the result of one of caseexprn expressions, the respective statement (or

block) will be execute. Otherwise, elsestatement will be execute. Else part of case statement is

optional. Different from Delphi, case statement in script doesn't need to use only ordinal values. You

can use expressions of any type in both selector expression and case expression.

Example:

case uppercase(Fruit) of

'lime': ShowMessage('green');

'orange': ShowMessage('orange');

'apple': ShowMessage('red');

else

ShowMessage('black');

end;

function and procedure declaration

Declaration of functions and procedures are similar to Object Pascal in Delphi, with the difference you

don't specify variable types. Just like OP, to return function values, use implicited declared result

variable. Parameters by reference can also be used, with the restriction mentioned: no need to specify

variable types.

Some examples:

procedure HelloWord;

begin

ShowMessage('Hello world!');

end;

procedure UpcaseMessage(Msg);

begin

ShowMessage(Uppercase(Msg));

end;

function TodayAsString;

begin

result:=DateToStr(Date);

end;

function Max(A,B);

begin

if A>B then

result:=A

else

result:=B;

end;

procedure SwapValues(var A, B);

Var Temp;

begin

Temp:=A;

A:=B;

B:=Temp;

end;

Calling dll functions

Overview

Scripter allows importing and calling external DLL functions, by inserting special directives on

declaration of script routines, indicating library name and, optionally, the calling convention, beyond the

function signature.

External libraries are loaded by Scripter on demand, before function calls, if not loaded yet (dynamically

or statically). To load and unload libraries explicitly, functions LoadLibary and FreeLibrary from unit

Windows can be used.

Note: to enable DLL function calls, you must set AllowDLLCalls property to true.

Pascal syntax

function functionName(arguments): resultType; [callingConvention]; external

'libName.dll' [name ExternalFunctionName];

For example, the following declaration:

function MyFunction(arg: integer): integer; external 'CustomLib.dll';

imports a function called MyFunction from CustomLib.dll. Default calling convention, if not specified, is

register. Scripter also allows to declare a different calling convention (stdcall, register, pascal, cdecl or

safecall) and to use a different name for DLL function, like the following declaration:

function MessageBox(hwnd: pointer; text, caption: string; msgtype: integer):

integer; stdcall; external 'User32.dll' name 'MessageBoxA';

that imports 'MessageBoxA' function from User32.dll (Windows API library), named 'MessageBox' to

be used in script.

Declaration above can be used to functions and procedures (routines without result value).

Supported types

Scripter support following basic data types on arguments and result of external functions:

Integer

Boolean

Char

Extended

String

Pointer

PChar

Object

Class

WideChar

PWideChar

AnsiString

Currency

Variant

Interface

WideString

Longint

Cardinal

Longword

Single

Byte

Shortint

Word

Smallint

Double

Real

DateTime

TObject descendants (class must be registered in scripter with DefineClass)

Others types (records, arrays, etc.) are not supported yet. Arguments of above types can be passed by

reference, by adding var (Pascal) or

byref (Basic) in param declaration of function.

Pascal System Functions

These can also be used in Basic Language

Abs

AnsiCompareStr

AnsiCompareText

AnsiLowerCase

AnsiUpperCase

Append

ArcTan

Assigned

AssignFile

Beep

Chdir

Chr

CloseFile

CompareStr

CompareText

Copy

Cos

CreateOleObject

Date

DateTimeToStr

DateToStr

DayOfWeek

Dec

DecodeDate

DecodeTime

Delete

EncodeDate

EncodeTime

EOF

Exp

FilePos

FileSize

FloatToStr

Format

FormatDateTime

FormatFloat

Frac

GetActiveOleObject

High

Inc

IncMonth

InputQuery

Insert

Int

Interpret (*)

IntToHex

IntToStr

IsLeapYear

IsValidIdent

Length

Ln

Low

LowerCase

Machine (*)

Now

Odd

Ord

Pos

Raise

Random

ReadLn

Reset

Rewrite

Round

Scripter (*)

SetOf (*)

ShowMessage

Sin

Sqr

Sqrt

StrToDate

StrToDateTime

StrToFloat

StrToInt

StrToIntDef

StrToTime

Time

TimeToStr

Trim

TrimLeft

TrimRight

Trunc

UpperCase

VarArrayCreate

VarArrayHighBound

VarArrayLowBound

VarIsNull

VarToStr

Write

WriteLn

Copyright © 2015 i-Logic Software


Designer

Designer

Script Designer IDE

Project concept and structure

A project is a collection of scripts (files), and each file can be a unit (a single script file)

or a form (a script file and a form file). A project file is just a list of the script files belonging to that

project and the information of which script is the main script.

Mixing languages

You can mix scripts with different languages, i.e., in a project you can have a Basic script which

creates and executes a Pascal form.

Main script

Each project has a "main" script. The main script is the script which will be executed when you press

F9 or click the "Run" button (or menu option).

Creating a new project

To create a new project, choose "File | New Project" menu option. This dialog will be displayed:

Keep in mind that here you are choosing the language for the units that will be created automatically by

the IDE. It's not the language of the "project" itself, since such concept doesn't exist. It's the language

of the main units.

After you choose the language of the main units, the IDE will create a main unit and a form unit. This is

the basic project and if you execute it right away you will have a running blank form in your screen.

Creating/adding units/forms to the project

You can create or add existing units/forms to the project by choosing the "File | New unit", "File | New

Form" and "File | Open (add to project)" menu options. If you are creating a new one, you will be

prompted with the same dialog as above, to choose the language of the new unit. If you're adding an

existing unit, then the IDE will detect the script language based on the file extension.

Editing the script in code editor

The IDE provides you with a code editor with full syntax highlight for the script language.

The main features of code editor are:

· code completion (pressing Ctrl+Space)

· syntax highlight

· line numbering

· clipboard operations

· automatic identation

· among other features

Designing forms

When you're dealing with units that are forms, then you have two parts: the script and the form. You

can switch between script and form using F12 key or by pressing the "Code" and "Design" tabs at the

bottom of the screen.

The form editor looks like the picture below:

Designing forms is a similar task as designing forms in Delphi or Visual Studio. You can use the tool

palette the choose a component to drop on the form, position the component using the mouse or

keyboard (resize, move, etc.) and change the properties using the object inspector.

The main features of the form designer are:

· Multi-selection

· Clipboard operations

· Alignment palette (menu "Edit | Align")

· Bring to front / Send to back

· Tab order dialog

· Size dialog

· Locking/unlocking controls

· Grid and Snap to Grid

· among other features

Running and debugging scripts

You can run and debug scripts from the TMS Scripter IDE. The main features of the debugger are:

· Breakpoints

· Watches

· Step over/Trace into

· Run to cursor/Run until return

· Pause/Reset

· and more...

You can use the shortcuts above or use the menu/toolbar buttons to perform running/debugging

actions, like run, pause, step over, trace into, etc..

You can also toggle a breakpoint on/off by clicking on the left gutter in the code editor.

The image below shows a script being debugged in the IDE. A watch has been added in this example

to inspect the value of variable "FinalMsg"

Code Insight features

TMS Scripter comes with code insight features, meaning that in the IDE editor you can have fully

automatic code completion and parameter hints

Code Completion

Code completion is a feature activated by Ctrl+<Space> or when you type an identifier name followed

by a "." (dot).

A list appears at the cursor position, displaying all the available options (methods, properties, functions,

variables) for the given context.

Smart code completion

When a code completion list appears, it will automatically preselect the item which was previously

chosen by you. The item selected is specific to the context.

For example, you might be dealing with a TDataset and retrieving several field values from it, using

FieldByName method. You follow this steps to use code completion for the first line:

1. Invoke code completion by typing Ctrl+<Space>

2. Start type the naming of your TDataset object, for example, type "Dat" and then you get the

"Dataset1" item selected in the completion list.

3. Press "." to insert "Dataset1." text in the editor.

4. A new code completion list will appear listing the methods and properties of the dataset.

5. You start typing "FieldB" to select the item "FieldByName" from the completion list

6. Press "(" to insert "FieldByName(", type the name of field, type ")." to close the parameters and

invoke the list again.

7. Type "AsStr" to find AsString property and then press ";" to finally complete the line.

Now, you want to start a second line with the same code for another field. Smart code completion will

remember your last options, and this is what you would need to type:

1. Invoke code completion by typing Ctrl+<Space>

2. "Dataset1" will come preselected in the list. Just press "." to insert text and invoke a new list for

Dataset1 members.

3. "FieldByName" will come preselected in the list. Just press "(" to insert text and type the field name

4. When close FieldByName parameters and press "." again, "AsString" will also come preselected,

and you can just type ";" to finish typing.

Easy navigation

When you have the desired item selected in code completion list, you can click Enter to make the

selection be typed in the text editor, so you don't have to type it.

You can type other keyboard keys in order to complete the text and also insert the character. For

example, if you press "." (dot), the selected item will be inserted in the text, followed by a dot, and a

new completion list will be displayed for the selected context.

Parameter Hints

Parameter hints is a feature activated by Ctrl+Shift+<Space>, or when you type a method/function

name followed by "(".

This will display the list of parameters for the specified method, so you can properly type the

parameters.

The current parameter being typed is highlighted in the hint

Open Project - Opens an existing form project.

New Project - Starts a new form project.

Save All

New Unit

New Form

Open File - Opens an existing unit.

Save File - Saves the currently visible unit file.

Cut

Copy

Paste

Run Script

Pause Script

Reset Script

Step Over

Step Into

Toggle Breakpoint

Add Watch

Load NC

Copyright © 2015 i-Logic Software


Examples

Examples

Pascal scripts

// script to add spaces

number_counter := 0

line_num := 0

repeat

inc(line_num);

GotoLine(line_num);

s2 := CurrentLine;

if (s2 > '') and (s2 <> '%') and (s2[1] <> 'O') then

begin

addSpaces;

end;

until line_num = LineCount;

// script for filelist test

count:=ListFileCount

ListFileFilter('*.nc')

SetListFolder('C:\Users\Public\Documents\i-Logic\Inplot\NC');

FirstListFile;

while not IsLastListFile do

begin

filename:=FileNameFromList;

LoadFile(filename)

NextListFile;

end;

// script to renumber with G71

var

number_counter, num_places: integer;

function next_number: string;

var s

begin

inc(number_counter)

if (num_places = 4) and (number_counter > 9999) or (num_places = 3) and

(number_counter > 999) or (num_places = 2) and (number_counter > 99) or

(num_places = 1) and (number_counter > 9) then

number_counter := 1

if number_counter < 10 then

s := '000'

else if number_counter < 100 then

s := '00'

else if number_counter < 1000 then

s := '0'

if num_places = 3 then

delete(s, 1, 1)

else if num_places = 2 then

delete(s, 1, 2)

else if num_places = 1 then

delete(s, 1, 3)

else if num_places = 0 then

s := ''

result := 'N' + s + inttostr(number_counter)

end;

num_places:=3;

number_counter := 0

line_num := 0

repeat

inc(line_num);

GotoLine(line_num);

s2 := CurrentLine;

if (s2 > '') and (s2 <> '%') and (s2[1] <> 'O') then

begin

if GetValue('G')=71 then

begin

P:=getvalue('P');

Q:=getvalue('Q');

G71LineNo:=line_num;

end;

N:=getvalue('N');

if N=P then

begin

Remove('N');

front(next_number+' ');

PN:=getvalue('N');

end

else

if N=Q then

begin

Remove('N');

front(next_number+' ');

QN:=getvalue('N');

gotoline(G71LineNo);

ChangeV('P',0,PN,901);

ChangeV('Q',0,QN,901);

gotoline(line_num+1);

P:=-1;

Q:=-1;

end

else

begin

Remove('N');

front(next_number+' ');

end;

end;

until line_num = LineCount;

// script to Add Heidenhain spaces

wordArray:=['BEGIN','PGM','MM',

'TOOL','CALL','TOOL','CALL']

number_counter := 0

line_num := 0

repeat

inc(line_num);

GotoLine(line_num);

s2 := CurrentLine;

if (s2 > '') and (s2 <> '%') and (s2[1] <> 'O') then

begin

AddSpaces;

end;

until line_num = LineCount;

// script to Renumber heidenhein

number_counter:=0

line_num:=1

GotoLine(line_num)

for line_num:=1 to LineCount do

begin

GotoLine(line_num)

s2:=CurrentLine

if (s2>'')and(s2<>'%') and(s2[1]<>'O') then

begin

front('N')

Remove('N')

front(inttostr(number_counter)+' ')

inc(number_counter);

end;

end;

// script for leading zeros

var

number_counter, num_places: integer;

function next_number: string;

var s

begin

inc(number_counter)

if (num_places = 4) and (number_counter > 9999) or (num_places = 3) and

(number_counter > 999) or (num_places = 2) and (number_counter > 99) or

(num_places = 1) and (number_counter > 9) then

number_counter := 1

if number_counter < 10 then

s := '000'

else if number_counter < 100 then

s := '00'

else if number_counter < 1000 then

s := '0'

if num_places = 3 then

delete(s, 1, 1)

else if num_places = 2 then

delete(s, 1, 2)

else if num_places = 1 then

delete(s, 1, 3)

else if num_places = 0 then

s := ''

result := 'N' + s + inttostr(number_counter)

end;

num_places := 0 // number of digits fo N number

number_counter := 0

line_num := 0

repeat

inc(line_num);

GotoLine(line_num);

s2 := CurrentLine;

if (s2 > '') and (s2 <> '%') and (s2[1] <> 'O') then

begin

Remove('N');

front(next_number+' ');

AddSpaces;

end;

until line_num >= LineCount

// script to remove spaces

number_counter := 0

line_num := 0

repeat

inc(line_num);

GotoLine(line_num);

s2 := CurrentLine;

if (s2 > '') and (s2 <> '%') and (s2[1] <> 'O') then

begin

StripSpaces;

end;

until line_num = LineCount;

// Script to Renumber heidenhein

number_counter=0

line_num=1

GotoLine(line_num)

for line_num=1 to LineCount do

begin

GotoLine(line_num)

s2=CurrentLine

if (s2>'')and(s2<>'%') and(s2[1]<>'O') then

begin

front('N')

Remove('N')

front(inttostr(number_counter)+' ')

inc(number_counter);

end;

end;

//Script to skip lines at beginning

// skip all lines until "START"

// first look through the whole file to see if there is "START"

num_lines:=linecount

found:=false;

line_num := 0;

global9:=0;

GotoLine(line_num);

repeat

inc(line_num);

GotoLine(line_num);

s2 := CurrentLine;

found:=hasaddress_s('START',s2);

if found then

begin

GotoLine(line_num+1); // will continue from next line

global9:=999; // supress going back to line 1 when send

line_num:=num_lines;

end;

until line_num >= num_lines;

// if not found then go to top

if found=false then

begin

GotoLine(1);

end;

Basic Scripts

' Script to extract filename

' from acramatic incomming I/O

' search first 2 lines only

if global1<2 then

s= GetIOLine

x=instr(s,"NAME=""O")

if x>0 then

global1=9

x=x+7

s=mid(s,x,4)

TriggerAutoSave("::"+s)

end if

global1=global1+1

end if

' script filter to add spaces

s=GetIOLine

s=AddSpaces_s(s)

SetIOLine(s)

' Hello

Showmessage("Hello")

' send editor text to serial port

note("punch")

punch

'script to renumber

function next_number

inc(number_counter)

return "N"+inttostr(number_counter)

end function

num_places=0 'number of digits for N number

number_counter=0

line_num=0

do

inc(line_num)

GotoLine(line_num)

s2= CurrentLine

if (s2 > "") and (s2 <> "%") and (s2[1] <> "O") then

Remove('N')

front(next_number+' ')

AddSpaces

end if

loop until (line_num >= LineCount)

'script to rotate x,y values

s=getioline

bx=hasaddress_s("x",s)

by=hasaddress_s("y",s)

if bx then

global1=getvalue_s("x",s)

end if

if by then

global2=getvalue_s("y",s)

end if

'puts the last value if not there

if bx=false then

s=rear_s("X"+cstr(global1),s)

end if

if by=false then

s=rear_s("Y"+cstr(global2),s)

end if

s=rotate_s(10,s)

setioline(s)

'strip spaces input filter

s=GetIOLine

s=StripSpaces_S(s)

SetIOLine(s)

'script input filter to send to Excel spreadsheet

line=GetIOLine

if mid(Line,1,3)="///" then

row=getvalue("R")

col=getvalue("C")

x=getvalue("X")

xvalue=excelget(row,col)

x2=cdbl(xvalue)+x

exceladd(row,col+1,cstr(x2))

end if

'output script to wait 1 second before sending

if isfirstline then

Wait(1000)

end if


Language

Language

Language Files

The default language built-in to CNCLINK Script Designer is English.

DNC has full Unicode support for user interface and editor. (Serial port communication is still only ASCII characters because that's what the CNC machines use.)

CNCLINK Script Designer has the ability to load a user configurable language file that changes all the text in the user interface.

On Main Menu - Configuration - Files, there is a dropdown box that lists all the language files in the user data folder.

Example of using a different language from a CNCLINK Script Designer Language File:

A language file for CNCLINK Script Designer consists of a text file with an identifier that represents an item on the interface and the translated string to change it to.

You can see from the included language files how they are arranged and how you can change the text you want displayed.

You can edit these files in a text editor that supports Unicode characters, like the Windows NotePad.

On the left of the equal sign is the item identifier. These show the English text that is used in the program. After the equal sign is the text that should be substituted instead. Just change the string after the equal sign to your translation. You cannot add any new item identifiers - these are the only ones used.

You can make your own language file of any language you want. The file must have a ".lang" extension. The text in the file must begin with the line: [Language]. You can just copy one of the existing language files to a new filename and edit it. You must put the file in the User Data Folder(shown in Settings - Advanced) directory for it to show up on the language list in Settings (on the Files page ).

The DNCsimplifiedChinese.lang file starts out like this:

[Language]
T_PRINT_COLUMNS= 打印栏
T_NUMBER_OF_COLUMNS= 栏的数字
T_SHORTCUT= 快捷方式
T_BROWSE= 浏览
T_DESCRIPTION= 描写
T_PATH= 路径
T_SETTINGS= 设置
T_THIS_PRODUCT_EXPIRES_IN= 这种产品过期在
T_RUN= 跑
T_RUNS= 跑

Windows Language Support

If all the text in in the buttons and labels are blanks, then it means your computer does not support for that language installed.

If you have an English language Windows operating system, you may not have Eastern language support installed. In Windows XP you can install eastern language support by going to Control Panel - "Regional and Language Options".

Go to the Languages tab:

Check the "Install files for East Asian languages" checkbox and click Apply. It will go through an installation routine. After it is done, restart computer.