Post processor files are written in the Lua macro language. See http://www.lua.org
and http://lua-users.org/wiki/LuaDirectory
The post is event based. Each event has a function associated with it.
The available events are:
Occurs when the post details are displayed.
The event is a wxOptionsEvent(see plugin documentation). A simple about
would look something like this:
function OnAbout(event)
ctrl = event:GetTextCtrl()
ctrl:AppendText("My post processor\n")
ctrl:AppendText("Another line\nYet another line")
end
Occurs when the output file is opened.
Set the variable ‘bigarcs’ to 1 if you don’t want arcs to be output as
quadrants * DEPRECATED * see SetOptions instead
Set the variable ‘minarcsize’ to the minimum arc size in millimetres. If
arcs are less than this size they will be turned into moves instead.
Default value is 0.05mm
Whenever a new line is written to the output file
Occurs just before the output file is closed.
Rapid linear move
Linear move at feedrate
Arc/helical move. See the arcasmoves() function if your machine cannot handle arcs.
drill
Called just before drilling, after the toolchange.
Called after drilling is finished, before OnNewOperation()
Tap with a tapmatic type automatic tapping head
Tap with a rigid tapping head
Called just before tapping, after the toolchange.
Called after tapping is finished, before OnNewOperation()
Z axis moves upward. Can be used to turn a plasma/laser off
Z axis moves downwards. Can be used to turn a plasma/laser on
Feed rate change
Tool change
Occurs when a new operation is started
When a new part is started
Turn the spindle on clockwise
Turn the spindle on anticlockwise
Turn the spindle off
The spindle speed has changed
Turn flood coolant on
Turn mist coolant on
Turn coolant off
Output a comment to the g-code file. See commenttext variable below.
Called at the start of a new cut. This occurs just before moving to the start of the cut. See entitylength and entityclosed variables below.
Called just before the output file is opened. You can change the values of the fileName and filePath variables if you wish to save to a different file.
Called after the g-code file has been saved. Could be used to trigger
an external application to execute the code.
In each event the following standard functions are available. Note that
they are in the post namespace so each should be preceded by 'post.'.
For example post.Warning("This is a warning").
All parameters are combined into one string and displayed on the progress window.
All parameters are combined into one string and displayed on the progress window as a warning.
All parameters are combined into one string and displayed on the progress window as an error.
All parameters are output to the file. Line numbers are added to the start of each line and empty lines are ignored
All parameters are output to the file. The text is not processed in any way. No line numbers are added.
The text is output to the file unless the last call to modaltext
contained the same text
Here is an example:
modaltext(“G0”) - “G0” is output (the first call to modaltext() always
outputs the code)
modaltext(“G0”) - nothing is output because the previous call was “G0”
modaltext(“G1”) - “G1” is output because the previous call wasn't “G1”
modaltext(“G1”) - nothing is output because the previous call was “G1”
modaltext(“G83”) - “G83” is output because the previous call wasn't
“G83”
The next call to modaltext will always output the text to the file. It is functionally equivalent to modaltext(“”)
Output the number in the format specified by the format string. Number
can be any valid numeric expression
The format string defines the number of leading and trailing zeros.
The character '0' means that that digit must be output even if it is a
leading or trailing zero.
The character '#' means that the digit will be output if it is not a
leading or trailing zero.
A leading + indicated that the sigh should always be shown.
For instance Number(2.5 "+0000.00") will output ‘+0002.50', Number (2.56
"0.#") will output '2.6' and Number(123.45 "0.") will output '123'
Returns: The number as it was formatted. For instance:
post.Number(123.456789,”0.00”)
would output “123.46” and return the number 123.46. This is useful for
incremental posts.
Format a number using the format specified by the format string.
Returns: A string containing the formatted number and the number as it
was formatted.
For example a,b = post.FormatNumber(123.456,”+0.0”) would return:
a = “+123.5”
b = 123.5
a = post.FormatNumber(123.456,”+0.0”) would return:
a = “+123.5”
Text and number is output to the file if the number is different to the
last time ModalNumber was called with the same text. For example the
following code:
ModalNumber " X" 10 "0.0##"
ModalNumber " Y" 20 "0.0##"
ModalNumber " X" 10 "0.0##"
ModalNumber " Y" 21 "0.0##"
ModalNumber " Y" 21 "0.0##"
will output: ' X10 Y20 Y21'
Returns: The number as it was formatted. If the number was not output
the return value is the value as it would have been output.
like modalnumber() but text and number are always output. This keeps
track of modality if you wish to use modalnumber somewhere else.
Returns: The number as it was formatted.
This resets all modal numbers.
for example the following code
modalnumber " X" 10 "0.0##"
cancelmodalnumbers()
modalnumber " X" 10 "0.0##"
will output ‘ X10 X10’
Write an end of line to the file. This equivalent to text("\n")
if any source char is found in a filename or post name it is replaced
with the equivalent replace char. For instance if your post is called
"mypost(1).post"
then the following code:
post.SetCommentChars ("()", "[]")
text “(postname)”
will output 'mypost[1].post' to the file.
Perform the current arc as a series of short linear moves. This should
only be called from the onArc() event.
Tolerance is the maximum deviation in millimetres from a true arc.All
other parameters are optional. Reducing Tolerance increases the number
of line segments generated.
Set the file encoding. This overrides the option in options->machine->post processor and would normally be called from function OnInit()
Encoding is one of :
| wx.wxFONTENCODING_SYSTEM | system default |
| wx.wxFONTENCODING_DEFAULT | current default encoding |
| wx.wxFONTENCODING_ISO8859_1 | West European (Latin1) |
| wx.wxFONTENCODING_ISO8859_2 | Central and East European (Latin2) |
| wx.wxFONTENCODING_ISO8859_3 | Esperanto (Latin3) |
| wx.wxFONTENCODING_ISO8859_4 | Baltic (old) (Latin4) |
| wx.wxFONTENCODING_ISO8859_5 | Cyrillic |
| wx.wxFONTENCODING_ISO8859_6 | Arabic |
| wx.wxFONTENCODING_ISO8859_7 | Greek |
| wx.wxFONTENCODING_ISO8859_8 | Hebrew |
| wx.wxFONTENCODING_ISO8859_9 | Turkish (Latin5) |
| wx.wxFONTENCODING_ISO8859_10 | Variation of Latin4 (Latin6) |
| wx.wxFONTENCODING_ISO8859_11 | Thai |
| wx.wxFONTENCODING_ISO8859_13 | Baltic (Latin7) |
| wx.wxFONTENCODING_ISO8859_14 | Latin8 |
| wx.wxFONTENCODING_ISO8859_15 | Latin9 (a.k.a. Latin0, includes euro) |
| wx.wxFONTENCODING_KOI8 | KOI8 Russian |
| wx.wxFONTENCODING_KOI8_U | KOI8 Ukrainian |
| wx.wxFONTENCODING_ALTERNATIVE | same as MS-DOS CP866 |
| wx.wxFONTENCODING_BULGARIAN | used under Linux in Bulgaria |
| wx.wxFONTENCODING_CP437 | original MS-DOS codepage |
| wx.wxFONTENCODING_CP850 | CP437 merged with Latin1 |
| wx.wxFONTENCODING_CP852 | CP437 merged with Latin2 |
| wx.wxFONTENCODING_CP855 | another cyrillic encoding |
| wx.wxFONTENCODING_CP866 | and another one and for Windows |
| wx.wxFONTENCODING_CP874 | WinThai |
| wx.wxFONTENCODING_CP932 | Japanese (shift-JIS) |
| wx.wxFONTENCODING_CP936 | Chinese simplified (GB) |
| wx.wxFONTENCODING_CP949 | Korean (Hangul charset) |
| wx.wxFONTENCODING_CP950 | Chinese (traditional - Big5) |
| wx.wxFONTENCODING_CP1250 | WinLatin2 |
| wx.wxFONTENCODING_CP1251 | WinCyrillic |
| wx.wxFONTENCODING_CP1252 | WinLatin1 |
| wx.wxFONTENCODING_CP1253 | WinGreek (8859-7) |
| wx.wxFONTENCODING_CP1254 | WinTurkish |
| wx.wxFONTENCODING_CP1255 | WinHebrew |
| wx.wxFONTENCODING_CP1256 | WinArabic |
| wx.wxFONTENCODING_CP1257 | WinBaltic (same as Latin 7) |
| wx.wxFONTENCODING_UTF7 | UTF-7 Unicode encoding |
| wx.wxFONTENCODING_UTF8 | UTF-8 Unicode encoding |
| wx.wxFONTENCODING_EUC_JP | Extended Unix Codepage for Japanese |
| wx.wxFONTENCODING_UTF16BE | UTF-16 Big Endian Unicode encoding |
| wx.wxFONTENCODING_UTF16LE | UTF-16 Little Endian Unicode encoding |
| wx.wxFONTENCODING_UTF32BE | UTF-32 Big Endian Unicode encoding |
| wx.wxFONTENCODING_UTF32LE | UTF-32 Little Endian Unicode encoding |
This means that they should be outside any other function definition.
Define a variable name for use in the ‘set variable’ dialog.
varName = variable name
units. One of the following: sc.unitTEXT, sc.unitLINEAR, sc.unitANGULAR,
sc.unitFEED, sc.unitRPM, sc.unitTIME, sc.unitPERCENT, sc.unitPITCH,
sc.unit0DECPLACE, sc.unit1DECPLACE, sc.unit2DECPLACE, ,sc.unit3DECPLACE,
sc.unit4DECPLACE note the unitxDECPLACE units display
a number without units with a precision of the given number of decimal
places
min minimum value (ignored for text)
max maximum value (ignored for text)
Adds an option to the post options.
caption is a label that is displayed next to the input box.
The rest of the syntax is as DefineVariable above.
Show an options dialog containing the options defined using
DefineOption.
Caption is displayed in the dialog box title.
If no options have been defined this function has no effect.
Adds an extra parameter to a tool definition.
toolClass is the tool class name. See the toolClass variable for a
description of tool classes
default is the default value. Note that values are always in METRIC for
linear units, RADIANS for angular units and a decimal fraction for
percentage e.g 0.1 = 10%
The rest of the syntax is as DefineVariable above.
Force the file extension. Extension should not include a leading dot.
This overrides the user’s selection
e.g post.ForceExtension(“tap”)
Set an option. The available options are:
To combine options add them. For instance:
Post.SetOptions(post.DISABLE_TOOLCHANGE + post.DISABLE_ROTARY)
Current X,Y,Z coordinates.
X,Y,Z coordinates to move to. These variables are only valid for movement events.
Angle of current circular move in radians. Positive = clockwise. 0 = 12 o'clock. This variable is only valid for circular moves
Center X,Y coordinates of current circular move. This variable is only valid for circular moves
Safe clearance above the cut start. Rapids should be down to this then move at feed rate down to the cut start.
drillling and tapping start depth
drill and tapping depth
Drill peck depth
Drill retract amount
Rapid height
Z coordinate of material top (always 0)
Current feed rate
Plunge rate for this tool. Use for verification purposes only - feedrate is updated to reflect plunge rate when plunging.
This variable is always 1/25.4
This variable is always 1
for inch post output this variable is 1/25.4 otherwise it is 1
Current tool number
The number of the next tool to be pre-selected. -1 if there are no more tools needed
Current line number
Current spindle speed
G-code file name
G-code file name without path
G-code file path
Part name
Current tool name
Current operation name
date that post processing was started
time that post processing was started
Post processor file name
preheat delay (flame tool only)
pierce delay (jet tool only)
pierce height (jet tool only)
cut height (jet tool only)
end of cut delay (jet tool only)
Laser power (laser and waterjet tools only)
Bottom left coordinates of material
Top right of material
Material thickness
Height of material above the table
Tool diameter
Tool length
Tool flute length
Tool length offset
Tool V angle or drill point angle in radians (only valid for V cutters or drills). Multiply by 57.29577951308 to convert to degrees
-1 = unknown
0=mill/router
1=drill
2=V cutter
3=plasma
4=insert g-code
5=automatic tap
6=rigid tap
7=flame
8=water
9=laser
MillTool=mill/router
DrillTool=drill
VTool=V cutter
PlasmaTool=plasma
CodeTool=insert g-code
TapHeadTooll=automatic tap
TapTool=rigid tap
FlameTool=flame
WaterTool=water
LaserTool=laser
ThreadMillTool=Thread mill
MarkerTool=Plate marker
One of the following:
VariableOperation
MoveOperation
CodeOperation
JetOperation
DrillOperation
TapOperation
ContourOperation
PocketOperation
ZigzagPocketOperation
ThreadMillOperation
Tapping feed per rev. Only used by the autotap() and rigidtap() events
Tapping underfeed. Only used by the autotap() and rigidtap() events. 0.5 = 50%, 1= 100% etc
Tapping head axial travel. Only used by autotap() event
Tapping head reverse multiplier. Only used by autotap() event
Text for the comment() event
length of the next cut path
1 if the cut path is closed, 0 if it is open.
Defines if this is a leadin/leadout
0: Not a leadin/leadout.
1: A leadin.
2: A leadout.
-1 = CCW, 0 = off, 1 = CW
the index(starting from 0) of the current part
the index(starting from 0) of the current operation
The depth of cut. 0 if the tool does not exist or this operation does not use a tool.
All of SheetCam's internal variables are available in the var namespace. For instance :
var.ClampClearanceHeight would give the material thickness. You can see all of the available variables using the variable monitor (View->variable monitor)
math. See http://lua-users.org/wiki/MathLibraryTutorial for more details. This library has been extended to add the following functions:
math.hypot(x,y). This is equivalent to math.sqrt((x*x) + (y*y))
math.toint(n). Returns the integer value of n.
string. See http://lua-users.org/wiki/StringsTutorial for more details.
os Seehttp://lua-users.org/wiki/OsLibraryTutorial for more details
Also all of the wxLua plugin functions are available. See the plugin documentation.