The 3 issues (in the format template) that control Work offsets
7. SPECIAL FEATURES
7.5 If / Else Logic
5.3.4 File
In short, the 5 types of File commands give you control over both multiple output streams (or files) and multiple output styles that can either be routed into individual (or multiple) output files, or reorganized (in any order) into a single file. (If you didn't understand that, it's OK - it can be complicated. We'll explain below...)
What the File commands can do for you
The File commands lets you route any or all selected lines of output data (generated by the sequence lines) into one or more separate output files simultaneously. Then, you can either leave the output distributed among the individual files. or, if you like, you can merge some or all of the files back together into a single (or even more than one) final output file.
This not only gives you a high degree of control over how the final output file(s) are handled, but also over how the CL data gets processed; you can process the same section of CL data in several different ways, and then have the resulting output appear in multiple (different) locations within the same final program file (or in separate files).
For example, it enables you to do these types of things (in addition to many more)...
- Post the same CL data in several ways, then either
- 'channel' the output of the different kinds of processing into different files, or - 'join' the separate files into a single finished NC program.
Example: to create a 'tool list' at the top of your programs.
- 'Break' the code into 2 or more files.
(e.g. due to machine 'line number' limitations.) - 'Sort' the post's output into several separate files
Example: every operation (or the motion for each tool) can be output to its own file.
- Post programs for multiple machines simultaneously.
- Create multiple output files for machines that require more than one file to perform a machining job.
You can temporarily use up to 100 individual output files simultaneously in addition to the 'main' file. (You can actually create more than 100 files, but you can read or write only 100 of them simultaneously.)
The main file is the 'usual' final program file that the post creates when you don't use any File commands (usually named the same as the incoming CL file, but with the .NCC extension).
How to use the File commands
Per the usage examples in the table below, the word File is always followed by 2 parameters:
- the 1st parameter is one of the six 'options' (Alias, Empty, Off, On, Insert or Edit), and then - a file number.
The file number can be...
- a number from 1 to 100 (inclusive) or
- a [variable] or an equation that evaluates to an integer from 1 to 100 (inclusive), or - it can be the word 'Main'. (This lets you control the 'main' output file.)
At this point, since you can only specify file by its number (not its 'name'), you may be wondering how to create a file with a specific name... that's what the File Alias option is for. Read about it (and all of the other options) in the table below.
Notes re the table below:
1. The File command options are listed in the order that they are most likely to be used.
2. Remember - in the examples here, the 1 can instead be a [variable] or equation or the word Main .
Option Usage examples Purpose
Alias * File Alias 1 'This file.txt' ...or...
File Alias [Val19] 'This.txt' ...or...
File Alias [Tool]+5 {CLName} '.cmd' ...or...?
Use this only if you want to indicate a specific file name that you want to use as an 'alias' of the file number indicated. That is all that this command does. (It does not 'empty' the file or turn it on or off.)
From then on, simply use the file number (in this case, 1 ) for any Empty, On, Off, Edit or Insert operations; the post automatically keeps track of the actual file name. (This prevents you from having to have the file name text in multiple locations in your template [which could lead to lots of confusion in the case of file names that are based on variables!].) Note: If you just want to use a 'temporary' file (and you don't care what its name is), then do NOT use the File Alias command.
Because the Alias option does nothing but substitute a name for the file number, you will almost always follow every File Alias _ command with a matching...
- File Empty _ command (to create a new, empty file) or a
- File Insert _ command (to read the contents of a certain file into the other files that are 'on' [see 'File On' below]).
---The first example on the left will cause any subsequent operations on file 1 to actually operate on the file called This file.txt instead of the ..\Temp\1 file.
As you can see from the other examples on the left, the file name can be a 'hard-coded file name' or a {text variable} or any combination of 'hard-coded text', {text variables} and even [Numeric variables].
Numeric variables (such as [Tool] or [RotAngle]) will be formatted to output the 'simplest' text that represents the number – no leading or trailing zeroes, no trailing decimal points – regardless of any number formatting used elsewhere in the template. ( Examples:
0 or 1 or 180 or .5 )
Note: If you don't specify a folder, the file will be created in the same folder as your main output file.
Note: Don't use the Alias option more than once per file number (because this will 'overwrite' the file) – unless you first use the Insert option to 'copy' its contents into another file(s).
Empty * File Empty 1 ...or...
File Empty [Tool] ...or...
File Alias [Val3]+1 ...or...?
Empty creates a file that is initially empty; use Empty when you just need to use a 'temporary' file and you don't care what its name is. For example, when you just need to store some output that will be 'inserted' back into the main (or other) file later.
Note: Since the Empty option only uses a number (it doesn't let you specify a file name), it will create a file called (in this case) 1 (with no extension - in the ..\Temp folder underneath the folder that PostHaste.exe is in).
NOTE: You MUST use Empty when you want to start with a 'fresh' (empty) file. If you do NOT use Empty (i.e. if File ON 1 is executed before File Empty 1), then you will be appending information to the (existing) .. \Temp\1 file!
Option Usage examples Purpose
Use the ON option when you want to start (or resume) outputting data to a specific file number. Any sequence lines executed after a File On _ command is executed will be output to the file number specified (as well as any other files that are also in the 'on' state) until the post executes a corresponding File Off _ command. (The file will also be turned off if a 'File On... ONLY' command is processed for any other file number [see “the ONLY option”
below].
Note: The 'Main' file is ON by default when the post starts processing, so if you don't want it on to start with, then you must turn if off with a File Off Main command in your StartCode sequence. (Or, you can use a 'File On... ONLY' command to turn on 'only' some other file – thus turning off the main file.)
The “ONLY” option:
You should make it a habit to use the ONLY option whenever applicable in your FILE ON commands. Adding 'ONLY' to the end of the line turns off all other files, leaving 'only' the specified file in the 'on' state. (This eliminates the need for most FILE OFF commands, which makes your template much cleaner looking and easier to understand.) In other words, use the ONLY option when you only want 1 file on at a time.
(Obviously, if you need more that one file on at a time, you would NOT use ONLY.) Off File Off 1 ...or...
File Off Main ...or...
File Off [Val12]+[Sub] ...
This is the opposite of the ON option: use the OFF option when you want to stop including the upcoming code in a certain file (or files). This condition also persists until a File ON _ command is processed for the same file number.
Insert File Insert 1 ...or...
File Insert [Val4]
Use this to copy the contents of any file into any other file(s) that are ON. See the EndCode sequence in the 'tool list' example below (section 5.3.4.1) for a good example of how this is done.
NOTE: If you don't turn OFF a file before you 'insert' it into another, the post will automatically turn it off first – to prevent it from attempting to 'insert into itself'. (After the INSERT operation, the file will be left in the OFF condition.)
Edit File Edit 1 ...or...
File Edit [Tool] This option causes the post to 'execute' the file – which in most cases should result in it being opened by an editor (such as WordPad, NotePad or Microsoft Word, etc.) Depending on how you have your system's Windows' File associations set up, this could cause a file to be opened in any application you choose ( - a communications package, for instance, to send a NC program to one of your machines). To set up Windows' File associations, use Windows Explorer and go to the Folder Options choice in the View menu.
(in Windows 2000 and XP, the Folder Options choice is in the Tools menu.)
---You may have multiple File Edit _ commands in your post, and you can even 'edit' the same file number more than once – but only if you use File Alias commands executed somewhere between the File Edit commands so that the file number is 'reassigned' to different file names - so that you are not trying to 'edit' the same physical file more than once.
NOTES:
1. This command will NOT execute the file unless PostHaste's AutoOpen feature is enabled. (See the 'AutoOpen?' switch in the PostHaste.CFG file [Appendix A of the Getting Started manual].)
2. Since the AutoOpen feature automatically opens the 'main' file, you will never need to use the command File Edit Main
* Important notes re the Alias and Empty commands...
1. The Alias and Empty commands do NOT turn a file on.
- Alias does nothing more than associate a file name with a file number, and - Empty simply empties a file and get it ready for use later in the process.
(You must specifically give a File On _ command to start outputting to any file.)
2. The Empty and Alias commands cannot be used with 'Main' file. The post automatically creates an empty 'main' (final program) file (just as it always does when you are not using File commands).
5.3.4.1 'File' usage example: Creating a 'tool list' at the top of the program.
This example template excerpt in the chart below uses 'temporary' files to process 2 parts of the output, then merges them (in EndCode) back into the main output file - to output a final file that starts with a 'tool list' (consisting of the 'operation comments' that are in the CL data) like this:
%
Note: For brevity, the example below doesn't show the entire template - only the applicable sequences.
... Comments op comments, then
File off 1 turn off the 'tool list' file. Comments op comments, then
File off 1 turn off the 'tool list' file.
File On Main Only << Finally, turn on the main (_.NCC) file, (Note that this turns OFF the 'bulk' file [#2]).
File Insert 1 then append the Tool list, and
Note: The example above is an excerpt from the Tool List.pm3 file that is included in the standard post format library.
5.3.5 NoEol and EOL
Using NoEOL allows you to build a single line of output code (in a 'piece by piece' fashion) by 'stringing together' two or more sequence lines from your template. (In other words, when you want to create a single line of output code from MORE than a single sequence line.)
The NoEOL (literally, “NO End Of Line”) command suppresses the 'end of line' characters that PostHaste automatically outputs at the end of each code sequence line.
(Note - These are unique commands, as they are the only ones that can be used in a sequence on the same line as other output codes. All of the other commands [such as Comments, File, IF and Set] are always on lines by themselves and don't generate any output code.)
Here's an example of how you might use NoEol. In this case - a combination punch press with a laser head - the user wanted a G61 to appear on the first cutting move, but only if the machine was in 'laser' mode (not punching). Here's how we did it: (Only the applicable sections of the template are shown, also
demonstrating the Convert and UponRec commands.)
Convert "APPLY / LASER" to "APPLY / 1" For Val2 laser flag.
Convert "APPLY / PUNCH" to "APPLY / 0" Ignore: Apply / Punch Uponrec Apply [Val2] Val2 = 'laser on' flag.
end
ToolChange G0 H[H] Y[V]
if [Val2] = 1 (Laser) M64 '(LASER ON)' M66
G4 p100 M68
G61 NoEOL << NoEOL 'delays' the output of G61 to put it on the NEXT line! (1st cutting laser move).
endif
End (ToolChange)
5.3.5.1 EOL
Use this command (somewhere after NoEol command[s] are used) if you need to show where you want a line to be ended. You will NEVER need to use this command unless the last word that you want to be output on the line is accompanied by a NoEol command. (In other words, EOL cannot be used to output blank lines. Use the exclamation point for outputting blank lines - see section 0 for details on that.)
Below is a good example of how the EOL command is used (along with some NoEol commands, of
course). In this example, we want to prevent PostHaste from 'repeating' the first XY location in a drill cycle (where the machine requires that the XY location is on a separate line from the rest of the drilling code).
Since PostHaste treats all codes for the first hole of a drilling cycle as non-modal, the first XY position in the cycle is redundant (because PostHaste also always generates a rapid move to the XY position above the first hole location before a drill cycle is started). We use the following lines inside the Drill sequence to suppress the (redundant) XY location of the first hole :
Set [Val1] to 0 Val1 is a flag for 'X or Y has been output'.
if [H] <> [LastH] If X has changed, then X[H] NoEol Output it (with no EOL), and Set [Val1] to 1 set the 'has been output' flag.
endif
if [V] <> [LastV] Same for Y...
Y[V] NoEol Set [Val1] to 1 endif
if [Val1] = 1 If X or Y has been output, then Eol output the EOL to end the line.
Endif
Note: If we had left out the EOL section above, then the X and/or Y would be placed on the next line of code (because of the NoEOL commands on the X and Y lines), instead of being output on their own line.
5.3.6 Set
Set is a command that can be used inside a sequence (only) to set (or 'assign') the value of any variable.
There are any number of reasons you may want to do this - it's limited only by your imagination. One of the most common uses is to use it in conjunction with “If/Then/Else” logic to control the output of certain codes. (See section 7.5 for information on the use of “If/Then/Else” logic.)
Example:
In this first example, we have a machine that uses a G code to dictate any one of 5 spindle speed ranges (from G65 to G69). We will SET [Range] to the proper spindle range. We show it here in the
1stToolChange sequence, but you'd also put it in the ToolChange and RapidCode sequences as well.
(We've added blank lines to the examples for clarity - they don't affect operation of the post...)
1stToolChange G0 G90 G80 G40 G17 T[Tool] M6
SET [Range] to 65 This line sets the "under 1000 RPM" spindle range.
if [Speed] > 1000 This IF structure sets the range if the SET [Range] to 66 speed exceeds the 1st gear range.
endif
if [Speed] > 2000 ...and we do it again, one IF/SET structure for SET [Range] to 67 each range you want.
endif
if [Speed] > 3000 SET [Range] to 68 endif
if [Speed] > 4000 SET [Range] to 69 endif
G[Range] M[Direct] S[Speed] This line actually outputs the code.
G0 G[Work] X[H] Y[V]
G43 Z[D] H[Lcomp]
M[Cool]
End (end of 1stToolChange)
Another Example:
If your machine requires the spindle to be stopped before gear changes, then we will need to set up the RapidCode sequence to stop the spindle if a gear change is needed. (Remember, RapidCode is used when you want to override the post's default way of handling rapid moves.) To detect if a gear change is needed, we'll use the SET feature to "memorize" the previous range, then use an IF statement to compare the
previous range to the new range. If it's different, then we'll stop the spindle before outputting the new speed range code.
First of all, add the Set line in the following example AS THE LAST LINE (just before the "end") in the 1stToolChange and ToolChange sequences...
1stToolChange (do the same in your ToolChange sequence.) . . .
M[Cool]
Set [Val2] to [Range] (This 'memorizes' the spindle range in [Val2]. ) End (end of 1stToolChange)
...this will cause Val2 to "memorize" the spindle range that was just output. (You'll also notice that this will become the last line of the RapidCode sequence shown below...)
Now, Add IF structures to the RapidCode sequence to make it look like this:
RapidCode
... ( We didn't bother showing all the same range codes that ... were already shown in the above example, but in a real ... format they should be here. )
if [Speed] > 4000 (These 3 lines are the same as in the above SET [Val1] to 69 example - they set the high range...) endif
v--- THESE LINES ARE ADDED TO CHECK FOR SPINDLE STOP ---V if [Range] <> [Val2] If range has changed, then
M5 M5 to stop the spindle before...
endif
G[Val1] M[Direct] S[Speed] ...the gear change.
G0 X[H] Y[V] Z[D] The rapid movement is output here.
Set [Val2] to [Range] Finally, memorize the gear range again
for the next time around.
END (end of RapidCode)
5.3.6.1 Limitations of SET commands
You may have up to 200 Set commands per machine format. (That's a LOT – if you think you need more, then there's probably a much better way to create the output that you need, so take a minute to re-think your strategy.) Here are the rules regarding Set commands (as you've already seen in the examples above):
- the first parameter must be any [variable]; the second can be a variable, a numeral, or an equation.
- the two parameters are separated by the word "to" (upper, lower or 'mixed' case doesn't matter) - Set commands are only allowed inside of sequences.
6. Work Fixture Offsets (G54, etc.):
how they [Work]
Because they drastically affect overall positioning of your machine as well as individual movements, work offsets (including usage of the [Work] variable) are taken very seriously by the post. Having wrong or missing work offsets could easily cause you to crash your machine! For this reason, when it comes to outputting work offsets, PostHaste...
• NEVER ignores them,
• NEVER "makes them up",
• ALWAYS outputs ALL work offset changes, and
• NEVER leaves room for ambiguity.
The only way PostHaste WON'T output them is if you set up your format template AND your tool path data to specifically NOT use them. (The details of how to do this are also discussed below.)
The 3 issues (in the format template) that control Work offsets
There are 3 things in the template that affect how and when the work offsets are output. (They are listed and described briefly here, and discussed in more detail below.)
• Factors 1 and 2 are usually found in the "miscellaneous parameters" area of the template: you can have lines that start with WORK or WORKDEFAULT as in the examples here:
Work G - This tells the post what letter to use for work offsets.
WorkDefault 54 - If the post asks you for an offset, this will be the default value shown..
• The third factor is the use of the [Work] variable in the code sequences. Using the [Work] variable ANYWHERE may also affect the way work offsets changes are output EVERYWHERE ELSE in your program. Read about the [Work] variable below.
Work offsets "in a nutshell"
If you want work offsets to appear in your programs, then all you really need is to either...
• Use the [Work] variable in your 1stToolChange and ToolChange sequences. This will allow you to control EXACTLY where the first "G54" appears. (Subsequent offset changes will
automatically be output wherever needed with whatever letter you placed before [Work] -usually G.)
OR...
• Put a "Work G" (or equivalent) line in your format. (We recommend putting it in 'section 2' of your template - among the other commands & switches.) This will tell the post to just put them wherever they're really needed (...and to prompt you for offset numbers if they aren't in the CL data).
(Also, we recommend that if you want the "default" work offset to be something other than 54, then add a WorkDefault line to your format.)
That's it.
But, what if you DON'T want work offsets in your NC programs?
To completely eliminate work offsets from appearing in the code, you must do 2 things:
1. Eliminate all reference to work offsets in your template file - that is, make sure that you are NOT using the Work or WorkDefault command, and make sure that you are not using the [Work]
variable in any of your sequences.
variable in any of your sequences.