Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Rimmel on July 08, 2024, 04:12:33 PM

Title: Auto change offset to match tool?
Post by: Rimmel 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.
Title: Re: Auto change offset to match tool?
Post by: SwiftyJ 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
Title: Re: Auto change offset to match tool?
Post by: Rimmel 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.
Title: Re: Auto change offset to match tool?
Post by: charliejone 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.
Title: Re: Auto change offset to match tool?
Post by: Rimmel 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
Title: Re: Auto change offset to match tool?
Post by: Rimmel 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.
Title: Re: Auto change offset to match tool?
Post by: Rimmel 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.