Professional Documents
Culture Documents
MP Ref Guide - Vol 1
MP Ref Guide - Vol 1
1
Version 9
MP Post Processor
Reference Guide
V olume 1
Basic MP Post Processing
sample text
LEGACY DOC -- VERSION 9.1
Volume 1, Basic MP Post Processor Programming. Presents basic concepts, principles, and rules
you must understand to modify an MP post processor: postblocks, variables, formulas, functions, NCI
Gcode, drill cycles, canned text, etc. If you are planning to modify an MP post processor or just want
to understand how it is organized, you should read this volume.
Volume 2, Advanced MP Language Concepts and Applications. Describes how the MP language
implements special applications including subprograms, mill/turn applications, lathe canned and
threading cycles, and wire processing. Also discusses how MP language uses buffer files, handles
intersections, and breaks up motion.
Volume 3, MP Post Language Reference. Contains detailed descriptions of syntax and dependencies
of postblocks, variables, formulas, NCI Gcode, and parameters.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 1-1
LEGACY DOC -- VERSION 9.1
Additional resources
Please email any comments, suggests and/or corrections to the MP Post documentation to
posts@mastercam.com
For an ongoing discussion of Mastercam-related topics, visit the eMastercam online forum at
www.emastercam.com
1-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
This section presents an overview of the MP post processing language. It is intended to provide
direction for someone who wants to modify an existing MP post processor. It is not intended to teach
you how to write a post processor.
To be able to modify a post processor and understand the material in this Reference Guide, you should
have a basic understanding of how a computer program is structured and operates. As a minimum, you
should understand:
how the syntax of a programming language affects program operation
the use of variables to store and pass information
branching within a program based on conditional and Boolean expressions
jumping within a program through subroutine calls
mathematical expressions and formulas
nesting in formulas and a program language structure
general debugging techniques
In addition, you must be familiar with Mastercam and have a thorough understanding of NC code
(Gcode) and the specific requirements of the machine tool and control for which you want to create a
post processor.
Note: This Reference Guide does not describe “legacy posts”, also called family posts, which are no
longer supported by Mastercam. These posts are MS-DOS® based and can be identified by their use
of .COM executable files.
What is an MP post?
An MP (Mastercam Post) post processor is a combination of three (or four) files:
the post processor customization file (.PST)
the post processor customization text file (.TXT)
the post processor executable file (.DLL)
the post processor ‘binned file (.PSB) this is usually only with some “high end” posts
The MP post processor customization file (*.PST) is written in CNC Software, Inc.’s proprietary
scripting language, the MP language, which is a programming language designed to enable someone
with limited programming experience to customize a post processor for use with Mastercam. The MP
post processor executable (*.DLL) is a program that interprets the MP post customization files (*.PST
and *.PSB), processes the Mastercam intermediate file (*.NCI) and produces the NC output file
(*.NC).
The MP post processor is a combination of a configuration-type post, where all output is controlled in
the post executable by a series of questions the user answers to control output, and a language-based
post. Although a language-based is more difficult to use than configuration-type post , it is also more
powerful because there are no restrictions placed on the post writer by the capability of the post
executable. Using the MP language, the post writer can accomplish practically any task in the post
processor.
The MP post processor needs three main files:
A post customization file (.PST), which is an ASCII text file containing MP language instructions
that define exactly what NC code will be produced and its format.
A post executable file (.DLL), which can be considered the “engine” of the post processor. It
reads the post customization file (.PST), reads the intermediate file (.NCI) and writes the NC file.
You do not modify the post executable file but you can control some of its behavior through the
post customization file.
The Mastercam intermediate file (.NCI), which is the generic NCI file format generated from the
toolpaths that are created in Mastercam. Continuing the analogy, this is the fuel for the engine.
The information that is read from the NCI file is converted by the post process operation into NC
code.
There are two (optional) additional files:
A post text file (.TXT) file, which is an ASCII text file containing custom text prompts that allow
the post to alter (some) of the text data displayed inside of Mastercam.
A post ‘bin file (.PSB) file, which is a BINARY file containing some of the information from the
original .PST text file. This allows the post writer to protect sections of the .PST in a non-readable
(by humans) binary file format. This is usually only with some “high end” posts.
Definition:
g (NCI Gcode)
1 2 3 4 5 6 (six parameters)
Where:
g
123456
g 0: Linear Move at Rapid Feed Rate (NCI Gcode)
1 Cutter Compensation
2 Final X position
3 Final Y position
4 Final Z position
5 Feed rate settings
6 Contour flag
The post executable applies these parameter values to the appropriate predefined MP variables,
performs additional calculations to generate values for other predefined variables that are commonly
used for the NCI Gcode type being processed, and performs any routines enabled by the post
customization file appropriate for the NCI Gcode type. (An example of such a routine is breaking an
arc at its quadrants.)
Next the post executable begins executing MP instructions, which are contained in postblocks.
Postblocks
A postblock is an MP language mechanism - a named series of lines of MP statements, called postlines,
that can perform calculations, call other postblocks, and produce NC output. Based on the value of the
NCI Gcode in the two-line set it is parsing, the post executable calls a specific predefined postblock.
For more information on the correlation between NCI Gcodes and predefined postblocks,
see Volume 1, The NCI file and Volume 1, Postblocks
A predefined postblock called as a result of an NCI Gcode is an entry postblock because it is the
starting point in the post customization file where the instructions in the postblock are executed. There
are other types of predefined postblocks, which will be described later.
The post executable file interprets each postline, following the flow of the logic defined by the
postblock. Each postline is interpreted by examining the MP language statements contained in the line
in order from left to right. Depending on the statement type, a character string may be assembled that
becomes a line of NC output (although not all postlines result in output).
When the post executable determines that an NC output line is complete, it writes the line to the NC
output file. The post executable then continues processing postlines in the entry postblock until the
final instruction is processed. When all statements according to the logic flow of one postblock have
been processed, the post executable reads another two-line set from the NCI file. This produces a call
to another entry postblock and the process repeats. The posting process continues in this way until the
entire NCI file has been read.
The following diagram illustrates MP post processor flow.
Mastercam starts or user changes the post processor
selection.
Variables
Variables are labels given to specific values or strings the post processor uses. The variables may
represent numeric values (numeric variable) or character strings (string variable). They can be
parameters passed from the NCI, values calculated within the post executable file, or switches that are
used to enable or disable posting options. Variables allow the post processor to pass and manipulate
information by using the variable label to represent the value or string itself.
Variables may be predefined or user-defined.
Predefined variables are variables that exist in the post executable file. They do not need to be
declared in the post customization file except to apply an initial value to them or to format them for
output. A list of all pre-defined post variables is located at the end of Volume3, Numeric Variables
User-defined variables must be declared in the post customization file. User-defined numeric variables
must be initialized and/or formatted before they can be used in the post customization file. User-
defined string variables must also be declared before they are used. String variable labels always begin
with the letter “s”, for example, scoolant. User-defined numeric variables can start with any letter
(including “s”).
Using variables to construct output
The post processor constructs a line of NC output by assembling a series of variables found on a
postline. To be output, a variable must simply appear on a postline, but it must not be part of a formula
or conditional expression. For example, the following line would output the values and strings for the
variables, n, scoolant, and next_tool. ‘e’ creates a carriage return/line feed at the end of the line:
n, scoolant, next_tool, e
Note: Modality and Variable Modifiers affect whether a variable is actually output to the NC file.
See Volume 1, Numeric Variables for a description of modality.
String literals
The MP language also supports string literals, which are characters contained within quotes, for
example, “M00”. Literal strings are converted to a string variable internally when they are found on a
postline. They are output exactly as you see them in the post customization file.
Command variables
A special type of predefined numeric variable in the MP language is the command variable. This type
variable starts a process or action that is part of the post executable. They are normally used alone on a
postline. MP language command variables include, for example, comment, which buffers and outputs
comments where the post writer would like them, and fleader, which writes leader and trailer characters
for punched tape.
See Volume 1, Numeric Variables for information on the declaration and use of variables. For a full
description of predefined variables, and for a complete listing of commands, see Volume 3, Numeric
Variables.
Postblocks
A postblock is a labeled series of postlines containing MP statements that produce NC output,
conditionally branch, perform calculations, call other postblocks and trigger routines in the post
executable. A postblock label, which declares a postblock, usually begins with the letter “p” and
begins in the first column. Postblock labels can also begin with “l” or “m”. This format is usually used
for mill/turn applications. The postblock label must be on a separate line before the postlines included
in the block. The only other text that can appear on the same line as a postblock definition is an optional
#comment (text that follows the “#” character).
There are several kinds of postblocks. An entry postblock is one that is called automatically by the post
executable file as a result of the NCI code. Another is the bracketed postblock, which is a user-defined
postblock nested within another postblock. Bracketed postblocks are implied postblocks. By using the
open and close brackets ([,]) to surround the postlines, the post executable interprets this as a separate
block of instructions. Bracketed postblocks are used to make the post customization file more readable
and are normally used with conditional branching.
Postlines
Postlines can start in any column except the first. Use consistent indentation to make the organization
of the post clear. All postlines that are not nested within a bracketed postblocks are considered part of
the preceding labeled postblock until a label in the first column is encountered. This label can be
another postblock label, a variable label or post function declaration. Post comments are ignored and
do not end the postblock.
There are three types of postlines:
Formula postline
Boolean postline
Output postline
Formula postlines
Formula postlines are used for assignments or equations. The equal sign (=) after a result variable as
the first item on the postline is what identifies the formula postline. A formula postline can be
considered a postline statement called a formula statement. A formula statement is limited to one line
and cannot continue over multiple lines in the post customization file. It can be part of a Boolean
postline but cannot be included in an output postline.
Boolean postlines
Boolean postlines begin with a conditional branching statement.
This is a formula statement in a Boolean postlines:
if speed > maxss, speed = maxss
Boolean postlines are very similar to formula postlines except, instead of using an equal sign with a
result variable, a Boolean postline uses the conditional operators ‘if’, ‘else’ or ‘while’ as the first entry
on the postline. In addition, a formula in the conditional branching statement can continue over several
lines until a comma (,) that is not part of a formula function is encountered. Both the conditional
operator and the Boolean formula are considered a postline statement.
For example:
This is a Boolean postline and a conditional branching statement:
if speed > maxss,
This is also a Boolean postline and a conditional branching statement:
else,
Following the comma delimiter in the Boolean postline, it is legal to have any statement type except
another conditional branching statement.
Output postlines
“Output postline” is a misleading term because the statements allowed on this type of postline can
imply that a variable will necessarily be output. However, output postlines can perform any or the
following tasks:
modify variable attributes with or without variable output
call a command routine
output a string literal
output an ASCII character
prompt the user
call a postblock
All of these statements are called output statements.
What identifies an output postline is the fact it is not interpreted as a formula postline, formula
statement or Boolean postline by the post executable. Each of the output statements listed above can
occur in an output postline and must be separated by a comma (,). Statements that are legal for an
output postline are also valid as statements following the conditional branching statement in a Boolean
postline. For example, this is a Boolean postline with output statements:
if speed <> 0, n, speed, next_tool, pblockcall, e
An output statement that contains another postblock name performs a call to the named postblock.
Similar to an entry postblock, this type of postblock passes control to the position of the called
postblock declaration. When the output statement contains more than one postblock name, each
postblock name passes control to its postblock in turn. When all instructions in the called postblock(s)
have been completed, control returns to the calling output statement.
See Volume 1, Postblocks for more information.
Conditional branching
The MP language supports the conditional operators (if, else, while). These are used with conditional
branching statement in the MP language to control what instructions are processed in the post
customization file.
See Volume 1, Postblocks for more information on conditional branching.
Mathematical operators
The MP language supports a large number of operators, including the common mathematical operators:
(open and close parentheses, +. -, *, /), comparison operators (=, <>, <, >, <=, >=), Boolean or logical
operators (&, |, not). (& is the Boolean ‘and’ operator and | is the Boolean ‘or’ operator.)
See Volume 3, Formulas for a complete listing of MP language operators.
Formula functions
An MP formula function performs a defined routine using one or two passed arguments and returns
some result, which is applied or assigned to the variable on the left of the equation, for example, gear =
frange (one, speed) or string2 = lcase (string). Formula functions are part of the MP language; you cannot
define your own functions. The MP language provides a Math Library that includes the following
types of functions:
arithmetic
trigonometric
2D intersection
vector/matrix
string and file manipulation
See Volume 3, Formulas for a complete listing of MP language functions.
Note: Some formula functions are designed to take the left value and assign it to the argument that is
the right value. This is contrary to normal convention.
User prompts
You can display prompts or questions in the Mastercam prompt area at the bottom of the Mastercam
application screen. A unique method is used to trigger a user prompt. The post function for user
prompt (fq) is declared and a trigger placed on a postline in the post customization file. The trigger is
not a variable but is a combination of the letter ‘q’ and the matching number of the post function for
question; for example, q1. When the trigger is encountered as an output statement, the post processor
pauses, displays the prompt text in Mastercam and waits for the user’s response.
See Volume 1, How Prompt Questions Work for more information.
Post comments
A post comment is used to document in the post customization file any information the post writer may
feel is needed. The pound symbol (#) marks the start of a comment. However, because the comment
ends at the end of the line in the post customization file, it is not possible to nest comments or insert
them in between postline statements. All comments are ignored when the post customization file is
parsed by post executable file.
Lookup tables
Lookup tables are essentially two-column tables that associate a value in the first column with a value
or variable in the second column. There are two types of lookup tables:
Lookup tables used to associate an input value with an output value
Lookup tables used to associate an operation parameter Gcode with a numeric or string variable
Lookup tables are normally of the type that associates an input value with an output value. Spindle
gear selection is a good example of this type of lookup table. The spindle speed is passed as an
argument and matched to a value in the second column. The value from the first column is returned.
Lookup tables are declared in the post customization file. The MP_EZ.PST post provides a lookup
table (lookup table 1) to select a gear range based on spindle speed.
See Volume 1, Post Functions for more information.
Buffer files
Buffer files are temporary files used to store and retrieve numeric or string data. They normally exist
only while the post is running. You can convert them to text files or open existing text files as a buffer
files.
Note: MP_EZ.PST does not contain an example of buffer files.
See Volume 2, How Buffer Files Work for more information.
Definition area
The Definition area contains the following sections:
Header containing the title block, revision log, and feature list. This entire section is series of
comments, which is indicated by the pound character (#). (The post executable ignores the # and
everything following it on that line.) Comments are generally documentation intended to be read
by the post’s users.
Debug switches, program constants and other program switches. Debug switches allow you to
generate information about which NCI line and postblocks have produced each line of NC output.
See Volume 1, Post Debugging Techniques for more information. Program constants are numeric
variables that have a single constant value that should never be changed. Program switches turn
program features on and off or select a behavior from a list of options. Both program switches and
variables are given initial values by the post in this section of the customization file.
Numeric variable initialization is a continuation of the debug switches, program constants, and
other program switches section. Some are predefined numeric variables that may be initialized to a
different value depending on the post writer’s requirements. Others are user-defined numeric
variable declarations that are required in the post customization file. A numeric variable
initialization is always defined with the colon “:” and, as the name implies, assigns only the initial
value of the numeric variable.
Format statements describe the numeric format of every numeric variable you will output to the
NC file. Format statements are referred to by number. By default, format statement 1 is associated
to a numeric variable.
String variables, string select functions declare string variables and the string select
functions, which are used to obtain a character string based on a numeric variable. The string
variable label always starts with the letter ‘s’ and the declaration uses a space between the label and
the character string.
Lookup Tables define tables. The post function declaration is entered followed by the table
entries.
Buffers define the buffers used to access or save data. MP_EZ.PST does not use buffer files and it
is generally best to avoid their use unless absolutely needed.
Global formulas are numeric variable declarations that are evaluated whenever the declared
numeric variable is encountered as a postline statement or in a postline formula. This evaluation
occurs before any output. Although any numeric variable declarations (initialization or global) can
have a formula assignment, a global formula is different in that it uses the equal sign (=) instead of
the colon (:) for the assignment. Note: Use of global formulas is not recommended and can lead to
confusion when debugging. Try to put the formula in the postblock where it is used.
Format assignments assign both a prefix character and defined format statement to a numeric
variable. When the numeric variable is output, these formatting assignments are applied.
Postblock area
The Postblock area contains Postblock declarations.
User-defined postblocks must always be declared by defining the postblock with a postblock label
following the syntax rules for postblocks. A user-defined postblock must be called from a predefined
postblock.
Note: To produce output, predefined postblocks must be declared, and postlines with statements for
processing the output must be written. If they are not found in the post customization file as a
declaration, control is immediately returned without any warning to the user. If output statements that
produce output are not present in your post customization file, the NC file will be empty or missing
critical motion output.
Definition area
Title block # Post Name : MP_EZ
# Product : MILL
# Machine Name : GENERIC FANUC
# Control Name : GENERIC FANUC
# Description : GENERIC FANUC 3 AXIS MILL POST
# Associated Post : NONE
# Mill/Turn : NO
# 4-axis/Axis subs. : NO
# 5-axis : NO
# Subprograms : NO
# Executable : MP 9.10
#
# WARNING: THIS POST IS GENERIC AND IS INTENDED FOR MODIFICATION TO
# THE MACHINE TOOL REQUIREMENTS AND PERSONAL PREFERENCE.
Revision log # ---------------------------------------------------------------------
# Revision log:
# ---------------------------------------------------------------------
# Programmers Note:
# CNC 01/12/01 - Initial post setup v8.1
# CNC 01/09/02 - Initial post update for V9.0
# CNC 05/01/02 - Set "helix_arc:2", support helix arc output in XY plane
# CNC 02/04/03 - Initial post update for V9.1
#
Debug # --------------------------------------------------------------------------
# Debugging and Factory Set Program Switches
switches, # --------------------------------------------------------------------------
program m_one : -1 #Define constant
constant zero : 0 #Define constant
one : 1 #Define constant
definitions, two : 2 #Define constant
program three : 3 #Define constant
switch and four : 4 #Define constant
variable five : 5 #Define constant
c9k : 9999 #Define constant
initialization
fastmode : 1 #Posting speed optimization
bug1 : 2 #0=No display, 1=Generic list box, 2=Editor
bug2 : 30 #Append postline labels, non-zero is column position?
bug3 : 0 #Append whatline no. to each NC line?
bug4 : 1 #Append NCI line no. to each NC line?
whatno : yes #Do not perform whatline branches? (leave as yes)
Format # ---------------------------------------------------------------------
# Format statements - n=nonmodal, l=leading, t=trailing, i=inc, d=delta
statements # ---------------------------------------------------------------------
#Default english/metric position format statements
fs2 1 0.7 0.6 #Decimal, absolute, 7 place, default for initialize (:)
fs2 2 0.4 0.3 #Decimal, absolute, 4/3 place
fs2 3 0.4 0.3d #Decimal, delta, 4/3 place
#Common format statements
fs2 4 1 0 1 0 #Integer, not leading
fs2 5 2 0 2 0l #Integer, force two leading
fs2 6 3 0 3 0l #Integer, force three leading
fs2 7 4 0 4 0l #Integer, force four leading
fs2 9 0.1 0.1 #Decimal, absolute, 1 place
fs2 10 0.2 0.2 #Decimal, absolute, 2 place
fs2 11 0.3 0.3 #Decimal, absolute, 3 place
fs2 12 0.4 0.4 #Decimal, absolute, 4 place
fs2 13 0.5 0.5 #Decimal, absolute, 5 place
fs2 14 0.3 0.3d #Decimal, delta, 3 place
fs2 15 0.2 0.1 #Decimal, absolute, 2/1 place
fs2 16 1 0 1 0n #Integer, forced output
Format # ---------------------------------------------------------------------
# Format assignments – prefix, fs#, variable
assignments # ---------------------------------------------------------------------
fmt T 4 t #Tool No: prefix T, fs4, variable t
fmt T 4 first_tool #First Tool Used: prefix T, fs4, first_tool
fmt T 4 next_tool #Next Tool Used: prefix T, fs4, next_tool
fmt D 4 tloffno #Diameter Offset No: prefix D, fs4, tloffno
fmt H 4 tlngno #Length Offset No: prefix H, fs4, tlngno
fmt G 4 g_wcs #WCS G address: prefix G, fs4, g_wcs
fmt P 4 p_wcs #WCS P address: prefix P, fs4, p_wcs
fmt S 4 speed #Spindle Speed: prefix S, fs4, speed
fmt M 4 gear #Gear range: prefix M, fs4, gear
Postblock area
# --------------------------------------------------------------------------
# Tool Comment / Manual Entry Section
# --------------------------------------------------------------------------
ptoolcomment #Comment for tool
tnote = t
toffnote = tloffno
tlngnote = tlngno
"(", pstrtool, *tnote, *toffnote, *tlngnote, *tldia, ")", e
# --------------------------------------------------------------------------
# Start of File and Toolchange Setup
# --------------------------------------------------------------------------
psof0 #Start of file for tool zero
psof
100. Number of places BEFORE the decimal point for sequence numbers? 3
101. Number of places AFTER the decimal point for sequence numbers? 0
Understand how the post customization file you are about to modify works and the NCI Gcode
input before making any changes to the post. Do not blindly use a post comment (#) to remove MP
code in the post customization file. Required procedures may be removed and adversely impact
the NC output.
Read all of the revision, features, and usage notes at the beginning of the .PST file before making
any changes. Log and document any changes you make in the Revisions area.
Check the toolpaths, parameter page entries, and the NCI file data to be sure that input from your
sample Mastercam file is correct.
Test and debug all changes you make to the post customization file before using the posted NC
output in a production environment.
NC lines are built in the order in which the output statements occur on the postline. What you see
in the post customization file is what you get in the NC output. Keep in mind that modality and
other factors control what is actually output to the NC file.
See Volume 1, Numeric Variables for more information on modality.
Use commas (,) to separate output statements.
Output statements can continue over multiple lines by placing a comma at the end of the line (and
before any post comment).
Terminate a series of output statements that are intended to produce NC output with the “e”
command variable. This tells the post executable to write the end-of-block characters.
Output statements may follow the comma delimiter on a Boolean postline.
A formula statement must be on a single line. Do not put more than one formula statement on a
line.
A single formula statement on a single line can follow the comma delimiter on a Boolean postline.
A conditional branching statement can never follow the comma delimiter on a Boolean postline.
A conditional branching statement can continue over multiple lines until the comma delimiter is
found.
Never use the colon (:) as an assignment operator in a postline formula statement. The colon is
reserved for initialization only.
In a conditional branching statement, use a space to separate the Boolean keyword (if, else, while)
from the formula.
Limits
Feature Maximum
When you hover over a region, Mastercam displays a tooltip with a preview of the region’s
contents:
How do I …?
Change the start-of-file Search for the postblock psof in the post customization file. Replace the % character in this line:
character "%", e
with the one needed on for your machine tool. If the character cannot be typed, replace the “%”
characters with the ASCII decimal equivalent. For example:
35, e # This will output a ‘#’ pound symbol character
Remove (or #comment out) the line if no special character is needed.
Change the end-of-file Search for the postblock peof in the post customization file. Follow the procedure used in “Change
character the start-of-file character.
Pre-stage tools for the MP_EZ post was set up to do this. Search for the numeric variable stagetool and find this line:
machines tool changer stagetool : 0 #0 = Do not pre-stage tools, 1 = Stage tools
and set the initialization to 1.
stagetool : 1 #0 = Do not pre-stage tools, 1 = Stage tools
At the end of the NC Search for the postblock peof in the post customization file. Find the line:
file, I want the first tool #if stagetool = one, pbld, n, *first_tool, e
pre-staged
and remove the # character. The # makes this statement a comment. Removing it exposes the code to
the post executable.
Separate the tool This change must be done in two postblocks. Search for the postblock psof in the post customization
number and tool file. Replace the entire line:
change command if stagetool >= zero, pbld, n, *t, "M6", e
with these lines:
if stagetool >= zero, pbld,
[
n, *t, e
n, "M6", e
]
By reordering the lines, you can reverse where the tool and command appear. Search for the postblock
‘ptlchg’ and repeat the process.
Use G92 instead of The Miscellaneous Integer number 1 is used to control this feature in this post. Search for “301.” in the
G54 post customization file. Change the response to 0. The next time the post is loaded, the setting takes
effect.
If you have existing operations, you will need to modify them from the Operations Manager in
Mastercam. Right-click and select Options, Edit Common Parameters. In the Tool Parameters dialog
box, select the Misc. values button and change the first Integers to 0.
Do not break the arcs Search for the numeric variable breakarcs and find this line:
breakarcs : 1 #Break arcs into quadrants?
at the quadrants
Set the initialization to 0.
breakarcs : 0 #Break arcs into quadrants?
Output I,J,K with arcs MP_EZ is coded to output R or I,J,K automatically with a user-defined numeric variable as a switch.
Search for the numeric variable ‘arcoutput’ and find this line:
arcoutput : 1 #0 = IJK, 1 = R no sign, 2 = R signed neg. over 180
Set the initialization to 0.
arcoutput : 0 #0 = IJK, 1 = R no sign, 2 = R signed neg. over 180
Output R signed when Follow the procedure used in “Output I,J,K with arcs” but set the initialization to 2.
the sweep exceeds arcoutput : 2 #0 = IJK, 1 = R no sign, 2 = R signed neg. over 180
180 degrees
Allow sequence Search for the numeric variable seqmax and find this line:
numbers to be greater seqmax : 9999 #Max. sequence no.
than N9999
Set the initialization to the appropriate value. Note: You control the initial sequence number and
increment amount in the Mastercam toolpath parameters dialog box.
Omit sequence Search for the numeric variable use_gear and find this line:
numbers entirely omitseq : no #Omit sequence numbers?.
Set the initialization to yes.
omitseq : yes #Omit sequence numbers?.
Set up a gear range Search for the numeric variable use_gear and find this line:
table use_gear : 0 #Output gear selection code, 0=no, 1=yes
Set the initialization to 1.
use_gear : 1 #Output gear selection code, 0=no, 1=yes
Next search for the post function ‘flktbl’ and find this line:
flktbl 1 3 #Lookup table definition - table no. - no. entries
A lookup table equates the spindle speed to gear range value. The postline here:
gear = frange (one, speed)
from the postblock ‘pgear’ returns the selected value to the numeric variable gear, which is
subsequently formatted and output. Adjust the table to your requirements by modifying and adding to
the lookup table entries. Remember to keep the ‘no entries’ current on the table declaration line.
Search for the post function fstrsel and find this line:
Modify the motion
fstrsel sg00 gcode sgcode
Gcode
The string variables above this line are used in the string selection and are placed in the target string
variable sgcode, which is used as an output statement. To modify the output, simply modify the string
variables character string. For example, change:
sg00 G0 #Rapid
to:
sg00 G00 #Rapid
to output “G00” instead of “G0”.
Change the numeric The post function fs and fs2 are used to define the numeric format for numeric variables. These are
format of a numeric assigned to the numeric variable label with the post function ‘fmt’. First, determine the numeric variable
variable name that you want to modify. Search for the variable name in the post and see if it is in a format
assignment (you may need to create a format assignment for the numeric variable). For example, to use
feed:
fmt F 15 feed #Feed rate
The third parameter (second if there were no prefix) indicates that the format assignment is from format
statement number 15. Now search for Format statement number 15 and find:
fs2 15 0.2 0.1 #Decimal, absolute, 2/1 place
Refer to Volume 1, Numeric Variables for information on modifying the numeric format.
Change the prefix of a Following the procedure used in “Change the numeric format of a numeric variable”, stop at the
numeric variable point where you found the format assignment. Between the keyword ‘fmt’ and the format statement
number is the optional prefix string. In the above example, you can replace F with E:
fmt E 15 feed #Feed rate
to output something like E1.5
Use double quotes if the prefix string has spaces.
Select long code or The usecan… predefined numeric variables control the post executable to determine which process to
canned cycle drilling use. Search for the partial string usecan to find the numeric variable initialization.
output See Volume 1, Working with Drill Cycles for more information.
Change the order of You can change the order of the words output to the NC file simply by rearranging the output statements
words in the NC output on a postline. For example, this line is copied from the postblock plinout:
pcan1, pbld, n, sgplane, `sgcode, sgabsinc, pccdia,
pxout, pyout, pzout, feed, strcantext, scoolant, e
possible output: N10G1G90X10.Y10.F5.M8
can be rearranged to:
pcan1, pbld, n, ` sgabsinc, sgcode, sgplane, pccdia,
pxout, pyout, pzout, strcantext, scoolant, feed, e
possible output: N10G90G1X10.Y10.M8F5.
Prompt the user for You must declare a user prompt function to display a prompt on the Mastercam screen. In the Definition
information during section of the post customization file, enter a user prompt function. For example:
posting
fq 1 omitseq Enter 1 to omit sequences, 0 to use sequences>
Call the question by inserting “q” with the fq definition number (for example, q1) on a separate postline
in the postblock where you want to prompt the user. pq would be a logical postblock for this user
prompt function call. See Volume 1, How Prompt Questions Work for details.
Control the number of Search for the numeric variable spaces and find this line:
spaces between words spaces :0 #No. of spaces to add between fields
in the NC output
Set the initialization to the appropriate number of spaces (10 is the maximum). Spaces are padded in
front of the output word.
February 2003 Mastercam Version 9.1 MP Post Processor Reference Guide 3-1
Chapter 3 Changes to the MP Post Volume 1
3-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
Volume 1 Chapter 4 Post Debugging Techniques
[This chapter is obsolete and has been removed. This functionality has been replaced by the Mastercam
Post Debugger. See the Debugger User’s Guide to learn more.]
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 4-1
Chapter 4 Post Debugging Techniques Volume 1
4-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
Volume 1 Chapter 5 Using Numbered Questions
[This chapter is obsolete and has been removed. This functionality has been moved to the control
definition. See the current control definition documentation to learn more.]
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 5-1
Chapter 5 Using Numbered Questions Volume 1
5-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
Volume 1 Chapter 6 Using the Post Text File
[This chapter is obsolete and has been removed. This functionality has been moved to the control
definition. See the current control definition documentation to learn more.]
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 6-1
Chapter 6 Using the Post Text File Volume 1
6-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
7 Postblocks
A postblock is a labeled block, or series of lines, of MP language code in the post customization file
(.PST file). The post executable file (the .DLL file) interprets the code in the postblocks to create a list
of instructions that produce the NC output, perform calculations and call other postblocks. These
blocks of MP language code produce the NC output.
For a list of postblock descriptions, see Volume 3, Postblocks.
5. Based on the value of the NCI Gcode, the post executable calls a specific MP language
mechanism called a predefined postblock. For NCI Gcode 2, the post executable calls the
predefined postblock pcir. The predefined postblock that is called based on the NCI Gcode is
an entry postblock because it is the point in the post customization file where the instructions in
the postblock begin executing.
Following the flow of the logic in the postblock, the post executable file interprets each line in
the postblock, which are called postlines. Each postline is interpreted by examining the MP
language statements contained in the line, in order, from left to right.
6. Depending on the MP language statement type, a character string is assembled that is the NC
output.
7. When the post executable determines that the NC output line is complete, it writes the line to
the NC output file.
8. The post executable continues processing MP language statements until the final instruction in
the entry postblock is processed.
9. The post executable reads two more lines and repeats the process.
From this description, you can see that the role of the predefined entry postblock is to provide a starting
point for processing the post writer’s MP language instructions in the post customization file. The
mechanism that controls the postblock entry also gives the post writer control over which instructions
are executed based on the NCI Gcode. The postblock structure allows the post writer to jump to other
postblocks and to nest postblocks.
Postblocks support the MP language features that allow the post writer to:
Perform calculations and MP language functions
Perform conditional branching
Manipulate processing in the post executable (beyond what was done with initializing
numeric variables that are post switches)
Call routines in the post executable
Generate NC code
Postblock structure
A postblock is a labeled series of postlines containing MP language statements that produce NC output,
branch conditionally, perform calculations, call other postblocks, and trigger routines in the post
executable.
There are two possible postblock structures:
Traditional postblock
Bracketed postblock
Traditional postblocks
A traditional postblock has two components:
Postblock label
One or more postlines
The postblock label declares the traditional postblock. A postblock label usually begins with the letter
“p” (although “l” and “m” can also be used), must be in the first column, and must be on a line by itself
(with the exception of any #comment).
See Postblock rules summary for a more complete list of rules.
Bracketed postblocks
Another form of postblock is the bracketed postblock, which is a user-defined nested postblock. The
post writer declares a bracketed postblock by using the open and close brackets ([,]) as postline
statements surrounding the postlines to be nested.
Bracketed postblocks are intended to make the post customization file more readable and are always
used within the traditional postblocks.
Bracketed postblocks are implied postblocks, which means they do not have postblock labels declared
by the post writer.
Note: The post executable assigns labels to implied postblocks, which are used internally when the post
customization file is parsed.
Postlines
Postlines are the remaining components of the postblock. A postblock can be declared without any
postlines but this serves no useful purpose.
pcomment2 # This is traditional postblock declaration, using Boolean logic IF/ELSE branching.
scomm = ucase (scomm)
if gcode = 1007, “(“, scomm, “)”
else, “(“, scomm, “)”, e
Postblock declaration
Traditional and bracketed postblocks are declared differently.
Traditional postblocks
A traditional postblock label is used in the following ways:
to declare the postblock
to identify the postblock
in a postline statement to call a postblock
Traditional postblock labels:
Must always start in the first column
Must begin with the letter “p”, “l”, or “m”
May contain letters (a - z), numbers(0 - 9), and the underscore character ( _)
May be a maximum of 25 characters long
Must be on a separate line except for a post comment ( # )
Note: Both predefined and user-defined postblocks are declared the same way.
All postlines that are not nested in bracketed postblocks are considered part of the postblock until a
label in the first column is encountered. This label can be another postblock label, a variable label or
post function declaration. Post comments are ignored and do not end the postblock.
Bracketed postblocks
A bracketed postblock is declared not by a label but by the open and close brackets ([,]) as postline
statements surrounding the postlines to be included in the bracketed postblock.
The post executable assigns a label to bracketed postblocks when the post customization file is parsed.
The assigned labels can be seen when the debugging options are enabled. The labels are created by
concatenating the string “p__”, a number that is the occurrence of the bracket set, the colon “:” and the
line number in the post customization file that the open bracket was on. For example, the first
bracketed set found with the “[” on line 100 would result in the post executable assigning ‘p__0:100’.
Bracketed postblocks:
Are always inside a traditional postblock
Start with the “[“ as an output statement on an output postline
End with the “]“ as an output statement on an output postline
Should have the nesting brackets on separate lines except for a post comment (#)
Can be nested to a maximum of 50 levels deep
Are always user-defined type postblocks
Postblock types
There are many postblock types. Each type serves a purpose in the posting process. Listed here are the
main types and subtypes:
User-defined postblocks
Bracketed postblocks
Standard user-defined postblocks
Predefined postblocks
Pre-process postblocks
Preparatory postblocks
Pre-output postblocks
Standard postblocks
Command postblock
Post-process postblock
User-defined postblocks
User-defined postblocks are declared by the post writer. User-defined postblocks can be called (or
jumped to) only from another postblock and can never be called as entry postblocks based on the NCI
Gcode or from an internal post executable routine.
Predefined postblocks
Predefined postblocks are an integral part of the MP language. The labels for the predefined postblock
are part of the post executable and are called by specific NCI Gcode, command statements, or post
processing order.
All predefined postblocks attempt an entry into the instruction list that was parsed from the post
customization file. If there is no postblock declaration for the predefined postblock, the attempt to enter
the instruction list fails and control is returned to the post executable.
At the end of this chapter you will find descriptions all predefined postblocks.
Pre-process postblocks
Pre-process postblocks are called before post processor reads the NCI file. These postblocks do not
have access to the NCI file data. The following are preprocess postblocks:
pprep
Allows post instructions after the post is parsed but before the NC and NCI file are opened. Do not
attempt to output to the NC file in this postblock because the NC output file is not yet opened.
pq
Allows post instructions after the NC and NCI file are opened but before reading NCI data.
Preparatory postblocks
Preparatory postblocks have access to limited NCI data and are called optionally before the normal
processing NCI file read loop. Preparatory postblocks are called on the NC tool change Gcodes and
NCI parameter Gcodes.
The following are preparatory postblocks:
ptooltbl
An obsolete routine that should no longer be used. It was used to create a tool table.
pwrtt
Provides tool change data from the NCI and scanned information from the toolpaths themselves.
Note: Both ptooltbl and pwrtt are called when the NCI tool change Gcodes are found by the post
executable in the NCI file.
pwrttparam
Called by the NCI parameter Gcodes; similar to the pparameter predefined postblock routine but is part
of the preparatory NCI file scan.
Note: Calls to these postblocks must be enabled in the post customization file by inserting and setting
the post switch variable tooltable to 1 (on).
ptooltbl and pwrtt are mutually exclusive. If you have used ptooltbl (not recommended) then you
should not have pwrtt in your post customization file and vice versa.
See How Preparatory Postblocks Work for more information.
Pre-output postblocks
Pre-output postblocks are called based on the NCI Gcode but before internal calculations are performed
in the post executable. Pre-output postblocks have labels with a “0” or “00” suffix, for example psof00,
ptlchg00, plin0, pcir0, and peof00. If pre-output postblocks are present in the post customization file, the
post executable first calls the preparatory postblock with the same name, for example, pcir0, and then
the standard postblock pcir.
Important Note: Postblocks psof0, ptlchg0, and peof0 are not pre-output postblocks. The “0” suffix with
psof0 and peof0 indicate to the post to call them if the tool number (t) is zero. The “0” suffix with
ptlchg0 indicates that the postblock is called for a null tool change (a tool change information block
where the tool number has not changed from the prior tool change).
See tool_zero in Volume 3, Numeric Variables for important related information.
Standard postblocks
Standard postblocks are called based on the NCI Gcode after internal calculations are performed in the
post executable.
Command postblocks
Command postblocks are called during the normal NCI file processing but perform delayed calls to
output comments, subprograms and canned cycles at locations in the NC code where the user and NC
code require them. They are provided to add flexibility when generating output of comments,
subprograms and canned cycles. The following are command postblocks:
pcomment
Outputs comments to the NC file.
psub_st_m
Called for transform subprograms to write the subprogram header.
psub_call_m
Used for transform subprograms and a single tool to call the subprogram.
psub_call_mm
Used for transform subprograms and many tools to call the subprogram.
prcc_setup
Used to capture information from the roughing tool with lathe canned cycles.
Post-process postblock
A post-process postblock is called after posting has completed and all the files have been closed.
ppost
The only post-process postblock, it allows manipulating the NC file after posting.
Note: The post writer is responsible for opening the files before attempting to write to them.
Postlines
Postlines are the lines of MP language instructions within the postblock. They may appear only after
the postblock declaration and constitute the body of a postblock. Because certain conditions can allow
a postline to continue over more than one line in the post customization file, you must determine where
each postline ends. Never declare variables or post functions on a postline.
For example, this postblock is from the MPFAN.PST post:
ptlchg # Tool change
pcuttype
toolchng = one
if mi1 = one, # Work coordinate system
[
pfbld, n, *sg28ref, "X0.", "Y0.", e
pfbld, n, "G92", *xh, *yh, *zh, e
]
pbld, n, "M01", e
pcom_moveb
c_mmlt # Multiple tool subprogram call
ptoolcomment
comment
pcan
pbld, n, *t, "M6", e
pindex
sav_absinc = absinc
if mi1 > one, absinc = zero
pcan1, pbld, n, *sgcode, *sgabsinc, pwcs, pfxout, pfyout,
pfcout, *speed, *spindle, pgear, strcantext, e
pbld, n, "G43", *tlngno, pfzout, scoolant, next_tool, e
absinc = sav_absinc
pcom_movea
toolchng = zero
c_msng # Single tool subprogram call
Postline types
Some postlines generate output and some provide logic within the post customization file.
Basic postline types are determined by the type of statement at the beginning of the postline. Listed
here are the basic postline types:
Output
Formula
Boolean
Output postline
The term output postline is misleading because the statements on this postline often do not generate
output. An output postline may contain variables, commands, string literals, ASCII decimal equivalent,
and postblock call statements. It is considered an output postline, as long as the line is not a formula
postline or Boolean postline.
Formula postline
Formula postlines are assignments or equations. A result variable followed by an equal sign (=) as the
first item on the postline identifies a formula postline.
The following function calls should always be entered as formula postlines:
Lookup table function call
Parameter table function call
Buffer file function call
Boolean postline
Boolean postlines begin with the conditional operators “if”, “else”, or “while”.
Postline statements
Postline statements are the components that make up the postline. MP language rules determine where
the statement types can appear on a postline, how they are delimited and which basic postline types
they can be used with.
Postline statement definitions include both the variables that can be used and an action. Conditional
branching statements and formula statements are identified by formula components and keywords.
Output statements include variable modifiers.
Following are the major postline statement types:
Conditional branching statement
Formula statement
Output statements
Output line variables
• Numeric variable
• User-defined numeric variable
• Forced numeric variable
• Update numeric variable
• Format numeric variable
• Dependent numeric variable
• Debug numeric variable
• Command variable
• Previous numeric variable
• User-defined string variable
• String variable
• Forced string variable
• Dependent string variable
• Debug string variable
String select function call
• Selector string variable
• Selector forced string variable
• Selector dependent string variable
Formula statement
The formula statement begins with a result variable before the equal sign (=) that is part of an equation,
assignment or formula and ends where the actual postline ends (ignoring spaces and post comments).
The formula statement must remain on a single line in the post customization file:
speed = abs(ss)
Formula statements and conditional branching statements are similar, differing from each other only in:
The keyword that determines the type (for a formula, “variable =”, or for conditional
branching, “if”, “else”, “while”).
The end delimiter (for formula, the end of the postline, or for conditional branching, a
comma).
The way the result is interpreted also differs:
A conditional branching statement is tested for true or false and the result is zero or non-zero.
A formula statement result is returned directly in the result variable.
The following are allowed as components in the formula equation.
Math operator
Formula function
Numeric variable
User-defined numeric variable
Previous numeric variable
String variable
User-defined string variable
String literal
Note: What is allowed with any particular function or operator depends on the argument types. The
components of the formula are not considered as postline statement types; the entire statement
includes the type key and the type delimiter. See Formulas for more information.
Output statements
The term output statement is misleading, like output postline, because the statements might not
generate output. Output statements are not allowed in a formula statement or a conditional branching
statement. Output statements can continue over multiple lines in the post customization file and even
continue through postblock calls or jumps. Output statements are separated by a comma (,) between
each statement. If a postline statement was not identified as a formula statement or a conditional
branching statement, it is then assumed to be one of the output statement forms.
Output statements may contain:
Output line variables
String select function call
String literal
Dependent string literal
ASCII literal
Postblock call
User prompt function call
Output line variables
Any variable that is defined, either by the post executable or in the post customization file, can be
placed on a postline as an output statement. You can modify how the post executable handles
processing of the variable by adding a prefix called a variable modifier (!, *, @ ~, etc.) The following
may be output line variables:
Numeric variables
Variables predefined in the post executable file (without any modifiers). Output to the NC file is
expected based on modality. For example:
x
Variable modifiers
When added to numeric variables, variable modifiers change processing as follows:
Forced numeric variable (*)
Both user-defined numeric variables and numeric variables can be forced to output. The prefix asterisk
(*) overrides modality and forces output to the NC file. For example:
*x, *xabs
Command variable
Command variables are unique in that they trigger an event or routine in the post executable, possibly
calling back to the post customization file for some postblock instructions. All command variables are
predefined numeric variables. Most cannot be prefixed with a variable modifier. For example:
comment
String variable
Variables of this type are the predefined variables in the post executable file. This is the undressed
form of the string variable. Output to the NC file is expected. For example:
snamenc
When added to string variables, the variable modifiers change processing as follows:
Forced string variable (*)
Both user-defined string variables and string variables can be forced to output. The prefix asterisk (*)
override forces output to the NC file. This is only necessary when the string output is based on the
modality of a (fstrel) string select function. Output to the NC file is expected. For example:
*snamenc, *sm00
When added to selector variables, the variable modifiers change processing as follows:
Selector forced string variable (*)
The selector string variable can be forced to output. The prefix asterisk (*) forces output to the NC file.
Output to the NC file is expected. For example:
*sgcode
The selector string variable can be prefixed with the grave accent (`) to permit output to the NC file
only when there is other valid output on the assembled NC line. Sequence (n) already behaves this way.
For example:
`sgcode
String literals (“ “)
A string literal is actually a form of user-defined string declaration. The character string is enclosed
within double quotes (“”). The syntax implies a user-defined string variable when parsed by the post
executable. Output to the NC file is forced. For example:
”M12”
ASCII literals
Any of the standard ASCII characters can be output to the NC file by entering the decimal equivalent
(0 to 255 ) of the desired character as an output statement. Output to the NC file is forced. For
example, the pound character (#) is ASCII 035:
35
Postblock calls
To call a postblock, place the name of the postblock as an output statement. The post executable marks
the position where the jump occurs and passes processing of postline instructions to the called
postblock. No output is generated by the placement of the postblock name, but output may occur in the
postblock that is called. For example:
pblock
Postblock/postline examples
Following are examples of the postblocks, postline types, and postline statements from MPFAN.PST.
The MP language code here is commented with the post comment and highlighted to identify each of
the types on the postline.
psof #Start of file (Predefined postblock, Standard postblock)
#Output postline, Postblock call
pcuttype
#Formula postline, Formula statement
toolchng = one
#Boolean postline, Conditional branching statement
if ntools = one,
#Bracketed postblock, begin
[
#skip single tool outputs, stagetool must be on
# Formula postline, Formula statement
stagetool = m_one
#Output postline, Update numeric variable
!next_tool
#Bracketed postblocks, end
]
#Output postline, String literal, Command variable
"%", e
#Output postline, Forced numeric variable, Command variable
*progno, e
#Output postline, String literal, Numeric variable, String literal, Command variable
"(PROGRAM NAME - ", progname, ")", e
#Output postline, String literal, Command variable, String literal, Command variable, String literal, Command
variable
"(DATE=DD-MM-YY - ", date," TIME=HH:MM - ", time, ")",e
#Output postline, Postblock call, Numeric variable, Selector forced string variable, Command variable
pbld, n, *smetric, e
#Output postline, Postblock call, Numeric variable, Selector forced string variable, Selector forced string variable,
String literal, String literal, Selector forced string variable, Command variable
pbld, n, *sgcode, *sgplane, "G40", "G49", "G80", *sgabsinc, e
#Formula postline
sav_absinc = absinc
#Boolean postline, Conditional branching statement
if mi1 <= one,
#Bracketed postblock, begin
[
#Formula postline
absinc = one
#Output postline, Postblock call, Numeric variable, Selector string variable, String literal, Command variable
pfbld, n, sgabsinc, *sg28ref, "Z0.", e
#Output postline, Postblock call, Numeric variable, Selector forced string variable, String literal, String literal,
Command variable
pfbld, n, *sg28ref, "X0.", "Y0.", e
#Output postline, Postblock call, Numeric variable, String literal, Forced numeric variable, Forced numeric
variable, Forced numeric variable, Command variable
pfbld, n, "G92", *xh, *yh, *zh, e
#Formula postline
absinc = sav_absinc
#Bracketed postblock, end
]
#Output postline, Postblock call
pcom_moveb
#Output postline, Command variable
c_mmlt #Multiple tool subprogram call
#Output postline, Postblock call
ptoolcomment
#Output postline, Command variable
comment
#Output postline, Postblock call
pcan
#Boolean postline, Conditional branching statement, Output statement
if stagetool >= zero, pbld, n, *t, "M6", e
#Output postline, Postblock call
pindex
#Boolean postline, Conditional branching statement, Formula statement
if mi1 > one, absinc = zero
#Output postline, Postblock call, Numeric variable, Selector forced string variable, Selector forced string variable,
Postblock call, Postblock call, Postblock call, Forced numeric variable, Selector forced string variable, Postblock
call, String variable, Command variable
pcan1, pbld, n, *sgcode, *sgabsinc, pwcs, pfxout, pfyout, pfcout,
*speed, *spindle, pgear, strcantext, e
#Output postline, Postblock call, String literal, Forced numeric variable, Postblock call, Selector string variable,
Numeric variable, Command variable
pbld, n, "G43", *tlngno, pfzout, scoolant, next_tool, e
#Formula postline
absinc = sav_absinc
#Output postline, Postblock call
pcom_movea
#Formula postline
toolchng = zero
#Output postline, Command variable
c_msng #Single tool subprogram call
Studying these code examples should give the novice post writer a basic understanding of how
statements and postline types are assembled.
A series of output statements that are intended to produce NC output should be terminated with the
e command variable. This tells the post executable to write the end-of-block characters.
ldinl2
The length of second lead-in move. This allows for a change from rapid to plunge feed rate. if ldinl2 =
0, this move will be eliminated.
ldina2
The lead-in angle measured from first cut segment, in degrees. A lead-in angle of 0 would yield a
tangent lead-in.
ldoutl1
The length of lead-out move, measured from last point in cut. If ldoutl1 = 0, this move will be
eliminated.
ldouta1
The lead-out angle measured from last cut segment, in degrees. A lead-out angle of 0 would yield a
tangent lead-out.
ldoutl2
The length of second lead-out move. This allows for a change from rapid to plunge feed rate. If ldoutl2
= 0, this move will be eliminated.
ldouta2
The lead-out angle measured from last cut segment, in degrees. A lead-out angle of 90 would yield a
lead-out normal to surface.
Figure: 5-axis lead in/lead out
The drawing shows the relative location on the 5-axis toolpath where each move is generated by the
post executable. These moves are not part of the NCI file but are created in the post executable.
CALCULATED LDINL2
VECTOR
LDOUTL2
LDOUTL1
CALCULATED
VECTOR
The lead in motion is started when the NCI Gcode 11 is passed to the internal routine and the numeric
variable whatline is 0. The post executable delays this first position until the second position is read
from the NCI file so that the cut direction can be determined. Normally, whatline is set to 0 in
ptlchg1002 when using the programming technique enabled with tlchng_aft. This routine (tlchng_aft) is
designed to include the motion NCI data after the tool change NCI gcode (1000, 1001 and 1002) line as
part of the tool change series of lines. Otherwise, whatline is assigned 0 in the psof, and ptlchg
postblocks.
The lead out motion is triggered when the numeric variable cutpos, read from the NCI file, is equal to 3.
The called postblock depends on the setting of the lead in and lead out variables. If the move was
eliminated because the numeric variable was 0, a call is not generated to the predefined postblock.
Before each output postblock call, the internal routine to apply the numeric variables tilt (for tilt along
cut direction) and rhtilt (tilt perpendicular to cut direction) is called. At the end of the routine that
applied the tilt (if non-zero), a call is made to the postblock pmx0. Now, the postblock is called for the
NC output instructions in the post customization file.
Postblock calling for Gcode 11
whatline = 2 –
Lead in Line 1 is valid – Call pmx1
Lead in Line 2 is valid –
• whatline is set to 3
• Call pmx1
Original position is output – Call pmx2
whatline = 4 and cutpos <> 3 - Call pmx
cutpos = 3 –
Lead out Line 1 is valid – Call pmx1
Lead out Line 2 is valid – Call pmx1
drillcyc = 6 –
posttype = 1 (Mill/Router) –
• mmisc1_2 in post – Call mmisc1_2
• otherwise – Call pmisc1_2
posttype = 2 (Lathe) –
• lmisc1_2 in post – Call lmisc1_2
• otherwise – Call pmisc1_2
drillcyc = 7 –
posttype = 1 (Mill/Router) –
• mmisc2_2 in post – Call mmisc2_2
• otherwise – Call pmisc2_2
posttype = 2 (Lathe) –
• lmisc2_2 in post – Call lmisc2_2
• otherwise – Call pmisc2_2
If you want, you can break out the parameters on separate lines, but the initial
parenthesis must be on the same line as the postblock name:
# Define postblock with parameters
pcalc_position(
xcoord,
ycoord,
zcoord,
start_angle )
The values that you pass to the postblock can be any valid numeric expression:
User-defined or predefined numeric variables. This includes prv_ variables and
variables defined as constants.
Numbers—for example, 30.
Formulas/functions that return a numeric value—for example, (abs(xnci$)).
In this case, the formula or function will be evaluated before the postblock is
called, and the return value matched to the parameter list. Only formulas and
functions that return a numeric value can be used.
As a general rule, it is a good practice to enclose formula arguments in
parentheses.
Expressions—for example, 3*my_var.
You cannot skip any arguments when calling the postblock. If you include fewer
arguments than are defined in the postblock definition, MP will not generate an error.
However, the parameters for which no argument has been supplied will continue to have
whatever value they were last assigned.
Conversely, if your postblock call has more arguments than have been defined for the
postblock, the extra arguments will be ignored. The typical best practice is for the
postwriter to ensure that the number of arguments matches the number of parameters.
You are allowed to use a negative number as an argument; for example, –30. However, if
you use the minus sign in front of a variable name in your argument list, you must
enclose it inside parentheses; for example, (–ynci$).
ADDENDA
Previous values
Not only can you use the prv_ value of a variable as an argument when calling a
postblock, you can use it in the parameter list when you define the postblock. When you
do this, MP will also automatically create the regular variable when the postblock
definition is processed.
The prv_ states of the argument and the parameter definition do not need to match. For
example, if the postblock definition includes a prv_ in its parameter list, you can still
pass it a regular variable as an argument.
Global variables
You are allowed to use global variables both when defining and calling a postblock.
ADDENDA
Global variables used in a postblock definition are assigned the value that is passed in
when the postblock is called.
Global variables used as an argument when calling a postblock are not solved when the
postblock is called. They are assigned a value on return.
Quick Start
Versions of Mastercam before X8
Note that if you use these techniques in versions of Mastercam earlier than X8, MP will
not give you an error. However, they have not been tested in earlier versions of
Mastercam, and their use is not supported or recommended.
Example
Example: Defining and calling a postblock with arguments
The following example shows how different types of argument values are processed
and manipulated when they are passed to a postblock called pblockvars that is
defined with three parameters.
var_1 : 5
var_2 : 10
var_3 : 15
pheader$
You can see the effects of passing argument values in three different forms:
The value of var_1 is passed with the ! character, meaning var_1 is updated by
the postblock pblockvars.
The sign of var_3’s value is reversed before it is passed.
Instead of var_2, a simple number (13) is passed.
LEGACY DOC -- VERSION 9.1
Preparatory postblocks are postblocks that are called during a preparatory reading (processing) of the
NCI file. This preparatory processing allows information about the tool changes and toolpaths
contained in the NCI file to be captured prior to the normal processing of the NCI file. Although this is
commonly used to create a tool table that is then written to the head of the NC output, preparatory
processing is much more powerful than simply creating tool tables.
When combined with buffer files, preparatory processing permits the capture and retrieval of
information about the next tool change. (Buffer files are temporary files that can be created within the
MP language to store and retrieve data. See Volume 2, How Buffer Files Work.) Information about the
extent of motion in the NCI, cutting planes used, parameters and comments in the NCI can also be
extracted.
In this chapter, you will find the following topics:
Preparatory postblock lists and descriptions
Enabling preparatory postblocks using the tooltable numeric variable
What happens during preparatory processing
Preparatory processing with pwrtt
Preparatory processing with ptooltbl
Preparatory processing with pradlist (Wire only)
Preparatory processing with ptprlist (Wire only)
Ending the preparatory processing procedure
Using tooltable as command variable
The predefined numeric variable is tooltable, which must be set to a positive value
The system numbered questions (in the PST file) are:
1501. Insert parameter information in the ascii NCI? n
1502. Write operation information to binary file (.ops)? n
1503. Write transform operations (0=transform ops, 1=source ops, 2=both)? 1
See Volume 2, Parameter Information for more information.
NCI Gcode line 1001 is read and internal processing occurs as follows:
Postblock ‘prot0’ is called (Mill/Router/Lathe only)
Postblock ‘psof00’ is called (Mill/Router//Lathe only)
Postblock ‘pheader’ is called
Postblock ‘ptprlist’ is called (Wire only)
Postblock ‘pradlist’ is called (Wire only)
The internal pre-read routine is called, select one:
The ‘pwrtt’ Preparatory Processing Procedure
The ‘ptooltbl’ Preparatory Processing Procedure
Control is passed back from the pre-read routine and processing continues.
Postblock ‘psof’ or ‘ptlchg1002’ is called
Variable tooltable is set to -1
The preparatory processing procedure may be performed with either the pwrtt or ptootbl postblocks.
The post executable will be aware that the predefined postblock pwrtt has been declared and the
numeric variable tooltable has been set to a positive value and will processes the NCI file according to
the procedure for calls to pwrtt.
Note: This includes calls to pwrttparam if it also was declared in the post customization file.
At this point, the preparatory processing procedure from the normal NCI processing will have been
completed up to the point where the internal pre-read routine is called. The NCI file will be rewound
and processing of the NCI file will be restarted with the standard two line set NCI file read.
See Volume 3, Postblocks for more information and which variables are read during the pre-read
routine.
As each toolpath section in the NCI file is read (that is, from tool change to tool change), the NCI
Gcode is processed in the read loop. The following events occur in the order listed here:
1050 NCI Gcode – Read the parameters.
1011 NCI Gcode – Read the parameters.
1012 NCI Gcode – Read the parameters.
1013 NCI Gcode – Read the parameters.
1014 NCI Gcode – Read the parameters.
1015 NCI Gcode – Read the parameters. (Wire only)
1016 NCI Gcode – Read the parameters.
1017 NCI Gcode – Read the parameters. (Mill/Router/Lathe only)
1025 NCI Gcode – Read the parameters.
1020 NCI Gcode – If the system numbered question 1502 is set to write to the operation file
(.OPS file) and pwrttparam is present in the post customization file, then the 10000s parameters
are processed in prmcode and sparameter. A call is made to the pwrttparam postblock.
See Volume 2, Parameter Information for more information.
1018 NCI Gcode (Optional Mill/Router/Lathe transform subprograms) – Read the parameters.
10000s NCI Gcode – If the system numbered question 1501 is set to write to the operation
parameters to the NCI file, then the 10000s parameters are processed in prmcode and sparameter. A
call is made to the pwrttparam postblock.
See Volume 2, Parameter Information for more information.
20000s NCI Gcode (Mill/Router/Lathe only) – Read the parameters into the variables prmcode and
sparameter. A call is made to the pwrttparam postblock. NCI Gcode 20001 holds the comment from
the tool definition is assumed to be the tool name. This is placed in the predefined string variables
strtoolpath, strtool and strtoolext if the numeric variable strtool_v7 is set to 1.
See Volume 2, Parameter Information and Volume 1, Changes to the MP Post for more
information.
1000, 1001, 1002 NCI Gcode – Read the parameters. Set the look ahead variables directly from the
NCI file for next_dc, nextop, nextccomp, nextcflg and mill5 (Mill/Router only). The numeric variable
for tool number ‘t’ is checked to see if it has been used at any time prior to this tool change and is
signed negative if it has. Call the postblock pwrtt.
NCI Gcode in the toolpath – Read the parameters. The NCI motion extents for each toolpath
segment (tool change to tool change) are captured in the numeric variables x_max, y_max, z_max,
x_min, y_min, z_min. Additionally, any arc plane is captured in the variable ttplane. Wire looks for
the maximum taper angle in 2D contour wirepaths and stores that in the numeric variable wt_max.
• 1005-1008 NCI Gcode – Read the parameters into the variables prmcode and sparameter. A call
is made to the pwrttparam postblock. These NCI Gcodes can be at the beginning of the tool
change series of NCI lines.
• 1018 NCI Gcode (Optional Mill/Router/Lathe non-transform subprograms) – Read the
parameters. Set the numeric variable for rcc_flg, lower_x, lower_y, lower_z, upper_x, upper_y,
upper_z, to track lathe canned cycles.
See Volume 2, Lathe Canned Cycles for more information.
• 1019 NCI Gcode (Optional Mill/Router/Lathe non-transform subprograms) – See the 1018
NCI Gcode above.
1003 NCI Gcode – When the variable tooltable is set to 3, a final call the postblock pwrtt is
performed. The purpose of this call is to allow the information scanned from the last tool change to
the end of the file to be captured. In particular, the numeric variables x_max, y_max, z_max, x_min,
y_min, z_min, ttplane and wt_max (Wire only).
See Ending the Preparatory Processing Procedure below.
Note: Variables read in the actual toolpath are overwritten by the next set of NCI lines read.
Only the last values read before the call to pwrtt or pwrttparam are available.
As each toolpath section in the NCI file is read, the NCI Gcode is processed in the read loop.
The following events occur in the order here:
1050 NCI Gcode – Read the parameters.
1011 NCI Gcode – Read the parameters.
1012 NCI Gcode – Read the parameters.
1013 NCI Gcode – Read the parameters.
1014 NCI Gcode – Read the parameters.
1015 NCI Gcode (Wire only) – Read the parameters.
1016 NCI Gcode – Read the parameters.
1017 NCI Gcode (Mill/Router/Lathe only) – Read the parameters.
1025 NCI Gcode – Read the parameters.
1020 NCI Gcode – Read the parameters.
1018 NCI Gcode (Optional Mill/Router/Lathe transform subprograms) – Read the parameters.
10000s NCI Gcode – Parameters are not read.
20000s NCI Gcode (Mill/Router/Lathe only) – Parameters are not read except the NCI Gcode
20001 (comment from the tool definition) is placed in the predefined string variables strtoolpath,
strtool and strtoolext if the numeric variable strtool_v7 is set to 1.
See Changes to the MP Post for more information.
1000, 1001, 1002 NCI Gcode – Read the parameters. Set a flag to trigger a call to ptooltbl on the
next two line set NCI file read.
NCI Gcode in the toolpath – Read the parameters. The post executable checks to see if the flag
was set from the 1000, 1001, 1002 NCI Gcode NCI file read. The flag is removed and no call to
the ptooltbl postblock occurs if the numeric variable for tool number t has been used at any time
prior to the tool change (Mill/Router/Lathe only). Each case that calls ptooltbl is listed here:
• 0, 1, 2, 3, 200 NCI Gcode (Mill/Router/Lathe) – Parameters are not read.
Call the postblock ptooltbl.
• 0, 1, 2, 3, 20, 21, 22, 23, 30, 31, 32, 33 NCI Gcode (Wire) – Parameters are not read.
Call the postblock ptooltbl.
• 11, 81 NCI Gcode – Read the parameters.
Call the postblock ptooltbl.
The numeric variable (command variable) tooltable is set to -1 by the post executable when it returns
from the pre-read routine and has completed the call to the postblocks psof or lsof or msof or ptlchg1002.
The postblock calls are dependent on product and processing options.
See Volume 3, Mill / Turn Applications and Volume 1, Changes to the MP Post for more information.
Note: tooltable should not be initialized when used as a command variable. If it is desired to recall pwrtt
on the NCI Gcode 1003, set tooltable to 3 in the postblock pwrtt.
This example shows this technique:
pwrtt #Write tool table, scans entire file, repeat tools are negative.
tooltable = 3
tnote = t
toffnote = tloffno
tlngnote = tlngno
The H offset register is read for the taper to be used in the toolpath.
After the lists are written, the post writer must place them in the head of the NC file. A couple steps are
required to call the output to write the lists. In the post customization file, you must enable the call to
the list read loop for each list (see below):
listtpr : 1 # Enable taper list output, see ptprlist
listrad : 0 # Enable radius list output, see pradlist
The list read loop is a routine in the post executable. The read loop reads each record that was written
to it, in ascending order and on each read calls a specific postblock in the post customization file. The
postblock must be in the post customization file and output postlines within the postblock to write the
lists. For the wire taper list, the ptprlist postblock must be present:
ptprlist # List of taper angles, only tofs (index) and wt are read
# List is checked in linear/circular (0,1,2,3) and "tofs" set
*tofs, " = ", *wt, e
The above postblocks, when enabled, are called immediately after the predefined postblock pheader.
They are called in the order ptprlist and then pradlist. There is no way to alter the calling order.
Note: The taper list is generated starting at base zero but was written starting at base 1.
The radius list captures the calculated numeric variable for wire radius tlrad from the NCI Gcode 1010
and 1013 lines. These are then written to the list using the value from the numeric variable offset as the
index position.
When the list is generated in the post customization file, the predefined postblock pradlist is called each
list time a list entry is written (in ascending order) with a non-zero offset entry. The list is read starting
at 0. The numeric variable tlrad is assigned the saved wire radius value, and the numeric variables lofs
and offset are assigned the index position (the original offset value that wrote the radius).
The numeric variable offset should be used in your tool change postblocks and condition change
postblock pconchg to refer to the listed values in the NC file.
Note: Both these tables are limited to 1000 entries each.
9 Numeric Variables
Numeric variables are variables that represent numeric values in the MP language. The MP language
has only two types of variables: numeric values and character strings. The numeric variables are all
stored internally by the post executable as double real values.
A numeric variable is identified by a label. The label represents a specific memory location that holds
the value of the numeric variable. By using the variable label in the post customization file, you can
access the value the variable represents. The numeric variables can be parameters passed from the NCI
file, values calculated in the post executable for a specific routine, switches that enable or disable
posting options, variables defined by the post writer to be used within the post customization file.
Some numeric variables do not use the value associated with them but use the label or name to trigger a
routine in the post executable. These variables are called command variables.
For a list of numeric variable descriptions, see Volume 3, Numeric Variables.
Initialization (:)
When a numeric variable is declared with a colon (:), the value, numeric variable, or formula that is to
be assigned to the variable is evaluated when the post customization file is parsed. This occurs before
any processing of the NCI file. These values are written to the appropriate numeric variable as the
initial setting. These are the values seen when the NCI file read is started and the post executable starts
calling internal routines and postblocks. The post executable never re-evaluates the value, numeric
variable, or formula after the post customization file parsing is completed.
Examples
Here are examples of numeric variable initialization cases.
Initialization with a value
real_var1 : 12 # Initialize user defined variable with a value
x : 12 # Initialize predefined variable with a value
Note: The assigned numeric variable must be predefined or declared before the initialization with a
numeric variable.
Initialization with a formula statement
real_var1 : year + 2000 # Initialize with a formula statement
Note: The assigned numeric variable must be predefined or declared before the Global formula
initialization with a numeric variable.
Global formula with a formula statement
real_var3 = real_var3 + 2 # Initialize with a formula statement
real_var3 = fsg3(x) # Initialize with a formula statement
Format assignment
A numeric variable declared in a format assignment, but not declared with a numeric variable
initialization, is assigned an initial value of 0. It is allowed to have both a numeric variable
initialization and format assignment for a particular variable.
See Formulas for more information.
The post executable creates a label for 1 and 10 in the formula statement.
Note: It is more efficient to initialize the numeric variables than to imply them if the value is repeated.
The post executable creates an entry in the internal list for each implied numeric variable.
ASCII literal
The ASCII literal is implied as a string by entering the decimal equivalent (0 to 255 ) of the desired
character as an output statement. This is NOT converted to a numeric variable in this context. For
example:
n, 35, e
Format statements
The MP language supports two format statement functions:
fs defines a single numeric format.
fs2 defines a numeric format that changes automatically depending on the Mastercam
configuration, inch or metric, at the time the NCI file was generated. The post executable
applies the appropriate numeric format (either inch or metric) based on the value of the
met_tool numeric variable.
Either format statement function may be used in the post customization file but cannot share the same
enumerator. For example, this would not be valid:
fs 1 0.7 #Decimal, absolute, 7 places
fs2 1 0.7 0.6 #Decimal, absolute, 7/6 places
You can define a maximum of 30 format statements. The following tables describe the form required
for the two format statements:
12 Round off flag omitted Normal round off as required by number of fraction
(optional) digits.
2 Round to nearest even number.
5 Round to nearest multiple of 5.
9 Truncate the decimal at number of fraction digits
13 Keep leading zeroes l Keep/add leading zeroes.
flag (optional)
omitted Omit leading zeroes.
14 Keep trailing zeroes t Keep/add trailing zeroes.
flag (optional)
omitted Omit trailing zeroes.
15 Modality (optional) n Force non-modal.
omitted Use default modality.
16 Coordinate format omitted Absolute
(optional)
d Delta; incremetal but if zero do not output
i Incremental
17 Keep trailing zero z Keep a trailing zero with a whole number after the
(optional) decimal or comma.
omitted No trailing zero (depending on format).
To build a format statement, assemble the components from the entries in the Syntax column. Notice
that many of the entries can be omitted (or must be omitted) to generate the desired format. Only use
one selection if multiple choices are offered for any one component. The format statement must be
started in the first column and cannot be part of a postblock. For example, this defines format
statement one:
fs2 1 0.4 0.3t
This assembles the post function name fs2, and syntax components 1, 2, 4, 5, 6, 8, 9, 10, 11 and 14.
The components 3, 7, 12, 13, 15, 16 and 17 are implied by their omission.
The numeric formatter does nothing to control the number of integer digits written to the output. The
number of integer digits is only useful to pad the leading zeros if the l for leading format is used. The
delta d format outputs the absolute value if it is not zero, delta meaning output if a change. Incremental
output is calculated in the post executable as the difference from the previous move to the current
move. You should use incremental carefully because, at the moment after the NC output occurs, the
value is zeroed. If you do not define any format statements in the post customization file, format
statement number 1 is assigned 0 0 as the numeric format. This effectively removes any numeric
output.
The following table contains some examples of format statement. It is not practical to attempt to
display all the possible combinations of generated output.
Format assignments
Once the format statements have been defined, use the format assignment function to associate a format
statement with a variable. The format assignment allows you to:
Declare the numeric variable (if it is user-defined).
Assign the numeric format from the format statement ID.
Prefix the value with a character string (optional).
Apply a suffix character string (optional).
Format assignment examples
fmt 1 2 3 4 5 6 7 8
To build a format assignment, assemble the components from the entries in the Syntax column the
same as for format statements. The format assignment must be started in the first column and cannot
be part of a postblock.
For example, the following line assigns the format statement 1 to the numeric variable x:
fmt X 1 x
assembling the post function name fmt, and syntax components 1, 2, 3, 4, 5 and 6. The components 7
and 8 are omitted so there is no suffix.
Here are some format assignment examples:
fmt T 4 t # Tool number
fmt N 4 n # Sequence number
fmt X 2 xabs # X position output (absolute)
fmt Y 2 yabs # Y position output (absolute)
fmt Z 2 zabs # Z position output (absolute)
clearsub
clearaux
clearext
newsub
newaux
newext
c_msng
c_mmlt
c_rcc_setup
comment
tooltable
ex
exitpost
nci_rewind
fs1
These pre-formatted numeric variables are given a default prefix when the post executable is first
started. Along with all the remaining predefined numeric variables, they are given the default format
statement 1 (fs1).
Conditions Prefix
x, y, z X, Y, Z
xh, yh, zh X, Y, Z
xr, yr, zr X, Y, Z
i, j, k I, J, K
startx, starty, startz X, Y, Z
threadx, thready, threadz X, Y, Z
You can overwrite the default format by using a format assignment in the post customization file.
Note: It is possible to format a command variable and there are cases when you would do this (for
example, time and date variables). However, you would not normally assign a format to them because
they no longer can call the internal routine they are designed to access.
Having the previous variable value permits the post executable to test the current and previous value to
determine modality. The numeric variables that are to be output can be given the attribute of being
modal or non-modal.
A modal variable does not produce output if its current value is the same as its previous value, that is, if
its value hasn’t changed since the last time it was output. If the values are different, the current value
held by the numeric variable replaces the previous value held by the prv_variable when output is
complete.
A non-modal variable is always output regardless of the state of the current and previous value.
Numeric variables are modal by default, which means a variable will not be output unless its value has
changed (that is, its current value [var] does not equal prv_[var] value).
Numeric variables
Variables of this type are the predefined variables defined in the post executable file or initialized in the
post customization file with a unique label as a user-defined numeric variable. This is presented on the
output postline with out any modifier. Output to the NC file is expected based on modality.
For example:
n, gcode, x, y, z, real_var, e
For another way to force outputs, see the force() function in Volume1, Functions.
This is a useful technique to control the output of a modal variable. When this is done prior to the
numeric variable’s normal output, the normal output does not occur because of modality.
The @ modifier can be used before comparing values of current to previous or any place the rounded
value is needed and output or updating the previous value is not desired. See the formula fmtrnd in
Volume1, Formulas when comparing in a conditional branching statement and the rounded value is
needed.
In this output line, if x, y and z are modal (no output unless the previous output was different) and any
one previous value was different for x, y and z, you would expect output similar to:
N10G00X1.Y2.Z3.
If all the previous values were the same for x, y and z, then you would expect the entire line to be
omitted from the NC output, even if the value for gcode is changed.
This is useful in preventing undesirable output such as would happen if gcode had been 1 in the
example above. In this case, the following would have been generated.
N10G01
Command variables
Command variables are unique in that they trigger an event or routine in the post executable, possibly
calling back to the post customization file for some postblock instructions. All command variables are
predefined numeric variables. Most should not be prefixed with a variable modifier or assigned a
format statement. For example:
comment
However, because of rounding, before the second output and after the second NCI data read, the values
would be:
x = 1.234567 and prv_x = 1.2345
If a comparison is performed on these values, you will get a false return. See the formula fmtrnd in
Volume1, Formulas when comparing in a conditional branching statement and the rounded value is
needed. Previous numeric variables (prv_[var]) should not be used for normal output and cannot be
prefixed with a variable modifier. These are usually output when debugging or used in formula
statements or conditional branching statement.
For example:
prv_xabs
The following table shows the effect of variable modifiers on the output statement:
Modifier Solve Round Force Update Usage
Syntax Global Current Output pr_[var]
Formula Value Value
Variable var yes yes no yes Normal behavior.
(no
modifier)
Forced *var yes yes yes yes Force output.
Variable
Update !var yes yes no yes Access the prv_[var] to update it
Variable
without output.
Format @var yes yes no no Round the current value.
Variable
Debug ~var no no yes no Force output for debugging.
Variable
Dependent `var yes yes no yes Output is dependent on other output
Output
Variable on the postline.
Post switch variable – The post switch variable is initially set to a default value of zero by
the post executable. Its value is set in the post customization file with a numeric variable
initialization if a different value is desired. This type of variable allows the post writer to
specify which processing option is used with various routines in the post executable.
Note: Some post switch variables are also returned values when the NCI file processing
begins within the post executable.
Constant - The constant is a numeric variable that is set to an initial value by the post
executable when it is first started.
Note: A constant in the MP language is not protected in any manner. Be careful not to
assign a value to a constant or use it in a formula that can modify the value.
Command variable – Command variables do not normally take values. The variable label
is used as a trigger to execute a post executable routine. The time and date variables are the
exception. Formatting these variables exposes the value of the variable and they become
system data variables.
Helper variable – Similar to a calculated variable, this variable is the result of a formula
calculation. They are global variables that are required when the number of parameters
required for a post formula cannot be passed within the argument space available.
Boolean result – As this description implies, the value is the result of a conditional
branching statement or formula that returns –1, 0, or 1 as a result.
System data variable – Values from either the system (computer) or from Mastercam
directly.
Post data variable – Value from a post numbered question in the PST file.
File name variable – The command line file name strings passed to the post executable.
For a list of numeric variable descriptions, see Volume 3, Numeric Variables.
10 String Variables
For a description of each string variable, please see Volume 3, String Variables.
String variables are variables that represent character strings in the MP language. The MP language
has only two types of variables — numeric values and character strings. Character strings contain
characters from the ASCII character set (decimal 1 to 255). String variables are identified by labels
assigned to the character strings. By using the variable label in the post customization file, you can
access the character string it represents. The string variables can be parameters passed from the NCI
file, file paths, names and extensions, or comments passed from the NCI. String variables can be
defined by the post writer to be used within the post customization file.
Note: You must be careful when creating a string variable initialization that you do not use the colon
(:) or the equal sign (=). This error makes the post executable interpret the label as a numeric
variable!
Often it is necessary to have spaces, the colon, equal sign, double quotes, single quotes, or other
characters in the character string that can cause the post executable to misinterpret the character string.
To read these characters as part of the character string, enclose the character string with double quotes
or single quotes.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 10-1
LEGACY DOC -- VERSION 9.1
Note: In all cases, the pound sign (#) is interpreted as a post comment. You must use the ASCII literal
(35) in your code or convert the ASCII number to a string.
Here are examples of string variable initializations cases:
To create an empty string, place the string label on the line by itself or with spaces and the post
comment.
string1 # Initialize with nothing following
To create a string with spaces, place the character string in double quotes.
string1 “space s” # Initialize with spaces
To create a string with characters that can confuse the post executable, place the character string in
double quotes.
string1 " : = "
To create a string that contains double quotes, place the character string inside single quotes.
string1 ‘“double quotes”’ # Initialize with ‘ (single) ‘ quotes
To create a string that contains single quotes, place the character string inside double quotes.
string1 “’single quotes’” # Initialize with “ (double) “ quotes
The pound sign and any other characters in the standard ASCII characters set in the range of 1 to 255
can be assigned to a string using the string function no2asc. This must be coded as part of a postblock,
preferably a pre-process postblock, and the resulting string can be used with the string math functions
to append the characters. For example:
string1 # Initialize an empty string
string2 TOOL # Initialize a string
pprep
string1 = no2asc(35) # Convert (ASCCI value) 35 to the ‘#’ character
string2 = string2 + string1 # String2 now is ‘TOOL#’
String literal
A string literal is a character string is enclosed by double quotes (“ ”). The syntax implies a user-
defined string variable. Output to the NC file is forced.
10-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
For example:
”M11”
The post executable creates a label for a string literal in the internal string array. The label is built with
the characters “s__” followed with its position in the internal list, for example, s__50. Do not create
user-defined string variables with similar labels.
The post executable labels dependent string literals the same as normal string literals.
ASCII literal
The ASCII literal is implied as a string by entering the decimal equivalent (0 to 255) of the desired
character as an output statement. Output to the NC file is forced.
For example:
35
is converted to the pound sign (#). The post executable creates a label for an ASCII literal in the
internal string array. The label consists of the character “s” followed by the decimal equivalent entered
on the postline, for example, s__35. Do not create user-defined string variables with similar labels.
Note: It is more efficient to initialize string variables than to imply them if the string is repeated
because the post executable creates an entry in the internal list for each implied string variable.
This is an example of the output line variables on a postline:
# String literal
"M11", e
# ASCII literal
65, 35, 65, e
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 10-3
LEGACY DOC -- VERSION 9.1
Note: Only ten ASCII literal null “0” decimal equivalents are allowed on a single postline. Do not
concatenate the token string with a formula. The token is only recognized as the token string as shown.
String variable
A string variable is predefined in the post executable or initialized in the post customization file with a
unique label as a user-defined string variable. It is presented on the output postline with out any
modifier. Output to the NC file is forced. For example:
n, stck_matl, sg00, e
If x, y and z are modal (that is, there will be no output unless the previous output was different) and any
one previous value was different, output would be similar to:
N10G00X1.Y2.Z3.
If all the previous values were the same, then the entire line would be omitted from the NC output.
10-4 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
If gcode is modal (that is, will not be output unless the previous output was different), and the previous
value was different, output (gcode = 0) would be:
N10G00X1.Y2.Z3.
If the previous value of gcode was the same, output would be similar to:
N20X2.Y3
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 10-5
LEGACY DOC -- VERSION 9.1
The NC output on each call to this output postline would produce the output following strings:
N10G00X1.Y2.Z3.
N20G00X2.
N30G00Y3.
If gcode, x, y and z are modal (that is, will not be output unless the previous output was different), and
any previous value was different for x, y and z, output would be similar to:
N10G00X1.Y2.Z3.
If all the previous values for x, y and z were the same, then the entire line would be omitted from the
NC output, even if the value for gcode is changed.
Selector debug string variable (~)
The selector string variable can be forced to output. The tilde (~) prefix forces output to the NC file for
debugging. Do not use this for normal output. For example:
~sgcode, e
String literal
A string literal is a character string enclosed with the double quotes (“ ”). The syntax implies a user-
defined string variable when parsed by the post executable. Output to the NC file is forced. For
example:
n, “G40”, “G80”, e
If gcode, x, y and z are modal and all the previous values were the same, then the entire line would be
omitted from the NC output.
10-6 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
ASCII literal
Any of the standard ASCII characters can be output to the NC file. Enter the number of the decimal
equivalent (0 to 255) of the desired character as an output statement. Output to the NC file is forced.
For example, to output the pound character (#), which is ASCII value 035:
n, “TOOL”, 35, e # This would output something like N150 TOOL#
4 # This would output the control character CTRL-D, (which mean End-Of-Transmission to some machines)
Note: Numbers in output postlines are interpreted as the ASCII decimal equivalent. In a formula
postline or Boolean postline, they are always interpreted as numbers.
See Volume 1, Postblocks for more information on postblocks and postlines.
String functions
String functions are used to convert and manipulate string variables or numeric variables with string
data associated to them. This table is an overview of the functions available for string variables.
Note: It is not recommended to use the string literals with math functions.
See Formulas for more information.
Function Name Description and example
+ String variable concatenation. Limit total line length to 79 characters.
string1 = string2 + string3 + string4
= Assignment formula. Copies string variable into result string variable.
string1 = string2
= Boolean formula. Compares string variables; case sensitive. Returns 1 if
exact match, 0 if not exact match.
if string1 = string2, paction
<> Boolean formula. Compares strings; case sensitive. Returns 0 if exact
match, 1 if not exact match.
if string1 <> string2, paction
lcase Converts a string variable to lowercase characters.
string1 = lcase(string1)
string1 = lcase(string2)
ucase Converts a string variable to all uppercase characters.
string1 = ucase(string1)
string1 = ucase(string2)
strlen Gets the number of characters in a string variable.
real_result = strlen(string1)
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 10-7
LEGACY DOC -- VERSION 9.1
10-8 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
mprint Displays a message (a string variable) to the screen. The output message is
not written to the NC output. mprint takes a single string variable or a single
numeric variable. The return value is 0 if numeric variable was passed or 1
if a string variable was passed to the function.
real_result = mprint(string1)
real_result = mprint(real_var)
After the post customization file has been parsed, the user-defined string variable will contain “300.0”.
10-10 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
11 Post Functions
This chapter describes the functions in the MP language. Functions are unique mechanisms in the MP
language that support the numeric variable format definition and assignment, string select feature, look
up table features, buffer files, user prompt feature, and tape leader/trailer generation. These function
mechanisms rely on a declaration in the post customization file for the feature, for example, defining a
look up table or buffer file, and a math formula or a command variable as the method to call the feature.
MP post functions
These are the post functions in the MP language. Because the functions are diverse and some are
complex, not all the functions are described in detail in this chapter. Refer to the chapter that is
referenced in this list for more detail on a specific function.
delay – The function stops processing for the time entered in seconds. The minimum time
accepted is a millisecond. See Volume 2, Graphics Functions for information.
fs, fs2 – The format statement is a general definition of the numeric format for the numeric
variables. See Volume 1, Numeric Variables for information on this function.
fmt – The format assignment defines a prefix string, the format statement to associate to the
numeric variable, and a suffix string. See Volume 1, Numeric Variables for information on this
function.
fnewsub – The function supports renaming a subprogram with nested subprograms for Version
9. See Volume 2, Subprograms for information on subprograms.
fstrsel – The string select function allows the post processor to assign a string variable from a
list of string variables to a target string variable based on the value of a numeric variable
selector used in this selection function.
flktbl – Lookup tables are two-column tables that associate a value in one column with a value
or variable in the matching column and returns the value from the matching column. The
formulas used to access lookup tables are: flook, frange, and finc.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 11-1
LEGACY DOC -- VERSION 9.1
fq – The user prompt function allows you to display prompts or questions in the Mastercam
prompt area at the bottom of the Mastercam application screen. The return value can be used in
the post customization file. See Volume 1, Prompt Questions for information on this function.
fbuf – Buffer files are files that you can use with the MP language as a place to store and
retrieve data. See Volume 2, How Buffer Files Work for information on this function.
fprmtbl – The NC parameters read from the NCI file or operation parameter file are not
assigned variable names but must be assigned to numeric and string variables with the
Parameter table function. See Volume 3, Parameter Information for information on this
function.
fleader – The tape leader and trailer is not truly a function, but behaves more like a command
variable. It has remained part of the post functions because of earlier design implementation.
force – This function forces the variable to output on the next output call. Modality is reapplied
from the format (fmt) statement.
fnewsub function
The fnewsub function was added to support renaming a subprogram with nested subprograms for
Version 9. V9 nested subprograms (where sub_level is initialized to 3 or 4) use the current nesting level
to control the subprogram naming. V8-type subprograms (where sub_level is initialized to 1 or 2) use
the command words newsub, newaux and newext to close a subprogram and reopen it with a different
name. V8-type subprograms were able to use the existing post subfile structure in MP, and this
mechanism remains fully functional even with nested subprograms enabled.
V9 nested subprograms are not able to use the existing subfile structure because the nesting levels are
not limited. To allow the same functionality, the fnewsub function was added. The first argument is a
string variable with the complete path and file name. The second argument is the nested level that you
want to rename the output file. The return value is 1 if successful or 0 if it fails. The numeric variable
subfile is used to determine if the file is opened new (subfile = 1) or the contents are appended (subfile =
2).
snewname "c:\mcam9\mill\nc\newname.nc"
postblock #A postblock
subfile = 1
result = fnewsub (snewname, 2)
The above closes the output file for the subprogram level two (subprogram levels are returned in the
variable sub_level) and reopens it as new with the file name (c:\mcam9\mill\nc\newname.nc).
With the subfile structure, the code would be:
snewname "newname"
postblock #A postblock
auxprg = 1
snameaux = snewname
newaux
11-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 11-3
LEGACY DOC -- VERSION 9.1
For example, a string select table can be used to output a different M code based on the value of the
numeric variable coolant. The following code illustrates this example.
# Coolant M code (string selection table)
In the example, the string select function, fstrsel, marks the string variable scoolant as the target of a
string select function. It also associates the string variable sm09 as the beginning of the implied array
(table) to make selections from, and associates the numeric variable selector coolant as the index
position in the implied array to make the selection. Each time the target string variable scoolant is
encountered on a postline, the post executable performs the following steps:
1. Get the value of the of the numeric variable selector coolant.
2. Go to the start of the implied string array sm09.
3. Index (from base zero) to the array position using the value of the numeric variable coolant.
Select the string variable in the implied string array at this index.
4. Copy the selected string variable contents to the target string variable scoolant.
5. Output the target string variable using the modality of the numeric variable selector coolant.
Update the numeric variable coolant as if it had been output to maintain modality.
Using updstr
The formula updstr is used to update the target string variable without NC output. For example:
real_result = updstr(scoolant)
See Volume 1, Formulas for more information.
11-4 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
ADDENDA
Note: You should use buffer files for very large tables. See Volume 2, Buffer Files for
information on buffer files.
The first line declares the table. It includes two integers. It must begin in the first column of
the line.
The first integer identifies the table.
The second number is the number of entries in the table.
The following lines are the individual table entries. Each consists of two numbers or
strings. The flook, frange and finc functions will use the value from the first column to
access the value from the second column.
The number of lines must match the number stated in the declaration.
Each line must be indented at least one space.
The columns of a lookup table can consist of integers, real numbers, or strings (see
below for special rules for string usage).
The following table summarizes these elements:
Note: Be sure that the “number of items in table” correctly matches the actual number of
code/match pairs! This is the only way that your post can correctly interpret the table.
ADDENDA
where
flook
The flook function looks up the closest match to a given value in column 2 and returns a
value from column 1. The following example shows a sample lookup table to look up
spindle codes (sscode) for a range of spindle speeds (ss$). The lookup value can be either
a string or numeric value.
Example 4: Using flook to return values from a table
flktbl1 10 # Define table number one with ten entries.
58 64 # sscode = 58, if ss$ < 64, = 64, or closer to 64 than 112
63 112 # sscode = 63, if ss$ is closer to 112 than 64 or 180.
64 180 # sscode = 64, if ss$ is closer to 180 than 112 or 224.
65 224 # sscode = 65, if ss$ is closer to 224 than 180 or 356.
67 450 # sscode = 67, if ss$ is closer to 450 than 224 or 710.
73 710 # sscode = 73, if ss$ is closer to 710 than 450 or 900.
74 900 # sscode = 74, if ss$ is closer to 900 than 710 or 1400.
75 1400# sscode = 75, if ss$ is closer to 1400 than 900 or 1800.
76 1800# sscode = 76, if ss$ is closer to 1800 than 1400 or 2800.
77 2800# sscode = 77, if ss$ is > 2800.
Note that the logic for the above table returns an sscode value of 77 if ss$ is closer to 2800
than 1800, and also returns the same value if ss$ is greater than 2800.
When placed on a postline, the following formula causes the post processor to return a
code from the lookup table #1 (shown above) based on the current ss$ value:
sscode = flook( 1, ss$ )
ADDENDA
frange
You can use the frange function on a lookup table to return the greatest match from
column 2 that is less than or equal to a given value, and return the corresponding value
from column 1.
For example, when the following formula is placed on a postline, it causes the post
processor to return a value from the lookup table #1 based on the current ss$ value:
sscode = frange( 1, ss$ )
finc
The finc function increments the output column of a lookup table. It looks up the closest
match in column 2 to a value and increments the code in column 1. This makes it possible
to keep count of the number of times a tool is used. The incremented count is returned.
The count then may be accessed (for reading) by flook or frange.
1 Set up the lookup table like this example:
flktbl 1 30 # Lookup table for tool usage tracking (30 entries)
0 1 # Tool number
0 2
0 3
[…remainder of the table is not shown…]
Notice that each value in the first column is 0. The second column contains a list of
tool numbers.
2 Create a user-defined variable, incorporating the finc function:
ntimesused = finc( 1, t$ ) # Increase count each time "t" is used
The first time this postline is executed, ntimesused will have the value 1, since
the initial value in column 1 is 0. At that time, the value in column 1 in the lookup
table will be incremented by 1—in whichever row corresponds to the value of t$.
Note that you cannot use finc if either column in the lookup table contains strings.
LEGACY DOC -- VERSION 9.1
Fleader command/function
The post function fleader will output a series of a selected character to the NC output. This function is
intended to provide the tape leader and tape trailer when punching paper tape. This function behaves
like a command variable. It is left over from an early design implementation and has remained
(incorrectly) as a post function.
The function operates by using the function label fleader as a trigger on an output postline. When the
function label fleader is encountered, an internal routine in the post executable is called. This routine
takes the values in the numeric variables ldrcode and ncldr and processes a program “while” loop that
continues for the value of ncldr. On each iteration of the “while” loop, the character with the ASCII
decimal equivalent of the value of ldrcode is output to the NC file.
To have a different length trailer or character, the variables ldrcode and ncldr must be reassigned locally
in the postblock and before the trigger label fleader.
Normally, fleader is placed in the beginning of the postblock pheader and at the end of the postblock
peof. For example:
11-8 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Force function
The force function was added in Version 9. It allows forcing a variable to be output on the next output
call. Modality is then reapplied from the format (fmt) statement assigned to the variable.
The following output calls reset this flag: normal output, forced output (*), and dependent output (`).
Because this function takes two arguments, a range of variables can be forced to output.
The first argument is the lower index position in the variable database. The second argument is
the higher index in the variable database. If multiple variables are specified, the variables MUST have
been defined in an “ordered-list” fashion in the post customization file!
Example 1:
result = force(x ,z)
Forces output of x, y, z on the next output postline call that references the x, y, z variables.
Example 2:
result = force(x, x)
Forces out only x on next on the next output postline call that references the x, variable.
The selector variable of a string select table can be set to be forced, the string output is then forced on
the next output.
Example 3:
result = force(gcode, gcode)
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 11-9
LEGACY DOC -- VERSION 9.1
12 Formulas
This chapter describes use of formulas in the MP language. For a description of each formula, please
see Volume 3, Formulas.
Formulas, in this discussion, are applied to the two MP language statement types that allow formulas:
the formula statement
the conditional branching statement
Both of these statement types use the same syntax in the argument portion of the statement. The major
difference between the two types are the Boolean statement, which evaluates for zero or non-zero in the
result of the formula, and the formula statement, which makes an assignment to the variable that is the
target of the formula.
Formula usage
Assignment formula types
Formula statements are assignment formulas. Assignment formulas are of three basic types:
Simple assignment—a direct assignment of a value from the right side of the equation to the
variable on the left of the equals sign.
Operator assignment—an assignment of a value calculated using the math operators. The result
of the equation is assigned to the left side variable.
Formula assignment—similar to the operator assignment but the result of a formula function.
Formula functions are different from operators in that parameters are passed enclosed in the
parenthesis following the function label.
See MP Post Formula Types for more information.
Simple assignment example:
result assignment argument
x = 2
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 12-1
LEGACY DOC -- VERSION 9.1
Operator and function assignments can be mixed and the order of evaluation controlled through the use
of parentheses.
x = abs(x) + int(y)
c = atan2((x + z), (y - 2))
12-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Initializing strings
Never use either the colon (:) or the equal sign (=) with a string variable initialization.
Example of a string variable initialization:
string1 “STRING”
Boolean formulas
Boolean statements that use the keyword ‘if’ or “while” use a Boolean formula to evaluate for a zero or
non-zero condition. Any non-zero is interpreted as a true condition. In the ‘if’ Boolean statement, a
true condition allows the action to be executed. In the “while” Boolean statement, a true condition
allows the action to be executed in a continuous loop.
The form of the Boolean formula is the same as the assignment formula except that the
‘result assignment’ is replaced with the keyword, and the action follows the statement.
Boolean formula examples:
keyword argument, action
if x, p_action
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 12-3
LEGACY DOC -- VERSION 9.1
Definitions
Before examining the operators and functions available in the MP language, you must understand the
terms that used in the operator and function descriptions. You also must understand some of the
underlying structures in the post executable, including the database order, to comprehend how the
formulas work. An understanding of these concepts is also needed to grasp the mechanism used with
functions.
Basic definitions
Cartesian coordinate system
A system that describes a point in space using three coordinate axes, any two of which are
perpendicular to one another. Each axis is labeled. The location of a point in space can be described
using ordered triple sets of positions along the three axes. Cartesian coordinate systems are also known
as rectangular coordinates, for example, x, y, z:
12-4 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Z axis
Y axis X axis
Scalar
A scalar value is a single numeric value that can be defined as a point on a number scale.
Vector
A vector is defined as a direction and magnitude. Three values are normally required to define a
vector. MP math functions always use vectors defined in the Cartesian coordinate system. The start
point is always 0,0,0 and is implied in the vector definition. The second point is a position some
distance from the start point. Thus any vector can be defined by the endpoint of the vector or the
second point. A 2D vector is a 3D vector with the Z component implied as zero.
Array
In the MP language, an array is defined by an ordered list of numeric variables that are formatted,
initialized, or predefined in the declared order. All arrays in the MP language are one-dimensional, but
you can imply multi-dimensional arrays by ordering several single dimension arrays.
var1 : 0 #User-defined numeric variables
var2 : 0
var3 : 0
var4 : 0
var5 : 0
Matrix
A matrix used in Mastercam and the MP math functions is described as the vector components of a
rectangular coordinate system. There are always nine elements in the matrix definition. The first 3D
vector describes the X axis, the second 3D vector the Y axis, and the third 3D vector the Z axis. Each
vector in the definition is unitized (see the next paragraph for a definition).
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 12-5
LEGACY DOC -- VERSION 9.1
Arrays in MP
All arrays in the MP language are one-dimensional because an array in the MP language is simply an
ordered list of variables. The order of this list is determined by the order in which the variables are
formatted, initialized, or predefined in the post executable. These can be described as implied arrays
because nothing other than the actual positions of the variables in the database denotes an array. They
are extremely sensitive to where the variables in the array are declared.
Note: Be very careful not to use predefined variables in a list of user-defined variables. It is difficult to
detect this error, and it causes unrelated variables to appear to change inexplicably.
Initialize and format numeric variables in identical order. You access the rest of the variables in the
array by selecting the first variable declared in the array. Functions using an array form as an argument
expect that the post writer has set up the variables in the correct order.
Note: A common mistake is to use the predefined variables t1 or t2 as user-defined variables in an
implied array. These labels have already been used in the intersection routines.
See Volume 1, Numeric Variables and Volume 1, String Variables for more information. Detailed
descriptions and a listing of the database order for all predefined numeric variables and predefined
string variables are provided in Volume 3, Numeric Variables and Volume 3, String Variables.
value: A number, real or integer, directly inserted in the formula. For example:
10.
string literal: Character string consisting of alphanumeric characters surrounded by double quotes (“”).
For example:
“ABC123”
Note: MP does not support the use of string literals in formulas. Declare a user-defined string
and use the string variable name as an argument.
string: Character string variable consisting of alphanumeric characters. For example:
string1 “ABC123”
2d vector: Two numeric variables representing a planar vector. This form is also used to represent a
planar point. For example:
Note: It is recommended that you always use 3D vectors, even with 2D vector routines.
v2_x : 1
v2_y : 1
v2_z : 1 # Not used but recommended
3d vector: Three numeric variables representing a vector with direction in space. This form is also
used to represent a point in space. For example:
v3_x : 1
v3_y : 1
v3_z : 1
line: Two 3D vectors representing the line end points in space. For example:
v3_x1 : 1 # Endpoint one
v3_y1 : 1
v3_z1 : 1
v3_x2 : 1 # Endpoint two
v3_y2 : 1
v3_z2 : 1
arc: One 2D vector, a scalar, and two angle variables. Five ordered variables are expected; arc center
on X, arc center on Y, radius, start angle, and the arc sweep. For example:
v2_xc : 1
v2_yc : 1
radius : 1
astart : 1
asweep : 1
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 12-7
LEGACY DOC -- VERSION 9.1
matrix: Three 3D vectors representing the X axis, Y axis, and Z axis. For example:
v3_xx : 1 # Vector representing X axis
v3_xy : 0
v3_xz : 0
v3_yx : 0 # Vector representing Y axis
v3_yy : 1
v3_yz : 0
v3_zx : 0 # Vector representing Z axis
v3_zy : 0
v3_zz : 1
array: The array or listing can be any size that is needed. If the variables are user-defined, they must
be declared in the post customization file in the order required by the function. For example:
Note: Be careful to avoid using predefined variables in the ordered declarations. If you are using
predefined variables, check the database order tables to determine how they are listed in memory.
Numeric variables and string variables cannot be mixed in the implied array. Each type is considered
separately.
If the array consists of user-defined numeric variables and you must format and initialize the variables.
The full array should then be included in both definitions.
Following is an example of 3D array initialization and format assignment.
v3_x : 1
v3_y : 1
v3_z : 1
fmt X 1 v3_x
fmt Y 1 v3_y
fmt Z 1 v3_z
Formula structure
A formula can be structured in many different ways depending on where it is used (assignment formula
or Boolean formula) and what arguments are contained in it. This section describes what variable types
can be combined in a formula, order of precedence, and the return types. The individual formula
descriptions give a detailed explanation of use and function.
12-8 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Nesting types
Formulas are of three basic types:
Simple assignment
Operator assignment
Formula assignment
These types can be combined or nested in an equation to perform calculations or resolve conditional
branching statements (‘if’ and “while”). The return type for the conditional branching statement must
always be a numeric value. This return value is a predefined numeric variable in the post executable
and has the label bool____result. The post executable examines this variable to see if it is 0 (false) or
non-zero (true) in evaluating the branching statement.
Note: Do not use bool____result directly because it is for internal use only in the post executable!
Formula assignments can be nested wherever the return type is a single numeric or string variable that
matches the argument type to be passed, for example:
result = (no2asc(65) = str_cap_a) + 1
Notice that the ASCII decimal “65” is converted to the character “A”, making a Boolean comparison to
the string (assuming it is also “A”), and adding the result of the comparison to the value 1. The result in
this case is 2.
The preceding example illustrates that the assignment types can be freely mixed as long as the rules are
followed relating to type matching. For example:
# Simple assignments
x = 1
x = y
str1 = str2
# Operator assignments
x = x + y
x = x^y
str1 = str2 + str3
# Formula assignments
c = abs (c)
c = atan2 (x, y)
str1 = no2str (65)
Do not nest vector or matrix function that return to a vector, matrix or implied array. These functions
must be coded on a separate line in the customization file and return to a vector, matrix or implied array
that is declared in the post or as predefined variables.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 12-9
LEGACY DOC -- VERSION 9.1
Only formulas that return a scalar or single string may be nested. For example, assume these defined
arrays:
v3_x1 : 1
v3_y1 : 1
v3_z1 : 1
v3_x2 : 1
v3_y2 : 1
v3_z2 : 1
v3d_x2 : 1
v3d_y2 : 2
v3d_z2 : 3
v3d_xr : 0
v3d_yr : 0
v3d_zr : 0
The function call would use the first variable name from the implied array definitions and access the
immediately following variable names:
v3d_xr = vadd (v3d_x1, v3d_x2)
12-10 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Precedence of operation
How a formula is evaluated is based on the precedence of its operators in relation to each other.
Following is a chart that describes the precedence of operation in MP language formula parsing. Those
operators with the highest precedence are at the top of the table. Highest precedence operators are
evaluated first from the left to the right in the formula statement.
Precedence can be controlled by using open and close parentheses. Do not confuse them with the
parentheses that encapsulate the formula parameters in formula functions. These must be used to
define the arguments passed with a function and can be considered part of the individual formula.
Precedence Operator
Symbol Description
= equal
<> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal
not opposite result of a logic statement
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 12-11
LEGACY DOC -- VERSION 9.1
The logic operators for comparison are combined with the logic operators “and” (&) or “or” ( | ) to
evaluate the true and false intermediate results in the following way:
The logic operators for comparison(<, >, =, and not) can be combined with & and | .
For example:
x>0&y>0 # Using the & (and) logic operator
abs (x) > 1 | x = 0 # Using the | (or) logic operator
12-12 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
A single “else” keyword can be used to follow a Boolean postline (conditional branching statement and
action). If the conditional branching statement evaluates true, then the action after the statement is
executed. If the conditional branching statement evaluates false, then the action after the “else”
keyword is executed instead. For example:
if x = y, x = prv_x
else, y = prv_y
Rules for using “if”, “while” and “else” conditional branching statements
“if,” “while”, and “else” keywords cannot start in the first column.
Put a space between the keyword “if,” or “while” and the Boolean formula. For example:
valid : if x = 1, x = 0
invalid: ifx < y, x = y # Requires a space
Put a comma delimiter after the Boolean formula. For example:
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 12-13
LEGACY DOC -- VERSION 9.1
The post executable considers only a single statement after the delimiter comma to be part of the
preceding conditional branching statement. For example:
valid: if x > 0,
“x is positive”, e
invalid: if x > 0 & y > 0,
“x is positive”, e
“y is positive”, e # “y is positive,” will be output even
# if “(x > 0) & (y > 0)” evaluates to false.
invalid: if x = 0 | y = 0, “x or y, or both, are zero”
else, “x is nonzero”
“y is nonzero” # “y is nonzero” will always be
# output, whether “x = 0 | y = 0”
# evaluates to true or false.
Note: If more than one postline is needed with an “if”, “while” or “else”, call a separate postblock or
use bracketed postblocks.
See Volume 1, Postblocks for more information.
A conditional branching statement cannot be the action of the conditional branching statement.
For example:
Note: Use a separate postblock or use bracketed postblocks to nest the conditional branching
statement.
See Volume 1, Postblocks for more information.
Instead of changing the limit, for MU1 the limit has been removed. Beginning with X4 MU1 you
can use the Escape key to terminate a while loop. When the Escape key is pressed, MP will
terminate the while loop and continue processing the rest of the post.
12-14 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Trigonometric functions– Standard trigonometric functions for sine, cosine and tangent of an angle.
An extremely useful function atan2 returns the solution of the arc tangent within the 360 degree range.
2D vector math – Single plane functions for vector addition and subtraction, and scaling. Even when
working in a single plane, it is recommended that you describe numeric variables as 3D positions. 2D
vector math functions are used less frequently because the 3D vector math functions are more
powerful.
3D vector math – 3D functions for vector addition and subtraction. Functions to rotate vectors and
points about an axis are also provided in this category.
Matrix math – Matrix functions allow for mapping within the matrix that defines a Cartesian coordinate
system. Other matrix manipulation functions such as matrix transpose are also available.
Special MP functions– Calls to the lookup table functions and buffer file function. Other unique
formulas to determine the negative, zero, or positive of a numeric variable are provided here.
Intersection functions – Planar intersection routines for line-line, arc-line and arc-arc.
String functions – String manipulation functions. String variables can be broken, values scanned from
a string, case changed, etc.
Conversion functions – Formulas to convert strings to numeric variables.
File functions – Powerful file manipulation functions to rename and remove files. File functions also
allow launching another program or Mastercam C-Hook.
Precedence functions – Parentheses are used to control the precedence in an assignment formula or a
Boolean formula.
Binary functions – Bit-wise functions.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 12-15
LEGACY DOC -- VERSION 9.1
Logic operators
&
|
<
<=
<>
=
>
>=
not
Trigonometric functions
acos
atan
atan2
cos
sin
tan
2D vector math
axb
dot
lng
12-16 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
rot
vad
veq
vlh
vnr
vrh
vsa
vsb
vsc
3D vector math
dot3
lng3
rotp
rotv
vadd
vaxb
vequ
vnrm
vsca
vscl
vsub
Matrix math
matt
mmap
mmul
mteq
vmap
Special MP functions
finc
flook
fprm
frange
fsg1
fsg2
fsg3
updgbl
rbuf
rpar
slin
slout
vlin
vlout
wbuf
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 12-17
LEGACY DOC -- VERSION 9.1
Intersection functions
xaa
xla
xll
String functions
brksps
lcase
nwadrs
scan
strlen
strstr
ucase
updstr
Conversion functions
newfs
no2asc
no2str
plcval
File functions
dll
fclose
fexist
launch
mprint
remove
rename
runvbs
Precedence functions
(
)
Binary functions
and
ger
good
ior
xor
12-18 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
Volume 1 Chapter 13 The NCI File
[This material in this chapter has been replaced by the NCI & Post Parameter Reference.]
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 14-1
LEGACY DOC -- VERSION 9.1
Null tool changes (NCI Gcode 1000) had been required to introduce the tool plane matrix necessary to
determine the angular movement, which required the drill cycle to be cancelled (NCI Gcode 80) for
each drill position in a new tool plane.
The new format also simplified the interpretation of 5-axis drilling because formerly there was no
vector data on the actual drill cycle (NCI Gcode 81). The post executable had to save the drill data
until the position move with 5-axis drilling.
Because of these changes, it has been necessary to provide a conversion process in the post executable
file to support the thousands of posts that were created before Mastercam V8 universal drilling format.
In the new NCI drilling format, the position data is described as a line with 3-dimensional endpoints at
the position represented by the bottom of the hole and the initial position of the tool above the drill
hole. Scalar positions along this line are then presented for the reference point, the top of stock, and the
point selected in Mastercam for the drill location.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-1
LEGACY DOC -- VERSION 9.1
To keep the existing post customization files compatible and, in general, to provide more usable data to
the post writer, the NCI data is then converted to represent the data as in the earlier NCI format. The
data presented for 3-axis drilling and 5-axis drilling has always been different, and those differences
have been maintained.
NCI Gcode 81
The following table describes the two-line set of NCI Gcode 81 (which defines the drill cycle) data
read from the NCI file. The second line shows the parameters that are written to the line. Below the
represented NCI line set is a table with a description of each parameter that was written.
Note: The table does not list the specific variable labels for the NCI values, just a description of each
parameter value. See Volume 3, The NCI File for detailed descriptions.
81
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Parameter Description
15-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Parameter Description
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-3
LEGACY DOC -- VERSION 9.1
Variable Description
Label
refht Absolute position of the Z location of the reference height
initht Absolute position of the Z location of the initial height
tosz Absolute position of the Z location of the top of stock
u Absolute X position of the initial height point
v Absolute Y position of the initial height point (zero in Lathe)
w Absolute Z position of the initial height point
cur_cflg Control flags
rev_drl5 Reverse the drill direction from the UVW point to the XYZ point (as read).
Variable Description
Label
drillcyc Drill cycle type (as read):
100: Simple drilling
101: Peck drilling
102: Chip break
103: Tap
104: Bore #1
105: Bore #2
106: Misc. #1
107: Misc. #2
108-119: Custom cycles
xnci Absolute X position of the drill point at the bottom
ynci Absolute Y position of the drill point at the bottom (zero in Lathe)
znci Absolute Z position of the drill point at the bottom
depth Incremental distance from reference height to the bottom.
dwell Dwell time (as read)
frplunge Feed rate (as read)
15-4 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Variable Description
Label
peck1 Incremental distance, first peck amount (as read)
peck2 Incremental distance, additional peck amounts (as read)
peckclr Incremental distance, peck clearance (as read)
retr Incremental distance, chip break retract (as read)
shftdrl Incremental distance, boring bar clearance shift amount (as read)
zdrl The selected drill point (always zero)
refht Incremental distance from the selected drill point to reference height.
initht Incremental distance from the selected drill point to initial height.
u Absolute X position of the reference height point
v Absolute Y position of the reference height point
w Absolute Z position of the reference height point
cur_cflg Control flags
rev_drl5 Reverse the drill direction from the UVW point to the XYZ point (as read).
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-5
LEGACY DOC -- VERSION 9.1
The text that appears on this dialog can be customized. See Volume 1, Post TXT File
The following table documents the two-line set of NCI Gcode 82 (which defines “additional” custom
parameters that may be used for a canned drill cycle) data read from the NCI file.
15-6 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
82
1 2 3 4 5 6 7 8 9 10
Variable Description
Label
drl_prm1 Drill parameter 1
drl_prm2 Drill parameter 2
drl_prm3 Drill parameter 3
drl_prm4 Drill parameter 4
drl_prm5 Drill parameter 5
drl_prm6 Drill parameter 6
drl_prm7 Drill parameter 7
drl_prm8 Drill parameter 8
drl_prm9 Drill parameter 9
drl_prm10 Drill parameter 10
Note: The drl_prm# variables do not have a specific meaning; they are values that the post
customization file can use for whatever purpose needed for that cycle.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-7
LEGACY DOC -- VERSION 9.1
Parameter Description
1 Drill cycle type
2 Absolute X position of the drill point at the bottom
3 Absolute Y position of the drill point at the bottom
4 Absolute Z position of the drill point at the bottom
5 Distance from the selected drill position to the initial height, sign positive for above
selected drill position
6 Distance from the selected drill position to the reference height, sign positive for above
selected drill position
7 Dwell time
8 Feed rate
9 Absolute U position of the initial height point
10 Absolute V position of the initial height point
11 Absolute W position of the initial height point
12 Control flags
13 Reverse the drill direction from the UVW point to the XYZ point.
14 Top of stock, the distance from the selected drill position (zdrl) to the top of stock, sign
positive for above zdrl
15 Drilling matrix XX
16 Drilling matrix XY
17 Drilling matrix XZ
18 Drilling matrix YX
19 Drilling matrix YY
15-8 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
20 Drilling matrix YZ
21 Drilling matrix ZX
22 Drilling matrix ZY
23 Drilling matrix ZZ
See Volume 3, Numeric Variables for addition ‘drl_???’ variables that MP calculates from this NCI
data.
See Volume 3, The NCI File for additional details.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-9
LEGACY DOC -- VERSION 9.1
The NCI Gcode 100 variables are unique in that the numeric variables for u, v and w are relative to the
original tool plane matrix defined with the NCI Gcode 81 tool change preceding the NCI Gcode 100.
This rotation, which is defined with the rotary axis selection in Mastercam, is used by the post
executable to create a new tool plane matrix relative to the NCI Gcode 100 drill position. Backwards
compatibility is maintained by rotating the NCI data for the endpoints into the new tool plane.
Variable Description
Label
xnci Absolute X position of the drill point at the bottom
ynci Absolute Y position of the drill point at the bottom (zero in Lathe)
znci Absolute Z position of the drill point at the bottom
depth Absolute Z position of the drill point at the bottom
dwell Dwell time (as read)
frplunge Feed rate (as read)
zdrl Absolute position of the Z location of the selected drill point
refht Absolute position of the Z location of the reference height
u Absolute X position of the initial height point
v Absolute Y position of the initial height point (zero in Lathe)
w Absolute Z position of the initial height point
cur_cflg Control flags
rev_drl5 Reverse the drill direction from the UVW point to the XYZ point (as read).
15-10 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Variable Description
Label
xnci Absolute X position of the drill point at the bottom
ynci Absolute Y position of the drill point at the bottom (zero in Lathe)
znci Absolute Z position of the drill point at the bottom
depth Incremental distance from reference height to the bottom.
dwell Dwell time (as read)
frplunge Feed rate (as read)
zdrl The selected drill point (always zero)
refht Incremental distance from the selected drill point to reference height.
u Absolute X position of the reference height point
v Absolute Y position of the reference height point
w Absolute Z position of the reference height point
cur_cflg Control flags
rev_drl5 Reverse the drill direction from the UVW point to the XYZ point (as read).
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-11
LEGACY DOC -- VERSION 9.1
In earlier versions of Mastercam, this rapid position was never written and the post customization file
would either call back to the tool change postblock or create the rapid positioning during the drill cycle
postblock calls. With the introduction of the mandatory rapid position in the NCI file, errors during
posting and in the NC output can be generated in posts written for the earlier NCI format when the
added rapid NCI line is encountered.
To avoid these problems, the numeric variable rpd_typ_v7 is added to the post customization file and is
set to 1. rpd_typ_v7 skips the rapid position after the tool change in the NCI file and reads the next two-
line set from the NCI file. This is usually the drill cycle definition (NCI Gcode 81) that was expected
by the older post customization file. rpd_typ_v7 also skips the new long code drilling calls if set on and
rotaxtyp is set to less than 6. See Volume 2, Rotary Processing for more information.
15-12 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Drill cycle long code processing has been enhanced in the post executable file when the numeric
variable rpd_typ_v7 is disabled (that is, omitted or set to 0). The enhanced drill cycle long code provides
support in the post executable for tap, bore1, bore2, misc1 and misc2 drilling and boring cycles. All
these cycles are also supported with 5-axis drilling.
When numeric variable rpd_typ_v7 has been enabled, as required for earlier post customization files, the
long cycle drill motion must be explicitly generated in the post customization file for 5-axis drilling and
the tap, bore1, bore2, misc1 and misc2 drilling and boring cycles.
Note: With rpd_typ_v7 enabled, tap, bore1, bore2, misc1 and misc2 drilling and boring cycles call the
drill (feed in, rapid out) long code output.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-13
LEGACY DOC -- VERSION 9.1
The following tables describe the enhanced drill cycle long code, the variables modified, and postblock
calls generated.
15-14 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-15
LEGACY DOC -- VERSION 9.1
15-16 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Tap (drillcyc = 3)
Action Description Variables Calls
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-17
LEGACY DOC -- VERSION 9.1
15-18 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-19
LEGACY DOC -- VERSION 9.1
15-20 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
The variable rtnrefht controls the Z-axis location where a drill cycle returns, as follows:
When rtnrefht = 0, return to the location of the initial height (initht).
When rtnrefht = 1, return to the location of the reference height (refht ).
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-21
LEGACY DOC -- VERSION 9.1
This is important with canned drill cycle calls because the last Z location perceived by the post
executable is at the final drill depth. With the long code output enabled (that is, when one of the
usecan… variables is set to 0), the final position is controlled by the position output with linear motion
generated in the post executable. The canned drill cycle output returns the Z location internally just
before the call to the postblock pcanceldc by setting the numeric variable z. There is no Z location
adjustment if this is a 5-axis drill routine (drill5 = 1). In the postblock pcanceldc the numeric variable z
should be updated.
pcanceldc # Cancel canned drill cycle
!z
n, "G80", e
Any other position can be stated as the last Z drill position by explicitly defining z or prv_z in the
postblock pcanceldc. For example:
pcanceldc # Cancel canned drill cycle
z = 10.
!z
n, "G80", e
pdrlcst8_2 # Custom drill cycle 8 (call active cycle for subsequent positions)
15-22 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
n, “REP”, x, y, z, e
pdrlcst9_2 # Custom drill cycle 9 (call active cycle for subsequent positions)
n, “REP”, x, y, z, e
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-23
LEGACY DOC -- VERSION 9.1
15-24 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-25
LEGACY DOC -- VERSION 9.1
Cut type
This is a user-defined variable in the MPFAN.PST that designates the cut type.
cuttype : 0 #Cut type flag
# 0 = Tool Plane, 1 = Axis Subs, 2 = Polar, 3 = 4/5 axis
15-26 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
M R canceldc
Variable Type Command
Category Drilling (v9.1+)
Description The command post variable and post switch combination
variable canceldc allows the post to call the postblock pcanceldc
to cancel an active canned drillcycle .
Initialize this variable with one (1) and MP uses the state of the
canned cycle to re-initialize the canned cycle if cancelled.
When a canned drill cycle is called and the NCI Gcode is 100
(repeat cycle), the state is checked and the Gcode 100 is
converted to Gcode 81 and the canned drillcycle definition
postblock is called.
Values
0 Not active
1 Active
Code Example None
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-27
LEGACY DOC -- VERSION 9.1
M R L drillcyc
Variable Type NCI variable
Category Drill
Description Type of canned drill cycle.
Values (See note below)
0 Simple
1 Peck
2 Chip break
3 Tap
4 Bore #1
5 Bore #2
6 Misc #1
7 Misc #2
8-19 Custom cycles
Code Example None
Notes When doing 5-axis drilling, each value shown above has ‘100’
added to it when the pdrill0 postblock is called. On exit from the
pdrill0 postblock, this ‘100’ gets subtracted out by MP
executable.
See the related drl_cycle variable (v9.1)
15-28 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
M R drl_cycle
Variable Type NCI
Category Drilling (v9.1+)
Description The drill cycle code value from the Gcode 81 NCI line.
This is not manipulated for 5-axis drill cycle reverse
compatibility.
Values
0 Simple
1 Peck
2 Chip break
3 Tap
4 Bore #1
5 Bore #2
6 Misc #1
7 Misc #2
8-19 Custom cycles
Code Example None
Notes See the related drillcyc variable, which has ‘100’ added to it
when 5-axis drilling.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-29
LEGACY DOC -- VERSION 9.1
M R drl_cycle_actv
Variable Type Calculated
Category Drilling (v9.1+)
Description Added to allow the post to see the active state of a canned cycle.
Values
0 Not active
1 Active
-1 Active (after a Gcode 100 NCI lines has been read)
Code Example None
Notes When pdrill0 is called on the cycle definition start, the setting of
drl_cycle_actv is 0.
Once the canned cycle is active, drl_cycle_actv is set to 1.
In this state, a call to the pcanceldc postblock; either from an NCI
gcode 80 or from the command variable canceldc will
successfully call the pcanceldc postblock. A call to pcanceldc sets
drl_cycle_actv to 0.
If a NCI gcode 100 is read, drl_cycle_actv is set to -1. This forces
an artificial call to the drillcycle definition postblock and
reestablishes the drill cycle.
See canceldc for related information.
15-30 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-31
LEGACY DOC -- VERSION 9.1
M R drl_plane
Variable Type Calculated
Category Drilling (v9.1+)
Description The plane relative to the drill direction motion.
Values
-1 no match
0 for direction only in Z
1 for direction only in X
2 for direction only in Y
Code Example None
Notes
15-32 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-33
LEGACY DOC -- VERSION 9.1
fsg1
Formula Type Advanced Math Functions
Description Returns:
0 for values less than 0.
1 for values greater than or equal to 0.
Form function argument
Argument numeric variable, value (scalar)
Return Type numeric variable (scalar)
Formula Code Ex. real_result = fsg1(x)
Notes Nested return values are stored internally to the post executable.
fsg2
Formula Type Advanced Math Functions
Description Returns:
0 for values equal to 0.
1 for values not equal to 0.
Form function argument
Argument numeric variable, value (scalar)
Return Type numeric variable (scalar)
Formula Code Ex. real_result = fsg2(x)
Notes Nested return values are stored internally to the post executable.
15-34 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
M R opcode
Variable Type NCI variable
Category Tool change information, Operation type
Description Operation code of the current Mill / Router operation.
Values
0 Neither
1 2D contour
2 3D contour
3 Drill
4 Pocket
5 Ruled
6 2D swept
7 3D swept
8 Revolution
9 Loft
10 Coons
11 Fillet
12 Flowline
13 Multisurface finish
14 Multisurface rough
15 Point
16 Drill 5-axis
17 Swarf 5-axis
18 Curve 5-axis
19 Face
Code Example None
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-35
LEGACY DOC -- VERSION 9.1
M R L plane
Variable Type NCI variable
Category Motion
Description Current cutting plane.
Values
0 XY plane, G17
1 YZ plane, G19
2 XZ plane, G18
Code Example Mill exmaple:
parc # IJK arc center output
if plane = zero, *i, *j, k # G17 plane - force I & J output
if plane = one , i, *j, *k # G19 plane - force J & K output
if plane = two , *i, j, *k # G18 plane - force I & K output
Notes
15-36 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
ss_underflow
Variable Type Post switch variable
Category Post switch, Process modification
Description Allows the string select variable to be a value less than zero.
Values
0 Not active
1 Active
Code Example sg-17 G17 # Plane code whnd drill direction is skewed
sg17 G17 # XY plane code
sg19 G19 # YZ plane code
sg18 G18 # XZ plane code
sgplane
fstrsel sg-17 plane sgplane
Notes If the ss_underflow switch is not active, and the string selector
variable is less than zero, MP will halt with an error.
New starting with Version 9.10 of the MP DLLs
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-37
LEGACY DOC -- VERSION 9.1
lng3
Formula Type 3D vector math function
Description Returns the length of the argument (vector).
Form function argument
Argument numeric variable (3D vector)
Return Type numeric variable (scalar)
Formula Code Ex. real_result = lng3(v3_x1)
Notes
15-38 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
vlin
Formula Type Special MP function
Description Writes a value to a numeric variable at specified offset from the
numeric variable passed as the second argument. The first parameter
indicates the position to offset from the base position, represented by
the second argument, relative to the database order of the numeric
variables.
Note the usual direction of this function. real_var1 is on the left side of
the equation (the “=” sign), but it is really the input variable. The
output of this function is loaded into the numeric variable whose
address is derived from the address of real_var2 plus the offset (1 in the
example below). The numeric variable represented by what would
normally be considered the return variable is passed to the offset of the
second argument.
Form function argument, argument
First Argument numeric variable, value (scalar)
Second Argument numeric variable
Return Type numeric variable
Formula Code Ex. real_var1 : 1 #User-defined numeric variables
real_var2 : 0
real_var3 : 0
pblock # A postblock
real_var1 = vlin(1, real_var2)
In this example, real_ var3 would receive the value 1 from real_var1.
Boolean Code Ex. Not allowed as a Boolean statement
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-39
LEGACY DOC -- VERSION 9.1
vlout
Formula Type Special MP function
Description Reads a value from a numeric variable located at a specified offset
from the numeric variable passed as the second argument. The first
parameter indicates the position to offset from the base position,
represented by the second argument, relative to the database order of
the numeric variables. The contents of the numeric variable at the
offset from the second argument is passed to the return variable
Form function argument, argument
First Argument numeric variable, value (scalar)
Second Argument numeric variable
Return Type numeric variable
Formula Code Ex. real_var1 : 0 #User-defined numeric variables
real_var2 : 0
real_var3 : 1
pblock # A postblock
real_var1 = vlout(1, real_var2)
In this example, real_ var1 would receive the value 1 from real_var3.
Boolean Code Ex. Not allowed as a Boolean statement
Notes This function can be used in a “while” loop to assign a values from the
database ordered variables.
See vlin for related information.
15-40 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
vsub
Formula Type 3D vector math function
Description Subtracts two vectors. The elements in the implied array are
subtracted: argument one – argument two.
Form function argument, argument
First Argument numeric variable (3D vector)
Second Argument numeric variable (3D vector)
Return Type numeric variable (3D vector)
Formula Code Ex. v3_resx = vsub(v3_x1, v3_x2)
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 15-41
LEGACY DOC -- VERSION 9.1
vequ
Formula Type 3D vector math function
Description Copies a vector. Copies the argument (vector) to the result (vector).
The term used for this formula is vector equate.
Form function argument
Argument numeric variable (3D vector)
Return Type numeric variable (3D vector)
Formula Code Ex. v3_resx = vequ(v3_x1)
15-42 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
MP posts from versions prior to Version 8 must be modified to take advantage of this new feature.
When selecting canned text and processing with an older MP-style post, the first canned text entry from
the Canned Text Gcode 1025 line is placed in the variable cantext and is processed as in prior versions.
All other entries are ignored.
Each of the 10 parameters has a 1-, 2-, or 4-place value (for example, 0, 12, or 1012). An unused
parameter will always be 0. Unused parameters exist because there are 10 parameters available and
you may need to use only one or two.
Note: All logic to interpret the cant_pos position flag and the cant_val canned text value must be written
into the post customization file.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 16-1
LEGACY DOC -- VERSION 9.1
g
1 2 3 4 5 6 7 8 9 10
Cant_pos1 … cant_pos10
The variables cant_pos1 … cant_pos10 represent the position where the canned text will be output for
parameters 1 through 10 on the 1025 line. The possible values of cant_pos are:
1 and 2 are the only 1000s place values that appear on the 1025 line. A cant_pos value of –1 (off) is
indicated by no 1000s place value and 0 (unused) for the parameter. A cant_pos value of 0 is indicated
by no 1000s place value and a value greater than 0 for the parameter.
cant_val1 … cant_val10
The variables cant_val1 through cant_val10 represent the actual cantext value for parameters 1 through
10 on the 1025 line. There can be up to 99 different canned text values, so cant_val will equal a value
of 1 through 99. Mastercam and the MP language associate the user’s canned text selection only with a
value of 1 through 99.
The post writer must modify the post .TXT file to display the proper text in the Mastercam Canned
Text dialog box for the up to 99 canned text possibilities.
For more information, see Customizing the post.TXT file to display text in Mastercam.
16-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
The post writer must also modify the post to output the correct string or value based on the value (1-
99) of cant_val. For more information, see Customizing the post to associate the cant_val with the
correct output string, output variable, or post action.
cant_no
The variable cant_no represents the number of non-zero parameters on the 1025 line (that is, the
number of canned text parameters used on that particular 1025 line.) Cant_no can be used to determine
whether there is any canned text being output from a 1025 line.
With a test such as “if cant_no > 0”, you can determine whether it is necessary to break down the
parameters on the 1025 line or skip the line and move on, that is, when cant_no is not greater than 0 and
there is no canned text to be output.
1025 is the NCI Gcode that indicates a canned text line. The 10 values on the next line are the 10
canned text parameters that will be output by this line. (Up to 10 canned text parameters can be output
at the same time.) In this case, there are four (non-zero) parameters for output, so cant_no would equal
4.
The first parameter is 2, so cant_val1 = 2. There is nothing in the 1000s place, so cant_pos1 = 0 and it
will be output before the linear move that appears on the next NCI line.
The second parameter is 9, so cant_val2 = 9. There is nothing in the1000s place, so cant_pos2 = 0 and
it will be output before the linear move that appears on the next NCI line.
The third parameter is a 1006, so cant_val3 = 6. There is a 1 in the 1000s place, so cant_pos = 1 and it
will be output with the linear move that appears on the next NCI line.
The fourth parameter is a 2010, so cant_val4 = 10. There is a 2 in the 1000s place, so cant_pos = 2 and
it will be output after the linear move that appears on the next NCI line.
Parameters will be output in order of their ‘before’, ‘with’, and ‘after’ designations, and then in the
order they were selected from the Canned Text dialog box. Notice that parameter 1 and parameter 2
are both to be output before the linear move that appears on the next NCI line. In this example,
parameter 1 will be output, and then parameter 2 will be output. Parameter 3 will be output with the
linear move. Finally, parameter 4 will be output after the move.
To customize the text that appears in Mastercam’s Canned Text dialog box, list the text to be displayed
line after line in a numeric list. You can have up to 99 lines or items in this list. This text is for display
in Mastercam only. It is not the text that will appear in the NC output, which is defined in the post
customization (.PST) file. Both the post .PST and .TXT files must be updated when making changes to
canned text.
This also means the text in the post .TXT file (which will be displayed in Mastercam’s canned text
dialog box) does not have to be the same text that will be output to the NC file. For example, the post
.TXT file can display “Stop”, as seen in the example below, and the post .PST file can be set up to
output “M00”. However, you should associate cant_val1 with line 1, cant_val2 with line 2, etc.
Here is an example of the canned text section of a Lathe post .TXT file:
[canned text]
1. "Stop"
2. "Ostop"
3. "Bld on"
4. "bLd off"
5. "rEt. tlstk"
6. "adV. tlstk"
7. "Ret. chute"
8. "Adv. chute"
9. "eXstp on"
10. "exstP off"
11. "Canned Text 11"
12. "M12"
13. "M13"
14. "M14"
15. "M15"
16. "M16"
See Volume 1, Post TXT File for more information
16-4 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
The calls to pcan, pcan1, and pcan2 must be made by adding them into postblocks in the appropriate
places to create ‘before’, ‘with’, and ‘after’ results. Look at the following a plinout postblock as an
example of how the calls to pcan, pcan1, and pcan2 might be made. pcan is called ‘before’, pcan1 is
called ‘with’, and pcan2 is called ‘after’. strcantext is the string that actually outputs canned text.
# -------------------------------------------------------
# Canned Text
# -------------------------------------------------------
The pcan postblock will be called by a postblock such as plinout. pcan clears any existing value to
strcantext, and then tests cant_no to see if there is any canned text to be output. If not, it returns to plinout
and continues processing.
If there is canned text to be output, it tests each of the 10 positions on the 1025 line to see if the canned
text is to be output ‘before’. (It’s currently in the pcan postblock, which is only going to output ‘before’
parameters.) If anything is found that should be output ‘before’, the appropriate pcant_? postblock is
called to extract the cant_val and take it to the pcant_out postblock, where the output string (strcantext) is
built. Finally, it returns here to pcan, outputs the strcantext string, and continues until all ‘before’
parameters have been processed and it can return to plinout.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 16-5
LEGACY DOC -- VERSION 9.1
The pcan1 postblock works very similarly to pcan, except for two major differences:
pcan1 allows canned text to pass when cant_pos = 1 for ‘with’ output.
Upon returning from pcant_out to pcan1, pcan1 does not output the strcantext string. Since it is being
output ‘with’, it is left so strcantext can be output on the line it is supposed to be ‘with’. This way, it
can be output in the desired order on the output line (on the NC line that is generated in postblock
plinout in this example).
pcan2 works almost the same as pcan, except pcan2 is looking for ‘after’ parameters.
pcant_1 through pcant_10 simply set the variable cantext equal to the cant_val being processed and call
pcant_out to build the output string.
16-6 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
The pcant_out postblock builds the output string, that is, turns a value such as 1 into M00. In this post,
the last five lines of code mean any cantext value (or cant_val – cantext was set equal to cant_val? in the
previous postblock) greater than 4 will simply output the cantext value with an “M” in front of it. A
cantext value of 5 would output an “M5” to the NC file (lines marked #8 through #12).
In most cases, adding more options to the list of available canned text requires just a few simple steps:
Modify the post .TXT file to display the correct text.
Define the output string.
Make two changes to the pcant_out postblock.
Note: Refer to the numbers at the end of each line in the pcant_out postblock shown in the preceding
section for this example.
1. Customize the post .TXT file, which is the only way to enable the use of the modifications you
make and have them visible while in Mastercam. Line 5 of the canned text section in
MPFAN.TXT has been modified here:
[canned text]
1. "Stop"
2. "Ostop"
3. "Bld on"
4. "bLd off"
5. "M52"
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 16-7
LEGACY DOC -- VERSION 9.1
3. Add a postline to pcant_out to build the sm52 string into the strcantext output string when cantext = 5.
After line 7, add the following line:
If cantext = 5, strcantext = strcantext + sm52
4. Since a cantext value of 5 now has special output defined, it is necessary to modify the line
(if cantext > 4,) to read:
if cantext > 5,
Original MPFAN.PST:
pcant_out # Canned text - build the string for output
# Assign string select type outputs
if cantext = three, bld = one
if cantext = four, bld = zero
# Build the cantext string
if cantext = one, strcantext = strcantext + sm00
if cantext = two, strcantext = strcantext + sm01
if cantext > four,
[
strtextno = no2str(cantext)
strcantext = strcantext + strm + strtextno
]
Altered MPFAN.PST:
sm52 “M52” # Define the string that will be output for cantext option 5
pcant_out # Canned text - build the string for output
# Assign string select type outputs
if cantext = three, bld = one
if cantext = four, bld = zero
# Build the cantext string
if cantext = one, strcantext = strcantext + sm00
if cantext = two, strcantext = strcantext + sm01
if cantext = five, strcantext = strcantext + sm52
if cantext > five,
[
strtextno = no2str(cantext)
strcantext = strcantext + strm + strtextno
]
16-8 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
When you enter the Canned Text dialog with this altered MPFAN.PST active, you will see a display
similar to the dialog box below. In this picture, canned text #5 (“M52”) has already been selected to
output before.
This is a sample output from the altered MPFAN.PST using the new “M52” (cantext #5) option.
The first “M52” in this NC program was generated by the selection of the cantext option as shown
above on the Canned Text dialog when programmed from the Tool Parameters page of the Contour
path parameters.
The second “M52” in this NC program was generated by the selection of the cantext option as shown
above on the Canned Text dialog when programmed from the Change at Point page accessed from the
Chain Manager.
(This cantext command was “tagged” onto a specific position along the contour toolpath.)
%
O0001
(PROGRAM NAME - CANTEXT_EXAMPLE)
N10G20
N12G0G17G40G49G80G90
( 1" FLAT ENDMILL TOOL - 1 DIA. OFF. - 1 LEN. - 1 DIA. - 1.)
N14M52
N16T1M6
N18G0G90G54X0.Y-.5A0.S1528M3
N20G43H1Z.25
N22Z.1
N24G1Z-1.F6.42
N26Y-1.5F24.45
N28X1.75
N30G3X2.Y-1.25R.25
N32G1Y1.25
N34G3X1.75Y1.5R.25
N36G1X-1.75
N38M52
N40G3X-2.Y1.25R.25
N42G1Y-1.25
N44G3X-1.75Y-1.5R.25
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 16-9
LEGACY DOC -- VERSION 9.1
N46G1X0.
N48Y-.5
N50Z-.9F6.42
N52G0Z.25
N54M5
N56G91G28Z0.
N58G28X0.Y0.A0.
N60M30
16-10 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
17 File Manipulation
The MP post executable is capable of providing several output file streams and temporary file streams.
These can be used to manipulate, order, and access data to be used for a variety of purposes. The
ability to manipulate files makes the MP language very flexible. This chapter presents the various file
streams and formula functions that can be used with them.
See Volume 2, Buffer Files and Volume 2, Subprograms for related topics.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 17-1
LEGACY DOC -- VERSION 9.1
The extensions are assigned the default character strings as shown above. This default can be
overwritten by initializing the string variables or by reassigning them on a postline. The new file name
is not used until the procedure to changing the output file is used. The NC file extension cannot be
reassigned, but when initialized in the post, it is read into Mastercam when the post is loaded. For
example:
sextnc “ABC” # Mastercam now uses “ABC” as the NC file extension
17-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
The subout variable acts as a switch to direct the NC code output to one of the following alternate files:
subout value alternate file (and default extension)
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 17-3
LEGACY DOC -- VERSION 9.1
subprg : 1 # Allow access to the sub file by initializing subprg = 1 (open and clear)
pblock # A postblock
subprg = 1 # Allowing access to the sub file as a formula statement (alternate method to subprg : 1)
subout = 1 # Re-direct the output to the sub file
The above code snippet displays the value set for erasing the contents of the .SUB alternate file when
the file exists. The following code displays the setting to append the NC output to the contents of the
file if it exists.
subprg : 2 # Allow access to the sub file by initializing subprg = 2 (open and append)
pblock # A postblock with the numeric variable
subprg = 2 # Allow access to the sub file as a formula statement (alternate method to subprg : 2)
subout = 1 # Re-direct the output to the sub file
Note: Automatic subprograms enable the alternate files, so it is not necessary to set these variables in
posts supporting the subprograms.
17-4 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
Note: To close a specified file rather than the current file, change the output file path, name, and or
extension before using these command variables in a postline.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 17-5
LEGACY DOC -- VERSION 9.1
17-6 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
This example creates a unique file name for each subprogram by appending a letter to the NC file
name. Initialize the following user-defined variables for use in the code snippet.
snameend # String for character to append
ascii_no : 65 # Ascii equivalent of character to append (ASCII value 65 = the letter ‘A’)
The postblocks and the postlines in them assign a new subprogram name (alternate file name) when
they are called. Notice that the main subprogram is automatically assigned the sub file and the sub
subprogram was assigned the auxiliary file.
psubname_m # Name the main subprogram
snameend = no2asc(ascii_no)
snamesub = snamenc + snameend
newsub
ascii_no = ascii_no + 1
The postlines first convert the ascii_no value to a character (initially to A). The character in the
resulting alternate file name is appended to the NC file name. Next, the command variable is
encountered, which closes the currently open file and reopens the stream with the new file name. The
last action is to index the numeric variable ascii_no to get the next character when either postblock is
called again.
For example:
ppost # This predefined postblock is called after all files are closed at the end of posting
sncfileame = spathnc + snamenc + sextnc # path + name + extension
result = remove(snewname) # in case this filename already exists
result = rename(sncfilename, snewname) #rename the NC file just created to the name specified in ‘snewname’
The above code snippet first builds the complete NC filename, with the path, file name, and filename
extension. Next, the file specified in the string variable snewname is removed from the disk. (This is a
precaution. If the file already exists on the disk, you cannot rename another to have that name.) Finally,
the NC file is renamed with the new file name.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 17-7
LEGACY DOC -- VERSION 9.1
In the postblock pheader, set the output to the external alternate file:
pheader # Predefined postblock at file header
extprg = 1 # Open (and clear) the .EXT file
subout = 3 # Direct post output into this file
In the postblock peof, switch the output stream to the NC output and build the external file name. Next,
close the external file and the name is assigned to the first buffer file. The buffer file (formerly the
external file) is checked for the size and then the file is read and written to the NC output. This
continues until all the records are read because of the variables used in the “while” loop. The rc1
variable used for the read counter is automatically incremented by the rbuf command each time a
record is read. (Normally you would have code in the “while” loop to manipulate the read record.).
peof #End of file postblock
n, "M30", e
s_extname = "C:\MCAM9\MILL\NC\" # Assign the path for the EXT file
s_extname = s_extname + snameext + sextext # Build up the complete file name
result = fclose(s_extname) # Close the EXT file
sbufname1 = s_extname # Now, open this file as a Buffer
subout = 0 # Set output stream to (main) NC file
size1 = rbuf(1, 0) # Get the size (# of records) in the buffer file by reading record ZERO
while rc1 <= size1, # Loop through the entire buffer file
[
stringbuf = rbuf(1, rc1) # Read a record (line) from the buffer file (rc1 auto increments)
stringbuf, e #This writes the record to the NC output file
]
See Volume 3, Formulas and Volume 2, Buffer Files for more information.
17-8 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
1. Define up to 20 prompt questions using the fq function. Each question can contain a maximum
of 80 characters, including the question number, and may also contain variables.
2. Insert a call to a specific question (that is, ask the question) in the post by inserting the question
name (q1, q2, q3, etc.) on a postline at the point where you would like the question to be asked.
When the post is run and a question is encountered, the question is output to the screen and the post
waits for a numeric or string reply. The reply will then be stored in a variable.
Note: The result numeric variable or string variable must be defined before the question is defined.
Where:
If t = 3, the above code would display on the Mastercam prompt area when post processing:
Note: The result target variable must be defined before the question.
Example
The following example shows adding a prompt question to a post. This example prompts the user to
enter a part number, and then outputs the part number at the start of the NC output file.
1. Define a string variable (spartno) to store the part number retrieved through the post question.
spartno #Define empty string
2. Add the question definition to the post processor. The fq function must begin in column 1.
fq 1 spartno Enter the part number
3. Add the question call to post. (This depends on where you wish the question to be asked.)
In this example, it is added to the pheader postblock
pheader #Header postblock
“%”, e
q1 # Question ‘Enter the part number’ is asked here…
4. Add a postline to output part number information to the NC output file.
psof #Start of file
pinit
progno
spartno = ucase (spartno) # Make it all UPPERCASE (optional)
“(Part Number: “, spartno, “)” # Output the part number that was entered at the question
prompt
18-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
For example:
# Definition using ‘scopyfile’ as the target variable
fq 2 scopyfile Enter name of file to merge # Define prompt question 2
pheader # Header postblock
q2 # Display “Enter external file name” and read contents of response file into scopyfile.
mergeext # Merge contents of file ‘scopyfile’ to NC file.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 18-3
LEGACY DOC -- VERSION 9.1
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 19-1
LEGACY DOC -- VERSION 9.1
19-2 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 19-3
LEGACY DOC -- VERSION 9.1
The rules for using the comment command can be complicated, but keep in mind that the main purpose
of the comment command is to save comments that appear before a tool change until after the tool
change block has been read.
19-4 Mastercam Version 9.1 MP Post Processor Reference Guide February 2004
LEGACY DOC -- VERSION 9.1
If the comment command is not used, the array of comments will be output when the start-of-file
postblock (psof, lsof, msof) is executed but before it is processed.
If the comment command is used, the comments will be output at the location of the comment
command when the start-of-file postblock is executed and not before.
Note: The function of the postblock pscomm0 is rarely needed. If you use the pscomm0 method, you
would not usually also use the comment command method.
February 2004 Mastercam Version 9.1 MP Post Processor Reference Guide 19-5
ADDENDA
The W and O parameters were added in X6. A complete directory of header parameters is:
V—Post update/edit version.
P—Mastercam product: 0=Mill, 1=Router, 2=Lathe, 3=Wire, 4=Mill/Turn.
E—Product used to edit post: 0=unknown, 1=UpdatePost (value 2 is reserved for
future use).
W—Version number of the product used to update the post (parameter E). So in
the example above, E1 indicates that the post was updated with UpdatePost;
W15.00 indicates UpdatePost Version 15 (for X6).
T—Date/time stamp from UpdatePost (do not enter this manually!)
M—Mastercam version required to run the post (X8 = 17).
I—Not currently used; reserved for future use.
O—Support for optional products or prototypes. This is a “license plate” value in
which each decimal place indicates support for a different product. Two values
are currently supported:
O1 indicates support for Renishaw probing.
O10 indicates support for the Pickoff/Cutoff utility.
Therefore, O11 indicates support for both products.
LEGACY DOC -- VERSION 9.1
A Glossary
This appendix defines terms used in the MP Post Processor Reference Guide. The definitions are grouped
as follows:
General terms
Post areas
Postblocks
Postline types
Postline statement types
Variables
Math
General terms
Alternate file Used to describe subprogram files or files that have been created
because the output stream has been redirected by the subout variable
(sub, aux, ext).
ASCII decimal equivalent A numerical value for a character as defined by the American
Standard Code for Information Interchange.
Buffer file function The function used to declare a buffer file in the post.
Format assignment A post function that assigns or links a format statement to a numeric
variable.
Format statement A post function that defines the format of a numeric variable.
Global formula An assignment to a variable that is automatically updated each time
the variable is encountered in a postblock.
Intermediate file A file that describes the cutter location and toolpath parameter
information.
Label The name given to a postblock or variable.
Lookup table A table of values to be referenced by the math functions; flook, frange,
and finc.
Lookup table function The function (flktbl) used to define a lookup table.
Modal, modality The property of a variable that determines how the post handles its
value.
MP language A specific code format that is acceptable to be interpreted by the MP
Post Executable.
NC output file The final output code produced by the post processor, which can be
read by a machine tool (G codes, M codes, etc.).
NCI file An ASCII text file containing the cutter location and toolpath
October 2003 Mastercam Version 9.1 MP Post Processor Reference Guide A-1
LEGACY DOC -- VERSION 9.1
parameter information.
NCI Gcode A numeric value that tells the MP post executable how to interpret the
next line of data from an NCI file.
Numeric variable An initial value assigned to a numeric variable using the colon ( : )
initialization operator.
Operation parameter file An external (.OPS) file containing toolpath parameter information.
Parameter table function A table of values to be referenced by the post function fprm.
Post customization file An ASCII text file that contains the instructions that are customized
by the post writer.
Post executable file The file responsible for reading the NCI data and interpreting the
instructions in the post customization file.
Post function A call to an internal routine in the post executable (for example, fs2).
Post text file An ASCII text file containing strings used to customize the text
messages and prompts in Mastercam.
Post writer A person who customizes a post.
Postblock Blocks of MP language code that perform a function or call another
postblock.
Postblock declaration The statement that declares a postblock. A postblock must be
declared before it can be used. Traditional postblocks are declared by
placing a label beginning with “p”, “l”, or “m” in the first column. A
bracketed postblock is declared by using the open and close brackets
([,]) as postline statements surrounding the postlines to be included in
the postblock.
Postline Individual lines of MP language code with a postblock.
Postline entries The individual elements or terms contained within a postline.
String select function A function used by the MP Language to link a numeric variable to a
list of strings. This allows the post writer to create groups of
commands and maintain modality within the group based on the value
of a numeric variable used to index through the list.
String variable initialization A string can be initialized by adding a space after the variable name
and following with a literal.
System numbered questions Questions in the post customization file read by Mastercam and used
to control aspects of Mastercam and post operation.
User prompt function A prompt that can be customized by the post writer to ask the user to
enter information that can be returned to the post in either a variable
or string.
Post areas
Definition area A section of the post that usually contains all of the variable
A-2 Mastercam Version 9.1 MP Post Processor Reference Guide October 2003
LEGACY DOC -- VERSION 9.1
Postblocks
Bracketed postblocks Bracketed code nested within a postblock using the square brackets ( [
) and ( ] ). These blocks of code are interpreted as user-defined
postblocks by the MP language.
Command postblock A pre-defined postblock called by a command word rather than a
standard postblock call.
Post-process postblock Postblocks called after processing the NCI file.
Predefined postblocks Postblocks defined internally within the MP executable.
Pre-output postblocks Postblocks called prior to the output standard output postblocks.
These postblocks provide access to NCI variables prior to the
calculation of the post calculated variables as in plin0 and pcir0.
Preparatory postblocks Postblocks called either prior to the actual NCI read or during the pre-
read scanning of the NCI as in ptooltable and pwrtt.
Pre-process postblocks Postblocks called prior the NCI read.
Standard postblocks Pre-defined postblocks typically used for output (for example, plin,
pcir, prapid).
User-defined postblocks Postblock definitions not automatically recognized by the MP
language, that is, whose definitions are not built into the MP language.
Postline types
Boolean postline A conditional test using the symbols “&” and “|” to represent AND
and OR.
Formula postline A variable assignment within a postblock.
Output postline Variables, strings and literals within a postblock that are not part of a
Boolean or formula that are to be considered for output.
October 2003 Mastercam Version 9.1 MP Post Processor Reference Guide A-3
LEGACY DOC -- VERSION 9.1
A-4 Mastercam Version 9.1 MP Post Processor Reference Guide October 2003
LEGACY DOC -- VERSION 9.1
action in a Boolean formula. The equal sign (=) is the only valid
assignment operator in this scenario.
Previous numeric variable A variable (prv_[variable name]) that stores the previous value of
another variable. All numeric variables have an associated variable
previous variable.
Selector debug string A call to a string select function prefixed with the tilde character ( ~ )
variable to control output. Will be output only if there is other output on the
current line of NC code.
Selector dependent string A call to a string select function prefixed with the accent grave
variable character (`) to control output. Output will be suppressed if it is the
only output to occur in a line of NC code.
Selector forced string A string select function call that is prefixed by a special character to
variable force non-modal output.
Selector string variable A string variable used in a list of strings linked by the post function
fstrsel.
String literal A string of characters enclosed by single or double quotes (for
example, “Text Message”).
String select function call A call to the internal routine in MP that will access a table of strings
defined by the fstrsel function and return a string based on the value of
the associated selector variable. Also referred to as the target string.
String variable A variable that holds character data rather than a numeric value.
Update numeric variable Prefixing a numeric variable with the exclamation mark ( ! ) to force
the update of its previous value (prv_); used to control modality.
User prompt function call A call to execute a user prompt as defined by the fq function.
User-defined numeric A variable used to store a floating point value not pre-defined
variable internally by the MP executable.
Variables
Boolean result The TRUE or FALSE return that controls whether or not to execute
the statements to the right of a conditional statement.
Command variable A variable used to trigger a pre-defined chain of events usually
involving a call to a pre-defined postblock.
Constant A variable that does not change in the post.
File name variable A string variable containing the name of a file.
Helper variable A variable calculated by a function to help make a logical decision,
such as the “T parameters” used with the intersection math routines.
NCI variable A variable read directly from the ASCII NCI file.
Output line variables Numeric variables typically used to format positional information
(that is, X, Y, Z, I, J, K).
October 2003 Mastercam Version 9.1 MP Post Processor Reference Guide A-5
LEGACY DOC -- VERSION 9.1
Math
2D vector math Math functions that work with two-dimensional (X and Y)
components.
3D vector math Math functions that work with three-dimensional data (X, Y and Z).
Advanced math functions Arithmetic operators for math operations other than addition,
subtraction multiplication and division (that is, log(), frac(), int(), etc.).
Assignment formula A formula that is evaluated by the MP language with the result
returned to the variable on the left side of the equation, for example, .
Basic math functions Basic arithmetic operators for addition, subtraction multiplication and
division.
Binary functions Mathematical operators that work on two numeric variables.
Boolean formula A formula that is evaluated by MP language with the result
determining a TRUE or FALSE return.
Conversion functions Functions that convert one type of data into another, for example,
no2str, which converts a number to a string.
Equation An expression that states the equivalence of mathematical or logical
expressions.
File formula Formula functions that perform actions such as renaming an output
file to that of an existing disk file. File formulas can be used in
conjunction with other MP features, such as buffer files, to perform a
high level of file manipulation.
File functions Function calls within the MP executable that work on disk files such
as fclose and rename.
Formula Math operators and math formulas as applied to the two MP language
statement types:
the formula statement
the conditional branching statement
Both of these statement types use the same syntax in the argument
portion of the statement. The formula statement makes an assignment
to a variable that is the target of the formula. The conditional
A-6 Mastercam Version 9.1 MP Post Processor Reference Guide October 2003
LEGACY DOC -- VERSION 9.1
October 2003 Mastercam Version 9.1 MP Post Processor Reference Guide A-7
LEGACY DOC -- VERSION 9.1
Precedence functions Open and close parentheses ( ) that control the precedence of
operation, that is, the order in which operations are performed.
Result assignment The variable on the left side of an equation.
Simple assignment The act of assigning a value to a variable without the need for a
complex formula or other math operator besides the equal sign ( = ).
Special MP functions Unique mechanisms in the MP language that support the string select
feature, lookup table features, buffer files and user prompt feature.
String formula A formula that alters a character string.
String functions Functions that operate on character strings rather than numeric data.
Trigonometric functions Standard trigonometric functions for sine, cosine and tangent of an
angle. The atan2 function returns the solution of the arc tangent within
the 360 degree range.
Unary functions Mathematical operators that work on a single numeric variable.
A-8 Mastercam Version 9.1 MP Post Processor Reference Guide October 2003