Machsupport Forum
		Mach Discussion => Mach4 General Discussion => Topic started by: Cbyrdtopper 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
- 
				See if this example helps.
 
 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
- 
				Thanks Chaoticone!! That did the trick.  Just needed ".." instead of ","
 Works Great!! =)
- 
				 :)