The JavaScript API gives the possibility to read/write parameters of each components of the machining process (machine, material, cycles and tools).
You can also load a machine, a material, perform actions on cycle, tweak and run an Opelist.
Getting parameter keys
Each parameter is known by a unique key. The keys can be known by using the ekey command in the dialog bar
This command allows diplay of special tooltips with API keys of parameters
And displays key information in the GO2cam information window
Machine
The machine is managed in Javascript by the object GO2SMachine.
Setting or getting parameters
The exemple bellow shows how to load a machine, and how to access some parameters.
var machine = new GO2SMachine
machine.LoadFromFile('', 'my_machine.MCF')
if(machine.IsLoaded())
console.log('Machine loaded')
// Set a parameter of the machine
machine.SetParam(REAL_MAC_DEC_X_ROT, 42.9)
// Get a parameter of the machine
console.log(machine.GetParam(REAL_MAC_DEC_X_ROT))
// Get a parameter of a holding device
console.log(machine.GetParam(REAL_MAC_SPACING, 1))
my_machine.MCF
Getting ISO file
Once loaded, the machine is the object that will give the iso code by calling GO2SMachine.RunPP
var machine = new GO2SMachine('', 'my_machine.MCF')
if(machine.IsLoaded())
machine.RunPP('iso', 'my_pp.iso')
Material
Material can be loaded using GO2SMachiningUtil object.
if(GO2SMachiningUtil.LoadMaterial('', 'Aluminium_alloys.MTR') == GO2SError.success)
console.log('Material loaded')
Aluminium_alloys.MTR
Cycles
Cycles are managed in Javascript by the object GO2SCycle. GO2SMachiningUtil provides several methods to get cycles form machining tree.
This API only allows to modify existing cycles. It does not allow to create cycles directly. To create machining operations, refer to Opelist.
Get/Set parameters
var cycles = GO2SMachiningUtil.GetByName('Facing')
var facing = cycles[0]
cycles = GO2SMachiningUtil.GetByName('Pocket')
var pocket = cycles[0]
facing.SetParam(REAL_MILL_TOOL_STEPOVER_RATIO, 0.3)
pocket.SetParam(REAL_MILL_INCR_DEPTH, 2)
GO2SInteract.UpdateMachining()
ParamUsi.PCE
Move a cycle
const cyc1 = GO2SMachiningUtil.GetByName("Hexagon Island")[0] // Get the first found
console.log(cyc1[0].GetName())
const cyc2 = GO2SMachiningUtil.GetByName("Contouring")[0] // Get the first found
console.log(cyc2[0].GetName())
GO2SMachiningUtil.MoveCycle(cyc1[0], GO2SWay.after, cyc2[0]);
GO2SInteract.UpdateAll()
MW_01_Plate Fixture.PCE
Tools
Tools are managed in Javascript by the object GO2STool.
The following exemple updates the tool diameter in all cycles using the same tool than 'Pocket' cycle.
var cycle = GO2SMachiningUtil.GetByName('Pocket')
var tool = cycle[0].GetTool()
tool.SetParam(REAL_TOOL_DIAMETER, 20)
tool.Update()
GO2SInteract.UpdateMachining()
The following code will updates only the tool diammeter for 'Pocket' cycle.
var cycle = GO2SMachiningUtil.GetByName('Pocket')
var tool = cycle[0].GetTool()
var tool_cc = tool.Copy('my_tool_cc')
tool_cc.SetParam(REAL_TOOL_DIAMETER, 20)
cycle[0].ReplaceTool(tool_cc)
GO2SInteract.UpdateMachining()
The following code will load a tool from a file and replace it in a 'Pocket' cycle.
var tool = new GO2STool;
tool.LoadFromFile(TOOL_MILL_FLAT, "EC020B07-3C03.F05");
var cycle = GO2SMachiningUtil.GetByName('Pocket');
facing[0].ReplaceTool(tool);
GO2SInteract.UpdateGeometry();
Opelist
GO2SWireFeature
- Attention
- this objects works only for turning application
see GO2SWireFeature to see how to create wireframe design linked to an opelist and be used as a 2D feature (turning>Part>Feature 2D)
Run an opelist from a script
An Opelist can can be loaded and run using GO2SOpelist object. Values of user parameters can be changed by referencing their key.
var ope = new GO2SOpelist('opelist', 'MyOplAuto.OPL')
if(ope.IsLoaded())
{
ope.SetUserParam('dia1', 2)
ope.SetUserParam('stepover', 0.12)
console.log(ope.GetParam('dia1'))
ope.Run()
}
Run a script from an opelist
In the Opelist Manger when doing a right click on the opelist you can associate a Macro to the opelist. You can select here a .js file that will be launched at the begining of the opelist execution.
Let's assume for example a pocketing opelist where you need to ask allowances before execution. You can achieve it by associating the following script as a Macro to the opelist
var xy = GO2SDialogUtil.AskDouble('Allowance','XY :')
var z = GO2SDialogUtil.AskDouble('Allowance','Z :')
GO2SOpelistUtil.SetParamRunningOpeList('paramXY', xy)
GO2SOpelistUtil.SetParamRunningOpeList('paramZ', z)