That script would not work for me with the motion controller that i use. I use a Vital systems HiCON board and their plugin keeps updating Mach4 with the position reported from the motion controller. telling the motion controller to set the axis position without moving causes your axis to go out of band. I emailed Marc from vital systems and he provided me with the script to use with their motion controller. I have a X / 2 and Y / 2 button next the axis zero buttons.
X / 2 button Left up script
if(machEnabled == 1)then
local inst = mc.mcGetInstance();
local xPosition = mc.mcAxisGetPos(inst, 0);
mc.mcCntlMdiExecute(inst, 'G0X' .. tostring(xPosition / 2));
end
Y / 2 button Left up script
if(machEnabled == 1)then
local inst = mc.mcGetInstance();
local yPosition = mc.mcAxisGetPos(inst, 1);
mc.mcCntlMdiExecute(inst, 'G0Y' .. tostring(yPosition / 2));
end
These buttons move the axis to to half of the dro readout when pushed, so make sure the Z is clear of the work when you use Them. I Hope this helps someone out.