Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Bill_O on August 17, 2020, 04:12:59 PM

Title: set selected tool
Post 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.

Code: [Select]
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
Title: Re: set selected tool
Post by: SwiftyJ on August 18, 2020, 02:51:12 AM
Hi Bill,

Use this

Code: [Select]
rc = mc.mcToolSetCurrent(number mInst, number toolnum)
Title: Re: set selected tool
Post by: Bill_O on August 18, 2020, 08:36:31 AM
Swifty,

I want to set the Selected Tool not the Current Tool.

Bill
Title: Re: set selected tool
Post by: SwiftyJ on August 19, 2020, 09:02:32 AM
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.

Code: [Select]
rc = mc.mcCntlSetPoundVar(inst, mc.SV_CUR_SELECTED_TOOL, Tool)
Title: Re: set selected tool
Post by: Bill_O on August 19, 2020, 10:01:36 AM
Swifty,

Thank you.
I will give it a try.
I do not care about the best way I just need it to work.

Bill
Title: Re: set selected tool
Post by: Bill_O on August 19, 2020, 11:57:30 AM
Swifty,

It worked great.
Thanks for the help.
Here is the final code.

Tool to get plus;
Code: [Select]
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;
Code: [Select]
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

Title: Re: set selected tool
Post by: travisfinley on September 02, 2020, 09:19:22 AM
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.