gcmc - G-Code Meta Compiler
Function reference
Vector functions
integer
count
(
vector:arg
)
integer
count
(
vectorlist:arg
)
arg |
vector |
|
Vector coordinates to count. |
arg |
vectorlist |
|
Vectors to count. |
Returns number of coordinates or the number of vectors
in arg for argument types vector
and vectorlist respectively.
float
length
(
vector:arg
)
arg |
vector |
[distance] |
Vector for length determination. |
Returns the length of
arg calculated as
sqrt(
arg *
arg).
vector
normalize
(
vector:arg
)
arg |
vector |
[distance] |
Vector for normalization. |
Returns the scaled version of
arg such that
length(
normalize(
arg))
equals 1.0. The resulting normalized vector has no units associated.
vector
reverse
(
vector:arg
)
vectorlist
reverse
(
vectorlist:arg
)
arg |
vector |
|
Vector to reverse. |
arg |
vectorlist |
|
Vectorlist to reverse. |
Returns the reversed version of
arg such that all coordinates of a vector or
vectors of a vectorlist are reversed. I.e. the first becomes the last, etc..
vector
position
(
)
vector
position
(
scalar:naxes
)
naxes |
scalar |
|
Maximum number of axis to return. Must be ≥ 1 and less or equal the number of active axes (6 or 9). |
Returns the current absolute position as a vector. The
number of coordinates returned is 6 or 9, depending whether 9-axis mode is
enabled on the command-line. The optional argument naxes
limits the number of axis returned.
vector
rotate_xy
(
vector:arg,
scalar:angle
)
vector
rotate_xz
(
vector:arg,
scalar:angle
)
vector
rotate_yz
(
vector:arg,
scalar:angle
)
vectorlist
rotate_xy
(
vectorlist:arg,
scalar:angle
)
vectorlist
rotate_xz
(
vectorlist:arg,
scalar:angle
)
vectorlist
rotate_yz
(
vectorlist:arg,
scalar:angle
)
arg |
vector |
[distance] |
Vector to rotate. |
arg |
vectorlist |
[distance] |
Vectors to rotate. |
angle |
scalar |
[angular] |
Angle of rotation. |
Returns arg rotated by angle.
The plane of rotation is XY, XZ or YZ for respective functions. If arg
is of type vectorlist, then each containing vector is
rotated and a vectorlist is returned.
vector
scale
(
vector:arg,
vector:mult
)
vectorlist
scale
(
vectorlist:arg,
vector:mult
)
arg |
vector |
|
Vector to scale. |
arg |
vectorlist |
|
Vectors to scale. |
mult |
vector |
|
Multiplication factors. |
Multiply arg with coefficients from
mult. Where mult can be seen
as the primary diagonal of a multiplication matrix. If the first argument is of type
vectorlist, then each containing vector of arg
is iterated and scaled separately.
vector
head
(
vector:arg,
scalar:nr
)
vectorlist
head
(
vectorlist:arg,
scalar:nr
)
arg |
vector |
|
Vector to take coordinates from. |
arg |
vectorlist |
|
Vectorlist to take vectors from. |
nr |
scalar |
[no unit] |
Number of elements to take if positive and number of elements to leave when negative. |
Returns the first
nr number
of entries from
arg as a vector or vectorlist.
If
arg is a
vector and has fewer than
nr entries, then the result is padded with
undef until the result
has
nr entries.
If
arg is a
vectorlist and has fewer than
nr entries, then only the available entries are returned.
If
nr is negative then a
vector/
vectorlist is returned with
|
nr| fewer entries than
count(
arg).
vector
tail
(
vector:arg,
scalar:nr
)
vectorlist
tail
(
vectorlist:arg,
scalar:nr
)
arg |
vector |
|
Vector to take coordinates from. |
arg |
vectorlist |
|
Vectorlist to take vectors from. |
nr |
scalar |
[no unit] |
Number of elements to take if positive and number of elements to leave when negative. |
Returns the last
nr number
of entries from
arg as a vector or vectorlist.
If
arg is a
vector and has fewer than
nr entries, then the result is prepended with
undef until the
result has
nr entries.
If
arg is a
vectorlst and has fewer than
nr entries, then only the available entries are returned.
If
nr is negative then a
vector/
vectorlist is returned with
|
nr| fewer entries than
count(
arg).
Math functions
scalar
abs
(
scalar:val
)
Return the absolute value of val. Units are preserved.
float
acos
(
scalar:val
)
val |
scalar |
[no unit] |
A number from -1.0 to 1.0. |
Return the arc-cosine of val in radians.
float
asin
(
scalar:val
)
val |
scalar |
[no unit] |
A number from -1.0 to 1.0. |
Return the arc-sine of val in radians.
float
atan
(
scalar:y,
scalar:x
)
y |
scalar |
[distance] |
Any number. |
x |
scalar |
[distance] |
Any number. |
Return the arc-tangent of y/x in radians.
float
ceil
(
scalar:val
)
Return the smallest integral number not smaller than
val.
Units are preserved. Examples:
ceil(0.5) → 1.0
ceil(-0.5) → 0.0
float
cos
(
scalar:angle
)
angle |
scalar |
[angular] |
Any number. |
Return the cosine of angle.
The returned value has no units associated.
float
exp
(
scalar:val
)
Return the exponentiation of val with base e.
The returned value has no units associated.
float
floor
(
scalar:val
)
Return the largest integral number not greater than
val.
Units are preserved. Examples:
floor(0.5) → 0.0
floor(-0.5) → -1.0
float
log10
(
scalar:val
)
float
log2
(
scalar:val
)
float
loge
(
scalar:val
)
val |
scalar |
|
Any number greater than zero. |
Return the logarithm of val with base 10, 2 and e respectively.
The returned value has no units associated.
float
pi
(
)
Returns pi (3.141529.....).
float
pow
(
scalar:x,
scalar:y
)
x |
scalar |
|
Any number. |
y |
scalar |
[no unit] |
Any number. |
Return the x raised to the power y.
The returned value has no units associated.
float
round
(
scalar:val
)
Return
val rounded with half-way cases rounded away from zero.
Units are preserved. Examples:
round(0.7) → 1.0
round(0.5) → 1.0
round(0.4) → 0.0
round(-0.4) → 0.0
round(-0.5) → -1.0
round(-0.7) → -1.0
float
sin
(
scalar:angle
)
angle |
scalar |
[angular] |
Any number. |
Return the sine of angle.
The returned value has no units associated.
float
sqrt
(
scalar:val
)
val |
scalar |
|
Any number greater or equal zero. |
Return the square root of val.
The returned value has no units associated.
float
tan
(
scalar:angle
)
angle |
scalar |
[angular] |
Any number. |
Return the tangent of angle.
The returned value has no units associated.
Conversion functions
scalar
to_deg
(
scalar:arg
)
vector
to_deg
(
vector:arg
)
vectorlist
to_deg
(
vectorlist:arg
)
arg |
scalar |
[angular] |
Any number. |
arg |
vector |
[angular] |
|
arg |
vectorlist |
[angular] |
|
Returns
arg /
pi() * 180.0 (deg)
if
arg has unit radians, returns
arg otherwise. Vectors and vectorlists are iterated
over all scalars contained in them and return vector or vectorlist.
Conversions:
1 | → 1deg |
1mm | → Warning, 1deg |
1in | → Warning, 1deg |
1deg | → 1deg |
1rad | → 57.29577951deg |
undef | → undef |
scalar
to_rad
(
scalar:arg
)
vector
to_rad
(
vector:arg
)
vectorlist
to_rad
(
vectorlist:arg
)
arg |
scalar |
[angular] |
Any number. |
arg |
vector |
[angular] |
|
arg |
vectorlist |
[angular] |
|
Returns
arg *
pi() / 180.0 (rad)
if
arg has unit degrees, returns
arg otherwise. Vectors and vectorlists are iterated
over all scalars contained in them and return vector or vectorlist.
Conversions:
1 | → 1rad |
1mm | → Warning, 1rad |
1in | → Warning, 1rad |
1deg | → 0.01745329rad |
1rad | → 1rad |
undef | → undef |
scalar
to_in
(
scalar:arg
)
vector
to_in
(
vector:arg
)
vectorlist
to_in
(
vectorlist:arg
)
arg |
scalar |
[distance] |
Any number. |
arg |
vector |
[distance] |
|
arg |
vectorlist |
[distance] |
|
Returns
arg coverted to inch.
If
arg has no units or already is in inch, then no
conversion is performed. Vectors and vectorlists are iterated over all scalars
contained in them and return vector or vectorlist. Conversions:
1 | → 1in |
1mm | → 0.03937008in |
1in | → 1in |
1deg | → Warning, 1in |
1rad | → Warning, 1in |
undef | → undef |
scalar
to_mm
(
scalar:arg
)
vector
to_mm
(
vector:arg
)
vectorlist
to_mm
(
vectorlist:arg
)
arg |
scalar |
[distance] |
Any number. |
arg |
vector |
[distance] |
|
arg |
vectorlist |
[distance] |
|
Returns
arg coverted to mm.
If
arg has no units or already is in mm, then no
conversion is performed. Vectors and vectorlists are iterated over all scalars
contained in them and return vector or vectorlist. Conversions:
1 | → 1mm |
1mm | → 1mm |
1in | → 25.4mm |
1deg | → Warning, 1mm |
1rad | → Warning, 1mm |
undef | → undef |
scalar
to_none
(
scalar:arg
)
vector
to_none
(
vector:arg
)
vectorlist
to_none
(
vectorlist:arg
)
arg |
scalar |
|
Any number. |
arg |
vector |
|
|
arg |
vectorlist |
|
|
Returns
arg stripping any
associated units. Vectors and vectorlists are iterated over all scalars
contained in them and return vector or vectorlist. Conversions:
1 | → 1 |
1mm | → 1 |
1in | → 1 |
1deg | → 1 |
1rad | → 1 |
undef | → undef |
float
float
(
scalar:arg
)
vector
float
(
vector:arg
)
vectorlist
float
(
vectorlist:arg
)
arg |
scalar |
|
Any number. |
arg |
vector |
|
|
arg |
vectorlist |
|
|
Convert arg to floating
point. Vectors and vectorlists are iterated over all scalars contained in them
and return vector or vectorlist. Undef is returned as undef and units are preserved.
integer
int
(
scalar:arg
)
vector
int
(
vector:arg
)
vectorlist
int
(
vectorlist:arg
)
arg |
scalar |
|
Any number. |
arg |
vector |
|
|
arg |
vectorlist |
|
|
Convert arg to integer.
Floating point numbers are converted by truncation. Vectors and vectorlists
are iterated over all scalars contained in them and return vector or
vectorlist. Undef is returned as undef and units are preserved.
undef
literal
(
...
)
Outputs all arguments as text into the output.
Note that the
literal() function does
not terminate the line with a newline and you must provide the newline as a
string argument if the line must be terminated. The SVG and DXF backends ignore
this function.
Do
not use the
literal()
function lightly. It is extremely powerful but also very dangerous. It will
make your source a lot more unreadable and may introduce side-effects that you
did not intend.
If you simply want to embed a comment or a G-code debug statement, you should
be using the
comment() function
instead because it is much safer to use.
undef
(
...
)
Outputs all arguments as a G-code comment into
the output. The
comment() function
will prepend a '(' and append a ')' including newline automatically.
undef
message
(
...
)
undef
warning
(
...
)
undef
error
(
...
)
Outputs all arguments as text to the console. Origin
file and line number is prepended and a newline is appended if none in the last
argument. The gcmc executable will return non-zero if error() is
executed.
Query functions
integer
isfloat
(
arg
)
integer
isint
(
arg
)
integer
isscalar
(
arg
)
integer
isstring
(
arg
)
integer
isundef
(
arg
)
integer
isvector
(
arg
)
integer
isvectorlist
(
arg
)
These functions return an integer (boolean) which is
true (1) if
arg is of tested type and false (0)
otherwise.
Function
isscalar(
arg) equals
"
isint(
arg) ||
isfloat(
arg)".
integer
isangle
(
scalar:arg
)
integer
isdistance
(
scalar:arg
)
integer
isdeg
(
scalar:arg
)
integer
israd
(
scalar:arg
)
integer
ismm
(
scalar:arg
)
integer
isinch
(
scalar:arg
)
integer
isnone
(
scalar:arg
)
These functions return an integer (boolean) which is
true (1) if
arg has the tested units and false (0)
otherwise.
Function
isangle(
arg) equals
"
israd(
arg) ||
isdeg(
arg)".
Function
isdistance(
arg) equals
"
ismm(
arg) ||
isinch(
arg)".
integer
isgcode
(
)
integer
isdxf
(
)
integer
issvg
(
)
These function return an integer (boolean) which is
true (1) is the current output format is set as queried and false (0)
otherwise.
integer
isdefined
(
string:var
)
Returns an integer (boolean) which is true (1) if a
variable with name var is currently defined in either
local or global scope and false (0) otherwise.
integer
isrelative
(
)
Returns an integer (boolean) which is true (1) if the
output is set to relative mode (-r option) and false (0) otherwise.
Movement functions
vector
arc_ccw
(
vector:endpoint,
scalar:radius
)
vector
arc_ccw
(
vector:endpoint,
scalar:radius,
scalar:turns
)
vector
arc_ccw_r
(
vector:endpoint,
scalar:radius
)
vector
arc_ccw_r
(
vector:endpoint,
scalar:radius,
scalar:turns
)
vector
arc_cw
(
vector:endpoint,
scalar:radius
)
vector
arc_cw
(
vector:endpoint,
scalar:radius,
scalar:turns
)
vector
arc_cw_r
(
vector:endpoint,
scalar:radius
)
vector
arc_cw_r
(
vector:endpoint,
scalar:radius,
scalar:turns
)
endpoint |
vector |
[distance] |
Endpoint coordinate of the arc. |
radius |
scalar |
[angular] |
Radius of the arc. Radius must not be zero. |
turns |
scalar |
[no units] |
Number of turns to perform. Turns should be integer and must be larger than zero. |
Perform a counter clockwise (ccw) or clockwise (cw)
arc from the current position to
endpoint with radius
radius. The arc will be shortest angular movement with
positive radius and largest angular movement with negative radius. Optional
turns sets the number of turns to perform. Functions
arc_ccw_r() and
arc_cw_r()
use relative addressing. The argument endpoint returned.
undef
circle_ccw
(
vector:centerpoint
)
undef
circle_ccw
(
vector:centerpoint,
scalar:turns
)
undef
circle_ccw
(
scalar:radius,
scalar:angle
)
undef
circle_ccw_r
(
vector:centerpoint
)
undef
circle_ccw_r
(
vector:centerpoint,
scalar:turns
)
undef
circle_cw
(
vector:centerpoint
)
undef
circle_cw
(
vector:centerpoint,
scalar:turns
)
undef
circle_cw
(
scalar:radius,
scalar:angle,
scalar:turns
)
undef
circle_cw_r
(
vector:centerpoint
)
undef
circle_cw_r
(
vector:centerpoint,
scalar:turns
)
centerpoint |
vector |
[distance] |
Coordinate of the center of the circle. |
radius |
scalar |
[distance] |
Radius of the circle. |
angle |
scalar |
[angular] |
Angle of the vector from the current point to the center of the circle. |
turns |
scalar |
[no units] |
Number of turns to perform. Turns should be integer and must be larger than zero. |
Perform a clockwise (cw) or counter clockwise (ccw)
circle with radius
length(
centerpoint)
for the
circle_cw_r and
circle_ccw_r
functions and radius
length(
centerpoint-
position())
for the
circle_cw and
circle_ccw
functions and where
centerpoint is the center point or
the circle. Optional
turns sets the number of turns
to perform. The specified
centerpoint is a relative
position for the
circle_cw_r and
circle_ccw_r
functions and an absolute coordinate for
circle_cw
and
circle_ccw. The non-active plane coordinate
may be used to create a helical movement.
The scalar form performs a clockwise (cw) or counter clockwise (ccw)
circle with radius
radius. The center point is located
at a vector calculated from the current position of length
radius
and angled at
angle. Optional
turns
sets the number of turns to perform. The circle is always performed within the
active plane.
undef
drill
(
vector:drillpoint,
scalar:retract,
scalar:increment
)
undef
drill
(
vector:drillpoint,
scalar:retract,
scalar:increment,
scalar:repeat
)
drillpoint |
vector |
[distance] |
Endpoint of the drill-hole. |
retract |
scalar |
[distance] |
Endpoint of the Z-axis after drilling. |
increment |
scalar |
[distance] |
Increments of the Z-axis before retracting temporarily. |
repeat |
scalar |
[no units] |
Number of repeats of the drill-cycle. Repeats must be larger the zero. |
Perform a drill-cycle to drillpoint
with retract denoting the retract (Z) position after the cycle,
increment the Z-axis increments and optional
repeat repeats.
vector
goto
(
vector:endpoint
)
vector
goto_r
(
vector:endpoint
)
endpoint |
vector |
[distance/anglular] |
Endpoint of the rapid |
Rapid move (G0) to position
endpoint.
The
endpoint position is an absolute position for
goto() and a relative position for
goto_r().
The
endpoint vector may consist of up to nine
coordinates and are interpreted for axis XYZABCUVW respectively. Coordinates
for axes XYZ and UVW are interpreted with distance units and axes ABC are
interpreted with angular units. The absolute position before the movement is
returned.
vector
move
(
vector:endpoint
)
vector
move
(
vector:endpoint,
scalar:rate
)
vector
move_r
(
vector:endpoint
)
vector
move_r
(
vector:endpoint,
scalar:rate
)
endpoint |
vector |
[distance/angular] |
Endpoint of the rapid |
rate |
scalar |
[distance] |
Maximum feed rate override; must be larger than zero. |
Feed move (G1) to position
endpoint.
The
endpoint position is an absolute position for
move() and a relative position for
move_r().
The optional
rate argument sets the feed override
(F-parameter) for this move and is interpreted in the context of the
feedmode() setting.
The
endpoint vector may consist of up to nine
coordinates and are interpreted for axis XYZABCUVW respectively. Coordinates
for axes XYZ and UVW are interpreted with distance units and axes ABC are
interpreted with angular units. The absolute position before the movement is
returned.
integer
plane
(
scalar:mode
)
integer
plane
(
string:mode
)
mode |
scalar |
[no units] |
Active cutting plane (see below). |
mode |
string |
|
Active cutting plane (see below). Mode is case-insensitive. |
Set the operational plane to
mode, which may be one of the following:
| scalar | string | Description |
• | 0 | "XY" | use XY plane (G17) (default) |
• | 1 | "XZ" | use XZ plane (G18) |
• | 2 | "YZ" | use YZ plane (G19) |
The previously active plane is returned.
G-code functions
undef
coolant
(
scalar:state
)
undef
coolant
(
string:state
)
state |
scalar |
[no units] |
Coolant state (see below). |
state |
string |
|
Coolant state (see below). State is case-insensitive. |
Enable/disable coolant (M7, M8, M9). Argument
state must be one of:
| scalar | string | Description |
• | 0 | "off" | coolant off |
• | 1 | "mist" | coolant mist |
• | 2 | "flood" | coolant flood |
• | 3 | "mist+flood" | coolant mist+flood |
undef
dwell
(
scalar:time
)
time |
scalar |
[no units] |
Time to stay at the current position. Time must be larger or equal zero. |
Pause (G4) for time seconds.
undef
feedmode
(
scalar:mode
)
undef
feedmode
(
string:mode
)
mode |
scalar |
[no units] |
Feed mode (see below). |
mode |
string |
|
Feed mode (see below). Mode is case-insensitive. |
Feed rate mode setting to one of the following:
| scalar | string | Description |
• | 0 | "inverse" | Inverse Time Mode (G93) |
• | 1 | "upm" | Units Per Minute (G94) (default) |
• | 2 | "upr" | Units Per Revolution (G95) |
The time based units interpretation depend on the command-line setting whether
metric (mm/s) or imperial (in/s).
undef
feedrate
(
scalar:rate
)
rate |
scalar |
[distance] |
Feed rate; must be larger than zero. |
Set feedrate (F) to
rate. The
rate is interpreted following the setting of the
feedmode() function.
undef
spindle
(
scalar:speed
)
speed |
scalar |
[no units] |
Spindle speed (see below). |
Enable/disable spindle turning and set the spindle's speed, where
speed should be:
| scalar | Description |
• | <0 | spindle counter clockwise (M4) |
• | 0 | spindle off (M5) |
• | >0 | spindle clockwise (M3) |
The spindle speed is set with an S command to
abs(
speed).
undef
spindlespeed
(
scalar:speed
)
speed |
scalar |
[no units] |
Spindle speed. Speed must be larger or equal zero. |
Set the spindle's speed (S) to speed.
undef
toolchange
(
scalar:toolnr
)
undef
toolchange
(
scalar:toolnr,
scalar:setoffs
)
toolnr |
scalar |
[no units] |
Tool number to change to. Toolnr should be integer and must be larger or equal zero. |
setoffs |
scalar |
[boolean] |
Set tool offset. |
Change tool (T) to toolnr.
An M6 code is also emitted to perform the actual tool change.
If setoffs evaluates to true, then a G43 code is
also emitted to set the tool's offset.
SVG functions
undef
svg_closepath
(
)
Emits a close-path SVG command (Z) to the path being
output, such that the current shape becomes closed.
DXF functions
No specific DXF functions yet.