Using the Trace Facility
Trace is a useful debugging tool. We want to introduce you to
Trace at this point because you can see how boolean expressions and other expressions are evaluated.
Here is the macro we are going to trace:
DEFINE Parenth
LET P1 (0,0) {parentheses not necessary}
LET P2 (10,0) {parentheses not necessary}
LET X (1) {parentheses not necessary}
WHILE ( X < 5 ) {parentheses necessary}
LET P1 (P1 + 0,10) {parentheses necessary}
LET P2 (P2 + 0,10) {parentheses necessary}
LINE TWO_PTS P1 P2 END
LET X ( X + 1) {parentheses necessary}
END_WHILE
END_DEFINE
The macro will draw four lines. When X equals 1, a line is drawn from 0,0 to 10,0. When X equals 2, a line is drawn from 0,10 to 10,10, and so on.
We have noted where parentheses are necessary and where they are not.
This macro demonstrates an important principle. Look at the syntax diagram for LINE TWO_PTS in the Creo Elements/Direct Drafting Programing Reference Guide. In a macro, the recursive loop shown can be ended only by an END statement. This is a general rule: when a syntax diagram ends with a recursive loop, use an END statement to get out of the loop.
Look at the diagram for LINETYPE. This diagram does not end with a recursive loop. No END statement is required in a macro.
Now let's use
Trace on our macro, and store the results in a file called
trace.
Before using
Trace, change the second line in
parenth from this:
LET P1 (0,0)
to this:
LET P1 0,0
Type the following in the user input line and press ENTER after each command:
input 'parenth'
trace
parenth
When the macro ends, disable
Trace:
1. Click
Miscellaneous and then, in the
System group, click
Trace.
2. Click
Off.

in the status bar indicates that
Trace is inactive.
| If your trace file is unexpectedly empty or incomplete, you may have forgotten to disable Trace. |
If you want to append the results of a
Trace operation to an existing file:
1. Click
Miscellaneous and then, in the
System group, click
Trace.
2. Click
On.
3. Click
Append.

in the status bar indicates that
Trace is active.
If you want a clean file for each run:
1. Click
Miscellaneous and then, in the
System group, click
Trace.
2. Click
On.
3. Click
New.

in the status bar indicates that
Trace is active.
To view the results of the
Trace operation:
1. Click
Miscellaneous and then, in the
System group, click
Trace.
2. Click
Edit.
The results of the
Trace operation are displayed in the standard text editor.
Here is the trace file for parenth:
Parenth
LET P1 0,0
LET P2 ( 10,0 ) 10,0
LET X ( 1 ) 1
WHILE ( X 1 < 5 ) 1
LET P1 ( P1 0,0 + 0,10 ) 0,10
LET P2 ( P2 10,0 + 0,10 ) 10,10
LINE TWO_PTS P1 0,10 P2 10,10
END
LET X ( X 1 + 1 ) 2
END_WHILE ( X 2 < 5 ) 1
LET P1 ( P1 0,10 + 0,10 ) 0,20
LET P2 ( P2 10,10 + 0,10 ) 10,20
LINE TWO_PTS P1 0,20 P2 10,20
END
LET X ( X 2 + 1 ) 3
END_WHILE ( X 3 < 5 ) 1
LET P1 ( P1 0,20 + 0,10 ) 0,30
LET P2 ( P2 10,20 + 0,10 ) 10,30
LINE TWO_PTS P1 0,30 P2 10,30
END
LET X ( X 3 + 1 ) 4
END_WHILE ( X 4 < 5 ) 1
LET P1 ( P1 0,30 + 0,10 ) 0,40
LET P2 ( P2 10,30 + 0,10 ) 10,40
LINE TWO_PTS P1 0,40 P2 10,40
END
LET X ( X 4 + 1 ) 5
END_WHILE ( X 5 < 5 ) 0
TRACE
The first line of trace
LET P1 0,0
is the same as in our macro.
The second line is different. Here, the "expression" within the parentheses has been evaluated. The result 10,0 is shown immediately after the expression.
Now look at the boolean expression:
WHILE ( X 1 < 5 ) 1
The current value of X is 1. This is shown immediately after X. The boolean expression (1 < 5) is true, so the value 1 appears immediately after the expression.
Note that WHILE never appears again in trace, but the value of the boolean expression appears after END_WHILE. Look at the last boolean expression after the last END_WHILE. Here, the current value of X is 5. The boolean expression is (5 < 5), which is false, so the value of the expression is 0.
The following macro will work:
DEFINE Parenth_2
LET P1 (0,0) {parentheses not necessary}
LET P2 (10,0) {parentheses not necessary}
WHILE (1) {parentheses necessary}
LET P1 (P1 + 0,10) {parentheses necessary}
LET P2 (P2 + 0,10) {parentheses necessary}
LINE TWO_PTS P1 P2 END
END_WHILE
END_DEFINE
Now the expression after the WHILE is always true. This macro will continue drawing lines until there is a power failure or until you press [Break].
This macro was included deliberately to show that a boolean expression always needs parentheses, even if a simple token is being used. If you don't believe it, try changing WHILE (1) to WHILE 1.
Change WHILE (1) to WHILE (TRUE) and it still works.
The following macro shows that a boolean expression is true if it has any non-zero value:
DEFINE Parenth
LET P1 0,0
LET P2 (10,0)
LET X (5)
WHILE (X)
LET P1 (P1 + 0,10)
LET P2 (P2 + 0,10)
LINE TWO_PTS (P1) (P2) END
LET X ( X - 1)
END_WHILE
DISPLAY_NO_WAIT 'something has changed'
WAIT 3
LET X ( X - 1 )
WHILE (X)
LET P1 (P1 + 0,10)
LET P2 (P2 + 0,10)
LINE (TWO_PTS) P1 P2 END
LET X ( X + 1)
END_WHILE
END_DEFINE