You are on page 1of 4

Volume 1 Chapter 19 Posting Comments into the NC File

19 Posting Comments into the NC File


Comments can be inserted into the NC toolpath file using Mastercam. They can be inserted using the
manual entry toolpath type or the change at point option accessed from the Chain Manager, and from
the comment box on the tool parameters page. The comments will appear in the NCI file with the
following Gcodes:
1005 - Write comment at current position with sequence number
1006 - Write comment at current position without sequence number
1007 - Write comment at the end of the next linear or arc move
When a comment is entered in the Comment box on the Tool Parameters dialog box of a toolpath
operation, it is written to the NCI file as a Gcode 1008.

Using pcomment to format comments


When the post executable processes the NCI file, comments are read into the predefined string variable
scomm. The post executable then calls the predefined postblock pcomment, where the comment is
formatted.
! If the comment is a Gcode 1005, 1006 or 1008, the comment is output immediately.
! If the comment is Gcode 1007, it is saved and output at the end of the next NC line.

You can set the pcomment postblock to output comments with different formats by checking the Gcode
numbers. In the NCI file:
! Gcode 1005 outputs the comment before the current NC block.
! Gcode 1006 outputs the comment after the current NC block.
! Gcode 1007 outputs the comment with the same line as the next arc or linear move.
! Gcode 1008 is a comment from the Comment box on the current toolpath operation. It is handled
internally like a Gcode 1005 comment.

Manual entry postblock example


A standard manual entry setup may look like the following:
pcomment #Com ment from manual entry (must call pcomment2)
pcomment2 #Needed if doing ‘if’ logic testing!
pcomment2 #Post to output Comment from manual entry
scomm = ucase (scomm)
if gcode = 1005, "(", scomm, ")", e # Before
if gcode = 1006, "(", scomm, ")", e # After
if gcode = 1007, "(", scomm, ")" # With
if gcode = 1008, "(", scomm, ")", e # Operation comment

Using scomm to capture comments


Comments in the NCI file are captured in the string variable scomm. scomm is output from the
postblock pcomment and is then cleared. When using scomm variable in a branch (logic) statement, the
June 2002 Mastercam Version 9 MP Post Processor Reference Guide 19-1
Chapter 19 Posting Comments into the NC File Volume 1

pcomment postblock must first call a user-defined postblock where the Boolean is performed to avoid
clearing the contents of scomm.

Using the commlng variable


The numeric variable commlng is automatically set to the length of the scomm text string. This is the
number of characters in the scomm comment string.

Using the commvar variable


The numeric variable commvar is a special comment case. If the scomm comment string is composed
entirely of numbers (0-9) and optionally the symbols “.”, “ +”, or “-“, it will be converted from the text
string into a numeric value and placed into the commvar variable.
Note: If commvar is used, the scomm string will be cleared.

Comments and the tool change block


One of the main uses of comments is to give the machine operator instructions, and one of the primary
times instructions are needed is at a tool change.
To get comments into the NCI file with a tool change block:
1. Choose manual entry when making a tool path.
2. Select the first point of the toolpath after the tool change.
3. Enter the comment.
4. Choose before to output the comment immediately before the tool change.
Note: If you choose with, the comment will be output to the NCI file with a 1007 Gcode, but not until
the first move of the toolpath (after the tool change). If you choose after, the comment will be output
after the first move in the toolpath (also after the tool change).

Using the comment command with tool changes


By default, comments appear immediately before the tool change. However, because you might wish
to process the tool change block before outputting the comments, you must save the comments until
after the tool change block has been read. This can be done with the special command comment.
If the comment command appears in any postblock when a comment with a Gcode 1005, 1006 or 1008
is read, it is automatically saved in an array. When the postline with the comment command is executed,
the array of saved comment strings is output, one comment string at a time. Each string from the saved
list is copied into the string variable scomm, and a call is made to the postblock pcomment. In this way,
each comment can be formatted before it is output to the NC file.
The comment command is usually used in the psof, ptlchg, ptlchg0, peof lsof, ltlchg, ltlchg0, and leof
postblocks to output the comments at a particular location in the NC program. To output comments at a
specific location, use the command comment. Never call the postblock pcomment directly from other
postblocks.

19-2 Mastercam Version 9 MP Post Processor Reference Guide June 2002


Volume 1 Chapter 19 Posting Comments into the NC File

Example using the comment command


The following is an example of correct usage of the comment command.
ptlchg # Tool Change postblock
n, pcooloff # Coolant off at end to tool
n, "G28 Z0" # End of previous operation
comment # Output the comment(s) here
n, t, "M6" # Tool change / start of new operation

The preceding code would generate NC output similar to:


M09
G28 Z0
(THIS IS THE COMMENT FOR TOOL#4)
T4M6

The rules for using the comment command are complicated, but keep in mind that the main purpose of
the command is to save comments that appear before a tool change until after the tool change block has
been read.

How the post processes comments


When a comment is found, it is saved in an array until an NCI line is read that is not a comment. If the
next line read is anything but the start of a tool change block or the NCI line for the end of file, the
array comments will be output before that NCI line is processed. If the next line read is the start of a
tool change block or the NCI line for the end of file, the comments will not be output until the
command comment is found in one of the following postblocks:
! psof
! ptlchg
! ptlchg0
! peof
! lsof
! ltlchg
! ltlchg0
! leof
! msof
! mtlchg
! mtlchg0
! meof
If the comment command does not appear in one of these postblocks, the array of comments will not be
output. In this case, the array of comments can be output by the comment command in a postblock
other than one of the postblocks mentioned above. For example, to delay outputting the comments until
after the first rapid move after the tool change, the command comment would appear in the postblock
prapid.
The one exception to the rules above is when comments appear before the start-of-file block, with
Gcode 1005, 1006 or 1008. These comments are always saved in an array whether the command
comment is used or not.

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 19-3


Chapter 19 Posting Comments into the NC File Volume 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.

Using the pscomm0 postblock


An alternative method of handling comments is to use the pre-defined postblock pscomm0 and the pre-
defined variable scomm0. When the post customization file (.PST) reads a comment from the NCI file,
it copies the comment string into the pre-defined variable scomm0 and calls the postblock pscomm0.
This allows immediate access to any start-of-file comments. After executing postblock pscomm0, the
post executable does not automatically reset the scomm0 variable to an empty string. The post writer
must do this in the post customization file with a postline at the end of the pscomm0 postblock:
scomm0 = sblank # sblank must be initialized as blank string

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.

19-4 Mastercam Version 9 MP Post Processor Reference Guide June 2002

You might also like