Hello Guest it is April 17, 2021, 08:16:31 AM

Author Topic: set selected tool  (Read 310 times)

0 Members and 1 Guest are viewing this topic.

Offline Bill_O

*
  •  362 362
    • View Profile
set selected tool
« 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
Re: set selected tool
« Reply #1 on: August 18, 2020, 02:51:12 AM »
Hi Bill,

Use this

Code: [Select]
rc = mc.mcToolSetCurrent(number mInst, number toolnum)

Offline Bill_O

*
  •  362 362
    • View Profile
Re: set selected tool
« Reply #2 on: August 18, 2020, 08:36:31 AM »
Swifty,

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

Bill
Re: set selected tool
« Reply #3 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)

Offline Bill_O

*
  •  362 362
    • View Profile
Re: set selected tool
« Reply #4 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

Offline Bill_O

*
  •  362 362
    • View Profile
Re: set selected tool
« Reply #5 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

Re: set selected tool
« Reply #6 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.