Cubit 16.14 User Documentation
To use APREPRO within CUBIT, simply enclose APREPRO statements within curly braces '{}' as part of the CUBIT command. Any APREPRO statements included in a command will be evaluated before the command is executed. For example, if the APREPRO variable 'my_x' is given the value of 3, the command
brick x {my_x}
will become
brick x 3
before the command is executed by CUBIT. Note that this means APREPRO will NOT give CUBIT parametric modeling abilities. In the above example, if the value of 'my_x' is later changed to 5, the size of the brick already created will not automatically change to five.
APREPRO expressions can also exist on separate lines. When doing this, it is recommended to add the CUBIT comment character '#' before the APREPRO statement. This will tell CUBIT to treat the evaluated expression as a comment, which will prevent errors from being issued in many cases.
Consider the following example:
#{my_x = 3}
#{my_y = my_x + 2}
#{if(my_y < my_x)}
brick x {my_x} y {my_y}
#{else}
create cylinder radius {my_x} height {my_y}
#{endif}
In the first two lines, only APREPRO statements are being executed (values are assigned to the variables 'my_x' and 'my_y'). After being evaluated by APREPRO, these two lines will be sent to CUBIT as
#3
#5
If the comment character was omitted instead CUBIT would issue several errors about incorrect command syntax. However, because these lines start with the comment character, they are ignored by CUBIT. Also note that the character '$' may be used in place of '#' for comments.
Repeated processing of a group of lines can be controlled with the {loop(control)}, {endloop} commands, as noted in section 6.2.5 of the APREPRO documentation.
A loop may also be terminated before running the specified number of times using a #{break} statement. As soon as a #{break} statement is encountered, the loop is exited and the rest of the statements in the loop will not execute. Additional iterations of the loop will not be executed either.
For example, the following commands will create 3 bricks:
#{_x = 1}
#{loop(10)}
brick x 1
#{if(_x == 2)}
#{break}
#{endif}
#{_x++}
pause
brick x 1
#{endloop}
When a #{break} statement executes, anything in the loop following the #{break} statement will be skipped, including the #{endif}. For this reason, a #{break} statement not only exits the loops, but also terminates the most recent #{if} statement exactly as #{endif} would do. #{break} statements should not be used outside of #{if} statements.
It is also possible to terminate a loop using the #{abortloop} statement. #{abortloop} will terminate all loops (including nested loops) without executing the contents of the loop(s). This can be useful when a typo is made while manually entering a loop at the command line. Instead of ending the loop normally and waiting for the loop to execute with numerous errors, the loop will end immediately without any execution or errors. Please note, however, that the #{abortloop} statement is only valid within a loop block; otherwise, it will generate errors.
When creating a loop, APREPRO will record all lines that are given to the command line until the corresponding #{endloop} is reached. During this process, no commands will be passed to CUBIT. Once the terminating #{endloop} is reached, APREPRO will expand the loop, repeating the recorded lines the number of times specified by the loop counter, and send the expanded list of commands to CUBIT. If the terminating #{endloop} is accidentally omitted, CUBIT may appear to be unresponsive to commands because APREPRO is still recording lines for the loop. In situations like these, the #{abortloop} statement may be used to terminate any unfinished loops and restore the command line to a working state.
Also note that it is not recommended to use the 'pause' command within a loop, as it can lead to situations in which the user must repeatedly enter the command 'resume' to execute the entire loop. In situations like these #{abortloop} will NOT terminate the loop because it has already been expanded by APREPRO and CUBIT is simply executing a list of commands.
There are two ways to delete an APREPRO variable in CUBIT. The first is to use the APREPRO 'delete' function. The delete function takes the name of the variable to be deleted as its argument, as shown in the following example:
#{my_var = 2}
...
#{delete('my_var')}
The second way to delete an APREPRO variable is by using the 'reset aprepro' command:
#{my_var = 2}
#{some_var = 3}
...
reset aprepro
This will delete all APREPRO variables and reset APREPRO to its initial state.
The following example shows the use of some of the string functions.
#{t1 = "ATAN2"}{t2="(0,-1)"}
#{t3 = tolower(t1 // t2)}
... The variable t3 is equal to the string atan2(0,-1)
#{execute(t3)}
...t3 = 3.141592654
The result is the same as executing {atan2(0,-1)} This is admittedly a very contrived example; however, it does illustrate the workings of several of the functions. In the first example, an expression is constructed by concatenating two strings together and converting the resulting string to lowercase. This string is then executed.
The following example uses the rescan function to illustrate a basic macro capability in APREPRO. The example creates vertices in CUBIT equally spaced about the circumference of a 180 degree arc of radius 10. Note that the macro is 5 lines long (2 of the lines start with #, with the exception of the looping constructs - the actual journal file for this would not continue lines but would put each one on one long line).
#{num = 0} {rad = 10} {nintv = 10} {nloop = nintv + 1}
#{line = 'Create Vertex {polarX(rad,(++num-1)*180/nintv)} {polarY(rad,(num-1)*180/nintv)}'}
#{loop(nloop)}
{rescan(line)}
#{endloop}
Note the loop construct to automatically repeat the rescan line. To modify this example to calculate the coordinates of 101 points rather than eleven, the only change necessary would be to set {nintv=100}.