Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started 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.
-
Put this code into the OnModify script of the Current Tool DRO
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
-
Put this code into the OnModify script of the Current Tool DRO
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.
-
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:
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.
-
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:
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
-
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:
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.
-
Put this code into the OnModify script of the Current Tool DRO
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.