Hello Guest it is July 18, 2025, 12:54:36 PM

Author Topic: Auto change offset to match tool?  (Read 15798 times)

0 Members and 1 Guest are viewing this topic.

Offline Rimmel

*
  •  284 284
Auto change offset to match tool?
« on: July 08, 2024, 04:12:33 PM »
Is there any way to script to change the active offset to match the current tool - when you enter a number into the Current Tool box?

E.g If I enter "5" into the current tool box and press enter - it automatically sets the active offset to 5. (2 and 2, 3 and 3 etc etc)

thanks

Edit: I kbnow you can type T0505 in the MDI, but I use the machine for rapid development of parts and as such its a semi manual machine. Typing T*********X everytime I want to manuually change a tools is very tiresome... especially when you could just change the tool on Mach3 and it changed the offset automatically.
« Last Edit: July 08, 2024, 04:14:59 PM by Rimmel »
Re: Auto change offset to match tool?
« Reply #1 on: July 09, 2024, 03:15:18 PM »
Put this code into the OnModify script of the Current Tool DRO

Code: [Select]
local inst = mc.mcGetInstance()
local toolNum = select(1,...) --Get the number entered into the DRO
local rc = mc.mcCntlSetOffsetIndex(inst, tonumber(toolNum)) --Set the offset index
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error Setting Offset Index")
end
return toolNum --Return the toolNum so that it is displayed in the DRO

Offline Rimmel

*
  •  284 284
Re: Auto change offset to match tool?
« Reply #2 on: July 09, 2024, 03:20:02 PM »
Put this code into the OnModify script of the Current Tool DRO

Code: [Select]
local inst = mc.mcGetInstance()
local toolNum = select(1,...) --Get the number entered into the DRO
local rc = mc.mcCntlSetOffsetIndex(inst, tonumber(toolNum)) --Set the offset index
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error Setting Offset Index")
end
return toolNum --Return the toolNum so that it is displayed in the DRO

Thank you  -I'll give that a go tomorrow.
Re: Auto change offset to match tool?
« Reply #3 on: July 09, 2024, 10:28:57 PM »
Is there any way to script to change the active offset to match the current tool - when you enter a number into the Current Tool box?

E.g If I enter "5" into the current tool box and press enter - it automatically sets the active offset to 5. (2 and 2, 3 and 3 etc etc)

thanks

Edit: I kbnow you can type T0505 in the MDI, but I use the machine for rapid development of parts and as such its a semi manual machine. Typing T*********X everytime I want to manuually change a tools is very tiresome... especially when you could just change the tool on Mach3 and it changed the offset automatically.
You can add the following Lua Script:
Code: [Select]
function changeToolAndOffset()
    local toolNumber = scr.GetProperty("CurrentToolBox", "Value")
    local toolOffsetCommand = string.format("G43 H%d", toolNumber)
   
    -- Change the active tool
    mc.mcToolSetCurrent(inst, tonumber(toolNumber))
   
    -- Apply the tool offset
    mc.mcCntlMdiExecute(inst, toolOffsetCommand)
end

-- Bind the function to the Current Tool box event
scr.SetProperty("CurrentToolBox", "On Modify", "changeToolAndOffset")
This script will ensure that when you enter a tool number, the corresponding tool offset is automatically applied without needing to type the full command in the MDI each time.
« Last Edit: September 23, 2024, 02:41:16 AM by Tweakie.CNC »

Offline Rimmel

*
  •  284 284
Re: Auto change offset to match tool?
« Reply #4 on: July 10, 2024, 06:23:42 AM »
Is there any way to script to change the active offset to match the current tool - when you enter a number into the Current Tool box?

E.g If I enter "5" into the current tool box and press enter - it automatically sets the active offset to 5. (2 and 2, 3 and 3 etc etc)

thanks

Edit: I kbnow you can type T0505 in the MDI, but I use the machine for rapid development of parts and as such its a semi manual machine. Typing T*********X everytime I want to manuually change a tools is very tiresome... especially when you could just change the tool on Mach3 and it changed the offset automatically.
You can add the following Lua Script:
Code: [Select]
function changeToolAndOffset()
    local toolNumber = scr.GetProperty("CurrentToolBox", "Value")
    local toolOffsetCommand = string.format("G43 H%d", toolNumber)
   
    -- Change the active tool
    mc.mcToolSetCurrent(inst, tonumber(toolNumber))
   
    -- Apply the tool offset
    mc.mcCntlMdiExecute(inst, toolOffsetCommand)
end

-- Bind the function to the Current Tool box event
scr.SetProperty("CurrentToolBox", "On Modify", "changeToolAndOffset")
This script will ensure that when you enter a tool number, the corresponding tool offset is automatically applied without needing to type the full command in the MDI each time.

Where are you adding the Lua Script? On the screenset Pageload event?

thanks
« Last Edit: September 23, 2024, 02:41:50 AM by Tweakie.CNC »

Offline Rimmel

*
  •  284 284
Re: Auto change offset to match tool?
« Reply #5 on: July 10, 2024, 08:57:23 AM »
Is there any way to script to change the active offset to match the current tool - when you enter a number into the Current Tool box?

E.g If I enter "5" into the current tool box and press enter - it automatically sets the active offset to 5. (2 and 2, 3 and 3 etc etc)

thanks

Edit: I kbnow you can type T0505 in the MDI, but I use the machine for rapid development of parts and as such its a semi manual machine. Typing T*********X everytime I want to manuually change a tools is very tiresome... especially when you could just change the tool on Mach3 and it changed the offset automatically.
You can add the following Lua Script:
Code: [Select]
function changeToolAndOffset()
    local toolNumber = scr.GetProperty("CurrentToolBox", "Value")
    local toolOffsetCommand = string.format("G43 H%d", toolNumber)
   
    -- Change the active tool
    mc.mcToolSetCurrent(inst, tonumber(toolNumber))
   
    -- Apply the tool offset
    mc.mcCntlMdiExecute(inst, toolOffsetCommand)
end

-- Bind the function to the Current Tool box event
scr.SetProperty("CurrentToolBox", "On Modify", "changeToolAndOffset")
This script will ensure that when you enter a tool number, the corresponding tool offset is automatically applied without needing to type the full command in the MDI each time.

Where are you adding the Lua Script? On the screenset Pageload event?

thanks


Couldn't get this to work. But thank you for your reply - appreciated.
« Last Edit: September 23, 2024, 02:42:24 AM by Tweakie.CNC »

Offline Rimmel

*
  •  284 284
Re: Auto change offset to match tool?
« Reply #6 on: July 10, 2024, 08:57:52 AM »
Put this code into the OnModify script of the Current Tool DRO

Code: [Select]
local inst = mc.mcGetInstance()
local toolNum = select(1,...) --Get the number entered into the DRO
local rc = mc.mcCntlSetOffsetIndex(inst, tonumber(toolNum)) --Set the offset index
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error Setting Offset Index")
end
return toolNum --Return the toolNum so that it is displayed in the DRO
This worked perfectly.

Thank you Sir.