Code Generator CGT Sections

Sections within a CGT file are called upon depending on the element being processed or the situation. For example the @LINE section is called when processing a line element to output a linear cutting move. The @TOOLCHG section is called when the next element to be processed is of a different tool. There are three types of sections, the system section, the user defined section and the local table section.

System Sections

System sections are predefined sections that are called on in a predetermined sequence. The uses of the system sections are fairly obvious. There are less obvious sections such as @DECLARE or @CYCLCHG. While all of the sections are too numerous to describe here, refer to the System-Defined CGT @ Section Reference for a complete listing. At the most basic level, the Code Generator first calls the @DECLARE section and sets any used variable types. The next section called, if defined, is the @CYCLCHG section, which can be used for debugging or any special needs between section calls. The @CYCLCHG section is called prior to every system section, if it is defined. The next section is the @START section where you can initiate variables and output any preparatory commands. The model is processed using the variety of sections that may be required and ends with the @END section where you output any post code and the program end command.

User Defined Output Sections

A user defined output section is a section you create to use for any special requirements that SmartCAM does not automatically support. Their processing must be invoked either with a #CALL() command or a #GOTO() command or with a special user command element within the model. They have the same form as a system defined section, but it is suggested that user defined section names are in lower or mixed case, beginning with a lower case letter, for ease of reading and debugging.

To call a user section with a user command, with the step you intend to use with the section, at the insert position you wish the section called, simply create a user command with the text @mySection. This can be further expanded by passing values and variables to the section with the text @mySection(#myVar=value, #myVar2=value2). The following example uses this user command: @inspect(#S1=B3) to output code that moves the part away from the tool, displays a message on the control screen instructing the operator to measure the hole depth of item 'B3' and output a program stop.

@inspect
G00 Z#ZHOME
X#XHOME Y#YHOME
(Check depth of hole #S1)
M00
@

The output would be similar to:

G00 Z4.000
X10.000 Y10.000
(Check depth of hole B3)
M00

User Defined CALC $Sections

A user defined calculation section is a section you create to use for any special logic or calculations that you want to organize. Processing can be invoked either with a



The following example shows its use in an expression contained in a #EVAL() command. The statement #EVAL( #myQuadLen = $arcCircumference / 4) sets #myQuadLen to the length of one quadrant for the current arc by invoking @$arcCircumference which returns the circumference for the current arc, and dividing that by 4.


@DECLARE
#DEC #myQuadLen
@

@ARC
#EVAL(#myQuadLen = $arcCircumference / 4)
{ Arc Quad Len = #myQuadLen }
< #MOV>< X#XPOS>< Y#YPOS>< I#XCTR>< J#YCTR>< F#FEED>
@

@$arcCircumference
#RETNUM(2 * PI() * #ARAD)
@

Alternatively both #myQuadLen and #arcCircumference can be declared as matching #CALCDECs and the calculation can be handled through them.


@DECLARE
#CALCDEC #arcCircumference, #myQuadLen
@

@ARC
{ Arc Quad Len = #myQuadLen }
< #MOV>< X#XPOS>< Y#YPOS>< I#XCTR>< J#YCTR>< F#FEED>
@

@$myQuadLen
#RETNUM(  #arcCircumference / 4 )
@

@$arcCircumference
#RETNUM(2 * PI() * #ARAD)
@

Table Sections

A table is a list of values that the #TABLE() function can choose from. #TABLE has two components within the parenthesis (). First is the table section to call and second is which item from the list to return. Another way to use a table is to declare a variable as a table variable (#TBL) and have a table section with the same name. Each time the table variable is to be output, it first retrieves its data from the table of the same name.

For the first example:

@START
#TABLE(myTable, 2)
@

@myTable
0,Off
1,Low
2,Med
3,High
@

This example would output Med at the top of the G-Code file. When the #TABLE function is encountered it will find the first parameter section name (@myTable) and parameter number two of that section, then output that to the code file. Note that it does not capture the first number and comma, these are ignored and are provided for readability. Only the data to the right of the comma is considered.

For the second example:

@DECLARE
#TBL#myTable
@

@START
#EVAL(#myTable=3)
#myTable
@

@myTable
0,Off
1,Low
2,Med
3,High
@

This example would output High at the top of the G-Code file. The @DECLARE sets #myTable as a #TBL, which lets the Code Generator know that it is a table variable. The @START section assigns the integer value of 3 to #myTable. The following line asks to output #myTable to the code file, but because the Code Generator knows it is a table variable it will search the CGT file for a section of the same name (@myTable) and use the integer value to return item 3 from the section. If no table exists by that name, nothing is output.

Syntax

A section begins with the @ sign followed by the section name and ends with the next @ sign. It is good practice to close a section with an @ sign on a line by itself.

@DECLARE
#STR #message
#INT #part_count
@START
G92X100Y100
@LINE

This example works fine with the Code Generator because a section closes with the next @ sign. In this case the closing @ sign for the @DECLARE section is the @ sign for the opening of the @START section. This practice is discouraged.

@DECLARE
#STR #message
#INT #part_count
@

@START
G92X100Y100
@

This example uses the @ sign on a line by itself to close each section. This not only has the potential to speed up processing, but also makes the CGT code easier to read and debug.