( Ultimate CNC 4.x )
The purpose of the scripts is maximum customization for your needs. So review these scripts and adapt them to your system.
 /* 
 Read the dimensions from your G-code program and 
 move your machine to the center of the work piece 
 */ 
 
 let program = new GCodeProgram(); 
 let frame = {}; 
 program.getSize( frame ); 
 
 let center = {}; 
 center.x = (frame.xmax + frame.xmin) / 2.0; 
 center.y = (frame.ymax + frame.ymin) / 2.0; 
 let gcoordenates = "G01X" + center.x + "Y" + center.y; 
 
 let machine = new Machine(); 
 machine.code( "G90; G21; F300;" ); 
 machine.goUpZ(); 
 machine.code( gcoordenates );