Here is the actual button down script I use. I have totally replaced the stock jog functions and this has proved reliable for a long time. This should give you some ideas from which to build, but note that I do not take any stock value for distance and jog type, as I created my own and saved them in the INI file. I call this from buttons and from keys mapped into the signal script.
--AW Jog button down initiates motion.
-- type is taken from INI if no parrameter is supplied
function Jogging.JogBtnDown(axis, direction, type)
local inst = mc.mcGetInstance()
if (type == nil) then
type = mc.mcProfileGetInt(inst,'Preferences', 'JogType', mc.MC_JOG_TYPE_INC)
end
local dist, rc = mc.mcProfileGetString(inst,'Preferences', "JogDist", '0')
dist = tonumber(dist)
local defUnits = mc.mcCntlGetUnitsDefault(inst)
rc = mc.mcJogSetUnitsMode(inst, axis, defUnits)
if (type == mc.MC_JOG_TYPE_INC) then
if (direction == mc.MC_JOG_NEG) then
dist = -1 * dist
end
rc = mc.mcJogIncStart(inst, axis, dist)
elseif (type ==mc.MC_JOG_TYPE_VEL) then
rc = mc.mcJogVelocityStart(inst, axis, direction)
end
end
My default units are set to metric, and I've never experienced a switch to Imperial units when using the ablove.
Allan