Page 1 of 1

GRBL Laser Post Processor

Posted: Fri Jan 05, 2024 4:39 am
by CrazyKen
Hi All

I am currently editing a GRBL post processor to run a laser. I am trying to pull in the tool type to build my code but am not having much luck. I can get the operationName with this snippet

post.Text (" /*OPERATION ", operationName, " */ \n")

The output in gcode is /*OPERATION Laser engrave, Layer 1, T18: Laser, 1.5 mm kerf, 0 mm Deep */

This will change for each tool and the layer name.
Is there a way to extract the first part of the string up to the comma so it only outputs "Laser engrave"?
I have tried several things but new to editing post processors so need some help.

Thanks

Re: GRBL Laser Post Processor

Posted: Fri Jan 05, 2024 2:46 pm
by bLouChip
try this snippet, it worked for me in some test cases this morning...

Code: Select all

-- test code   
   -- match any char from begining of string to comma and return that substring
   local s = string.match ( operationName, "^.-," )   
   if s~= nil then 
      -- remove the comma at the end
      s = string.sub ( s, 1, string.len(s) - 1 )
      post.Text ( s, "\n" )
   else 
      post.Text ( "no comma found \n" )
   end
SC post processors are written in a language named Lua, here is the reference doc: https://www.lua.org/manual/5.1/manual.html#5.4
Happy coding :)

Re: GRBL Laser Post Processor

Posted: Fri Jan 05, 2024 2:56 pm
by CrazyKen
That is exactly what I was looking for

thanks

Re: GRBL Laser Post Processor

Posted: Fri Jan 05, 2024 3:40 pm
by djreiswig
There should be a built in variable for the tool name. Not sure what it's called. Look at the variable monitor in SheetCam and you should see it.