Hello Guest it is March 29, 2024, 02:54:37 AM

Author Topic: Lua GcodeExecute  (Read 1933 times)

0 Members and 1 Guest are viewing this topic.

Lua GcodeExecute
« on: October 07, 2015, 11:04:26 AM »
I am wanting to execute g code using a variable.  In Mach3 you were able to do this easily but I can't figure out how to do it in Lua.
Here is the macro below.  The macro retrieves the reg val just fine but the part I'm concerned with are lines 8 and 9.  I have set the variable to my reg val.  Now how do I use the variable in the g code line. 


N01  function m1020() --Test
N02  --Macro to move programable coolant nozzle.
N03  --using registers for nozzle positions.
N04  inst = mc.mcGetInstance()
N05  hreg = mc.mcRegGetHandle(inst,"gRegs0/Test1")-- Position 1 2.5
N06  val = mc.mcRegGetValueString(hreg)
N07  val = tonumber(val)
N08  local ProgCoolant = val
N09  mc.mcCntlGcodeExecuteWait(inst, "G90G00C", ProgCoolant)
N10  end
N11  if (mc.mcInEditor()== 1) then
N12      m1020()
N13  end
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Lua GcodeExecute
« Reply #1 on: October 07, 2015, 12:56:36 PM »
See if this example helps.

Code: [Select]
local inst = mc.mcGetInstance() -- Get the instance of Mach4
local xval = mc.mcProfileGetString(inst, "RememberPos", "X", "NotFound") -- Get the register Value
local yval = mc.mcProfileGetString(inst, "RememberPos", "Y", "NotFound") -- Get the register Value
local zval = mc.mcProfileGetString(inst, "RememberPos", "Z", "NotFound") -- Get the register Value

if(xval == "NotFound")then -- check to see if the register is found
wx.wxMessageBox('Register xval does not exist.\nYou must remember a postion before you can return to it.'); -- If the register does not exist tell us in a message box
elseif (yval == "NotFound")then -- check to see if the register is found
wx.wxMessageBox('Register yval does not exist.\nYou must remember a postion before you can return to it.'); -- If the register does not exist tell us in a message box
elseif (zval == "NotFound")then -- check to see if the register is found
wx.wxMessageBox('Register zval does not exist.\nYou must remember a postion before you can return to it.'); -- If the register does not exist tell us in a message box
else
mc.mcCntlMdiExecute(inst, "G00 G53 Z0.0000 \n G00 G53 X" .. xval .. "\n G00 G53 Y" .. yval .. "\n G00 G53 Z" .. zval)
end
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Lua GcodeExecute
« Reply #2 on: October 07, 2015, 03:33:17 PM »
Thanks Chaoticone!! That did the trick.  Just needed ".." instead of ","
Works Great!! =)
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Lua GcodeExecute
« Reply #3 on: October 18, 2015, 06:29:57 PM »
 :)
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!