Share

SWITCH statement

When you compare a variable with a number of possible values and each value determines a different outcome, it is advisable to use the SWITCH statement.

The SWITCH statement enables you to compare a variable against a list of possible values. This comparison determines which commands are executed.

The basic control structure is:

SWITCH variable {
CASE (constant_A)
    Commands A
CASE (constant_B)
    Commands B
DEFAULT
    Commands C
}
Commands D

If condition_A is true then Commands A, B, C, and D are executed.

If condition_B is true then Commands B, C, and D are executed.

If condition_A and condition_B are false then Commands C, and D are executed.

image

Note: When a match is found all the commands in the remaining CASE statements are executed. You can prevent this from happening by using a BREAK statement.
Note: You can have any number of CASE statements, but at most one DEFAULT statement.

This example makes changes to the point distribution based on the tool axis type. There are three options:

  1. 3+2-axis toolpaths to have an output point distribution type of Tolerance and keep arcs and a lead in and lead out distance of 200.

  2. 3-axis toolpaths to have an output point distribution type of Tolerance and keep arcs.

  3. 5-axis toolpaths to have an output point distribution type of Redistribute.

Note: Because the CASE 'direction' block of code does not have a BREAK statement the macro also executes the code in the 'vertical' block.
SWITCH ToolAxis.Type {
    CASE 'direction'
        EDIT TOOLPATH LEADS RETRACTDIST "200.0"
        EDIT TOOLPATH LEADS APPROACHDIST "200"
        // fall though to execute
    CASE 'vertical'
        // Redistribute points to tolerance and keep arcs
        EDIT FILTER TYPE STRIP
        BREAK
    DEFAULT
        // Redistribute points
        EDIT FILTER TYPE REDISTRIBUTE
        BREAK
}

Was this information helpful?