GO2cam Javascript API  6.11
Launch a script

Using the GO2cam Javascript Editor

GO2cam is able to execute scripts written in JavaScript langage and stored in **.js** files. JavaScript files can be written out of GO2cam or by using the embedded JavaScript editor.

  1. In GO2cam menu click Tools > JavaScript Editor to open the JavaScript editor
  2. In the JavaScript editor menu
    • click File > Open to open a .js file
    • click Run to execute the script

‍It it also possible to drag 'n drop a .js file in GO2cam window. The file will be open in the JavaScript editor


[1] Run button to launch the script
[2] Editing area where the script is written
[3] Output area. This area displays error messages when errors occur while executing a script. It can also be used to display information using console.log command

Command line

Launching a script using GO2cam in command line is possible with the token -js 'path_to_my_script.js' It is mandatory to use it combined with token -y 'product_name' to indicate the appropriate product (milling, turning...etc.). The list of GO2cam products is available by running GO2cam in command line with the token -h. Optionaly, it is possible to use the token -blackbox to hide GO2cam graphic interface while the script is running.

Example to run a script for milling

go2cam.exe -js 'd:\myscript.js' -y 'milling'

Example to run a script for turning keeping GO2cam invisible

go2cam.exe -js "d:\monscript.js" -y “turning” -blackbox

Since version 6.11.203 of GO2cam, it is possible to give arguments to the script using - - token. Arguments can be retrieved in script file with variable args. Let's assume that test_args.js contains the following code

if(args.length>0)
{
let str = 'input arguments: '
args.forEach( a => str+= a + ', ' )
GO2SDialogUtil.CreateMessageBox(str)
}

The execution of the following command line will display a message box displaying input arguments

go2cam.exe -y milling -js 'd:\test_args.js' --12 --args2

Using several .js at the same time

Complex scripts can be divided to several .js files. File contents can be imported into a main .js file using GO2SUtil.ImportJS function (the script files must be in the same folder). Get toolbox.js file here: toolbox.js to run the following script.

//import utility functions defined in another file
GO2SUtil.ImportJS('toolbox.js')
var p1 = new GO2SXYZ(10,10,0)
var p2 = new GO2SXYZ(10,100,0)
var obl = new GO2SOblong(p1,p2,20)
DiscretizePts(obl) // defined in toolbox.js

API Limitations

It is not possible to import external libraries