Overview
In the most general terms, Code Generator (CG) editing is a cycle of Process - Code the model, inspect the produced G-Code file, edit either or both the CGT (Code Generator Template) and SMF (SmartCAM Machine Define) files, Process - Code again and re-inspect the code. Repeat these steps until the desired code is produced. These exercises assume you know at least the basics of the CG system and understand the necessary target nc code for your machine.
Use the appropriate PM5/JOF and SMF/CGT file pairs below to try the exercises that follow.
Milling applications | mill/mdata/gsmill.pm5 jof | common/mill/machine/lsmill.cgt smf |
---|---|---|
Turning applications | turn/tdata/gsturn.pm5 jof | common/turn/machine/lsturn.cgt smf |
Advanced Fabrication | fab/afdata/gslaser.pm5 jof | common/fab/machine/lscont.cgt smf |
Advanced Wire EDM | wire/awdata/gswire2.pm5 jof | common/wire/machine/lswire2x.cgt smf |
![]() |
Tip
While editing your CG files you do not need to close the Code control panel in the application. SmartCAM will incorporate any changes to the CGT or SMF files without closing and re-opening the Code panel. While editing either file (or both) it is much more productive to simply leave the Code panel open. |
Editing the Machine File
![]() |
Tip
Use the View - Select Categories to narrow the range of questions that are in the window to aid in quickly finding relevant items. |
- File - Open your exercise model (see table above for appropriate model).
- Process - Code, select Choose and select your exercise SMF and CGT files.
- Enter a Code File location and name.
- Create Code the code process (leave the Code panel open).
- Open the Code file with a text editor.
- Inspect the code and note the position format of X, Y and Z moves.
Start Machine Define from the SmartCAM Program Group and open your exercise SMF file. The position format is controlled with question number 22. Change this entry to a different format. (See the CG Numeric Formats section for more about this). File - Save the changed SMF file.
Since the Code panel is already open, simply press Create Code and overwrite the previous code file, then inspect the code file again. The change is reflected in all of the X, Y and Z moves of the new code file.
Use this same approach for editing any of the SMF file questions.
Editing the CGT File
Searching for the source of affected code
- File - Open your exercise model (see table above for appropriate model).
- Process - Code and select Choose and select your exercise SMF and CGT files.
- Enter a Code File location and name.
- Create Code the code process (leave the Code panel open).
- Open the Code file with a text editor.
- Inspect the code and note the position format of X, Y and Z moves.
Using a text editor, such as Windows Notepad, open your CGT file. Note the different sections that begin with the @ sign. For example:
@START
G00 G40 G80 G90
T#TOOL
#SPNDL S#SPEED
X#XPOS Y#YPOS
Z#ZPOS
@
This is the @START section and is the first section called that outputs code. This section will output a preparatory line (G00 G40 G80 G90), the tool call out, turn on the spindle and set the speed, position in X and Y, and finally position the Z move. Variables begin with the pound (#) sign. System variables automatically get their values from the model or JOS (See the CGT Word Reference section for more about this).
- Edit a line that outputs an X and Y move and add the #MOV word at the beginning. #MOV carries the current motion value (G00, G01, G02, etc.). For example, "#MOV <X#XPOS><Y#YPOS>"
- Code the file again and inspect the code.
Narrowing the search
It can sometimes be difficult to determine exactly where the #MOV word is output. X#XPOS Y#YPOS is a pair that can be output from many sections, and several places in that section. To aid in discovering which section your code is output from, turn on the CGT Diagnostics - Sections option on the Code dialog box.
Code the file again and inspect the code.
***** @START *****
G00 G40 G80 G90
T2
M03 S382
G00 X1.208 Y2.872
Z0.1
***** @STPROF *****
This now narrows the search to a particular section. But perhaps your section has many instances of X#XPOS Y#YPOS output and you need to narrow the search even more.
Flagging the exact location of a search
- Checking the Line Ref box in the code dialog box will precede each line of code with the CGT line number it came from.
- To focus only on a specific line from the CGT, edit the CGT line of interest and add a literal set of characters to the beginning. Choose a set of characters that are easy to spot among the rest of the code. For example "+++ #MOV <X#XPOS><Y#YPOS>".
- Code the file again and inspect the code.
***** @START *****
G00 G40 G80 G90
T2
M03 S382
+++ G00 X1.208 Y2.872
Z0.1
***** @STPROF *****
Now it is clear exactly which line(s) is affected by your CGT change.
Reporting Errors
SmartCAM provides an option on the Code dialog box to check for and to report errors to the code file. Errors are detected for a variety of problems including misspelled CGT words, missing CGT sections, and malformed statements and logic, to name a few.
Edit the same section that you added the flag to and intentionally insert a flawed phrase. In the following example, note that #TOOL is misspelled #TOL.
@START
G00 G40 G80 G90
T#TOL
#SPNDL S#SPEED
X#XPOS Y#YPOS
Z#ZPOS
@
Turn off the Checking - Sections option on the Code dialog box, since we no longer need the section names output.
Turn on the Checking - Errors option, and code the file.
Open the code file and note the error message displayed at the start of the code file. The information reported for errors includes the following: A sequential error reference number, the row and column number in the CGT file where the error was detected, the system error number and the corresponding message description text.
G00 G40 G80 G90
Err:1 Lin:24 Chr:4 4008: Unrecognized CGT variable will be output as literal
T#TOL
M03 S1035