Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Bill_O on August 17, 2020, 04:12:59 PM
-
I have a button to raise and lower the selected tool number.
The code works one time then I must exit Mach for it to work again.
I can not find any way to set the selected tool number other than using the gcode.
local inst = mc.mcGetInstance()
local Tool = mc.mcToolGetSelected(inst)
--get max tools
local ATCMaxTlsReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCMaxTools')
local ATCMaxTlsVal = mc.mcRegGetValue(ATCMaxTlsReg)
--if tool is in range add one to tool #
if (Tool <= (ATCMaxTlsVal - 1)) then
Tool = (Tool + 1)
mc.mcCntlGcodeExecute(inst, string.format("T" .. Tool))
end
Thanks,
Bill
-
Hi Bill,
Use this
rc = mc.mcToolSetCurrent(number mInst, number toolnum)
-
Swifty,
I want to set the Selected Tool not the Current Tool.
Bill
-
Hi Bill,
The following works but I am not sure if it is the best/correct way to do this. Maybe someone else can advise.
rc = mc.mcCntlSetPoundVar(inst, mc.SV_CUR_SELECTED_TOOL, Tool)
-
Swifty,
Thank you.
I will give it a try.
I do not care about the best way I just need it to work.
Bill
-
Swifty,
It worked great.
Thanks for the help.
Here is the final code.
Tool to get plus;
local inst = mc.mcGetInstance()
local Tool = mc.mcToolGetSelected(inst)
--get max tools
local ATCMaxTlsReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCMaxTools')
local ATCMaxTlsVal = mc.mcRegGetValue(ATCMaxTlsReg)
--if tool is in range add one to tool #
if (Tool <= (ATCMaxTlsVal - 1)) then
Tool = (Tool + 1)
mc.mcCntlSetPoundVar(inst, mc.SV_CUR_SELECTED_TOOL, Tool)
end
Tool to get minus;
local inst = mc.mcGetInstance()
local Tool = mc.mcToolGetSelected(inst)
--if tool is in range subtract one from tool #
if (Tool >= 2) then
Tool = (Tool - 1)
mc.mcCntlSetPoundVar(inst, mc.SV_CUR_SELECTED_TOOL, Tool)
end
-
Swifty,
It worked great.
Thanks for the help.
Here is the final code.
Tool to get plus;
Thank you for the solution, I had the same problem and this helped me too.