1
General Mach Discussion / Re: Mach3, Lightburn and GRBL work arounds
« on: October 17, 2023, 08:26:09 PM »
Here is GRBL code generated in lightburn to code that Mach 3 with Ethernet smooth stepper can use including the ability to control power. I use an Endurance 10W diode. This script inserts M11Px Sxx below every G0 move and M10Px above every G0 move.
-- Choose the file to be modified using the Finder
set chosenFile to choose file with prompt "Choose a file to modify:"
set fileReference to open for access chosenFile with write permission
-- Initialize variables
set modifiedLines to {}
-- Define the text to be inserted
set insertLineAbove to "M10P2"
set insertLineBelow to "M11P2 S10"
-- Read and process the file line by line
try
-- Read the file line by line
set eofReached to false
repeat until eofReached
try
-- Read the current line
set currentLine to read fileReference until "
"
-- Check if the line contains "G0"
if currentLine contains "G0" then
-- Add M10P2 one line above the G0 command
set end of modifiedLines to insertLineAbove
set end of modifiedLines to currentLine
-- Add M11P2 S25 one line below the G0 command
set end of modifiedLines to insertLineBelow
else
-- Keep the line unchanged
set end of modifiedLines to currentLine
end if
on error
-- End of file reached
set eofReached to true
end try
end repeat
-- Close the file
close access fileReference
-- Combine the modified lines into a single string
set modifiedText to (items 1 thru -2 of modifiedLines) as text
-- Write the modified text back to the file
set fileReference to open for access chosenFile with write permission
set eof of fileReference to 0
write modifiedText to fileReference
close access fileReference
display dialog "File successfully modified and saved." buttons {"OK"} default button "OK"
on error errMsg
-- Handle any errors that occur
try
close access fileReference
end try
display dialog "Error: " & errMsg buttons {"OK"} default button "OK"
end try
-- Choose the file to be modified using the Finder
set chosenFile to choose file with prompt "Choose a file to modify:"
set fileReference to open for access chosenFile with write permission
-- Initialize variables
set modifiedLines to {}
-- Define the text to be inserted
set insertLineAbove to "M10P2"
set insertLineBelow to "M11P2 S10"
-- Read and process the file line by line
try
-- Read the file line by line
set eofReached to false
repeat until eofReached
try
-- Read the current line
set currentLine to read fileReference until "
"
-- Check if the line contains "G0"
if currentLine contains "G0" then
-- Add M10P2 one line above the G0 command
set end of modifiedLines to insertLineAbove
set end of modifiedLines to currentLine
-- Add M11P2 S25 one line below the G0 command
set end of modifiedLines to insertLineBelow
else
-- Keep the line unchanged
set end of modifiedLines to currentLine
end if
on error
-- End of file reached
set eofReached to true
end try
end repeat
-- Close the file
close access fileReference
-- Combine the modified lines into a single string
set modifiedText to (items 1 thru -2 of modifiedLines) as text
-- Write the modified text back to the file
set fileReference to open for access chosenFile with write permission
set eof of fileReference to 0
write modifiedText to fileReference
close access fileReference
display dialog "File successfully modified and saved." buttons {"OK"} default button "OK"
on error errMsg
-- Handle any errors that occur
try
close access fileReference
end try
display dialog "Error: " & errMsg buttons {"OK"} default button "OK"
end try