gcmc - G-Code Meta Compiler

Function reference


Vector functions

count ( vector:arg )
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.

length ( vector:arg )
arg vector [distance] Vector for length determination.
Returns the length of arg calculated as sqrt(arg * arg).

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.

position ( )
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.

rotate_xy ( vector:arg, scalar:angle )
rotate_xy ( vectorlist:arg, scalar:angle )
rotate_xz ( vector:arg, scalar:angle )
rotate_xz ( vectorlist:arg, scalar:angle )
rotate_yz ( vector:arg, scalar:angle )
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.

scale ( vector:arg, vector:mult )
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.

head ( vector:arg, scalar:nr )
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. Nr should be integer and must be larger or equal zero.
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 vectorlst and has fewer than nr entries, then only the available entries are returned.

tail ( vector:arg, scalar:nr )
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. Nr should be integer and must be larger or equal zero.
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.

Math functions

abs ( scalar:val )
val scalar   Any number.
Return the absolute value of val. Units are preserved.

acos ( scalar:val )
val scalar [no unit] A number from -1.0 to 1.0.
Return the arc-cosine of val in radians.

asin ( scalar:val )
val scalar [no unit] A number from -1.0 to 1.0.
Return the arc-sine of val in radians.

atan ( scalar:y, scalar:x )
y scalar [distance] Any number.
x scalar [distance] Any number.
Return the arc-tangent of y/x in radians.

ceil ( scalar:val )
val scalar   Any number.
Return the smallest integral number not smaller than val. Units are preserved. Examples:
ceil(0.5) → 1.0
ceil(-0.5) → 0.0

cos ( scalar:angle )
angle scalar [angular] Any number.
Return the cosine of angle. The returned value has no units associated.

exp ( scalar:val )
val scalar   Any number.
Return the exponentiation of val with base e. The returned value has no units associated.

floor ( scalar:val )
val scalar   Any number.
Return the largest integral number not greater than val. Units are preserved. Examples:
floor(0.5) → 0.0
floor(-0.5) → -1.0

log10 ( scalar:val )
log2 ( scalar:val )
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.

pi ( )
Returns pi (3.141529.....).

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.

round ( scalar:val )
val scalar   Any number.
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

sin ( scalar:angle )
angle scalar [angular] Any number.
Return the sine of angle. The returned value has no units associated.

sqrt ( scalar:val )
val scalar   Any number greater or equal zero.
Return the square root of val. The returned value has no units associated.

tan ( scalar:angle )
angle scalar [angular] Any number.
Return the tangent of angle. The returned value has no units associated.

Conversion functions

to_deg ( scalar:arg )
to_deg ( vector:arg )
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

to_rad ( scalar:arg )
to_rad ( vector:arg )
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

to_in ( scalar:arg )
to_in ( vector:arg )
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

to_mm ( scalar:arg )
to_mm ( vector:arg )
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

to_none ( scalar:arg )
to_none ( vector:arg )
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 ( scalar:arg )
float ( vector:arg )
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.

int ( scalar:arg )
int ( vector:arg )
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.

literal ( ... )
...     Any type of argument
Outputs all arguments as text into the output. The SVG and DXF backends ignore this function.

message ( ... )
warning ( ... )
error ( ... )
...     Any type of argument
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

isfloat ( arg )
isint ( arg )
isscalar ( arg )
isstring ( arg )
isundef ( arg )
isvector ( arg )
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)".

isangle ( scalar:arg )
isdistance ( scalar:arg )
isdeg ( scalar:arg )
israd ( scalar:arg )
ismm ( scalar:arg )
isinch ( scalar:arg )
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)".

isgcode ( )
isdxf ( )
issvg ( )
These function return an integer (boolean) which is true (1) is the current output format is set as queried and false (0) otherwise.

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.

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

arc_ccw ( vector:endpoint, scalar:radius )
arc_ccw ( vector:endpoint, scalar:radius, scalar:turns )
arc_ccw_r ( vector:endpoint, scalar:radius )
arc_ccw_r ( vector:endpoint, scalar:radius, scalar:turns )
arc_cw ( vector:endpoint, scalar:radius )
arc_cw ( vector:endpoint, scalar:radius, scalar:turns )
arc_cw_r ( vector:endpoint, scalar:radius )
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.

circle_ccw ( vector:centerpoint )
circle_ccw ( vector:centerpoint, scalar:turns )
circle_ccw ( scalar:radius, scalar:angle )
circle_ccw_r ( vector:centerpoint )
circle_ccw_r ( vector:centerpoint, scalar:turns )
circle_cw ( vector:centerpoint )
circle_cw ( vector:centerpoint, scalar:turns )
circle_cw ( scalar:radius, scalar:angle, scalar:turns )
circle_cw_r ( vector:centerpoint )
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.

drill ( vector:drillpoint, scalar:retract, scalar:increment )
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.

goto ( vector:endpoint )
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.

move ( vector:endpoint )
move ( vector:endpoint, scalar:rate )
move_r ( vector:endpoint )
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.

plane ( scalar:mode )
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:
 scalarstringDescription
0"XY"use XY plane (G17) (default)
1"XZ"use XZ plane (G18)
2"YZ"use YZ plane (G19)

G-code functions

coolant ( scalar:state )
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:
 scalarstringDescription
0"off"coolant off
1"mist"coolant mist
2"flood"coolant flood
3"mist+flood"coolant mist+flood

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.

feedmode ( scalar:mode )
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:
 scalarstringDescription
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).

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.

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:
 scalarDescription
<0spindle counter clockwise (M4)
0spindle off (M5)
>0spindle clockwise (M3)
The spindle speed is set with an S command to abs(speed).

spindlespeed ( scalar:speed )
speed scalar [no units] Spindle speed. Speed must be larger or equal zero.
Set the spindle's speed (S) to speed.

toolchange ( scalar:toolnr )
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. If setoffs evaluates to true, then a G43 code is also emitted to set the tool's offset.

SVG functions

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.