Condition when creating a macro

You can specify a condition for each macro action when creating a macro. The macro is executed only if the condition is True. The predefined variables and the custom variables can be used to perform tests in a specific condition. You can import custom variables using the macro variables import interface. To disable a macro action temporarily, you can specify False in the Condition field of the macro action.

For example, a macro action is executed only if the number of selected process batches is greater than 100, using the SelectedProcessBatches>100.

This table shows the comparators in macro condition:

Comparison Description
Var > x True when the variable is greater than x
Var < x True when the variable is less than x
Var = x True when the variable is equal to x
Var <> x True when the variable is not equal to x
Var >= x True when the variable is greater than or equal to x
Var <= x True when the variable is less than or equal to x

You can combine comparisons using "&" and "|" operators:

Operator Description
& And
| Or

For example, the macro action is executed only if the number of selected process batches is greater than 100 and less than 200 using the SelectedProcessBatches>100 & SelectedProcessBatches<200 condition.

Predefined macro variables

The predefined macro variables represents the result code of the last executed action. The value of this variable is based on the action performed.

This table lists the value for each action:

Action Value that is stored in the ActionResult variable
Schedule.Check Schedule 1 in case of error, else 0.
Schedule.Run Solver The value of SolutionCount variable. See the description of this variable.
Inventory.Find Shortage.Below Minimum Number of violating products
Inventory.Find Shortage.Below Standard Number of violating products
Inventory.Find Overflow Number of violating products
Inventory.Batch Selection.Inflow Products Number of selected products
Inventory.Batch Selection.Outflow Products Number of selected products
Inventory.Batch Selection.All Products Number of selected products

For all the other actions, the ActionResult variable is reset to 0.

You can use this variable to check the result of a solver. However, the value is overwritten when another macro action is executed. Therefore, it is recommended to use the SolutionCount variable instead of ActionResult variable.

SelectedProcessBatches

This represents the number of selected process batches.

SelectedTankBatches

This represents the number of selected tank batches.

SelectedProducts

This represents the number of selected products.

SelectedOrders

This represents the number of selected orders.

SolutionCount

This represents the number of solutions of the last solver. This table lists the possible values for the solver results:

Solver result Value of SolutionCount
No solution found 0
Current solution only 1
Current sequence only 2
Current solution, plus current sequence 3
First heuristic solution 4
Second heuristic solution, and so on 5
Tenth heuristic solution 13
Partial solution with failed auxiliary constraints and all batches placed Same as above
Partial solution with failed inventory constraints and all batches placed (repair initial level, extra batches, etc.) Same as above but negative
Partial solution with failed critical constraints (for example, not all the batches are added) and all batches placed 0
Partial solution with failed constraints and not all batches placed 0
Partial solution without failed constraints but not all batches placed 0

For example, you can specify that a solver is run only if no solution has been found by the previous solver.

This table lists the details of an example related to macro parameters with this variable:

Condition Action Parameters Description
Schedule.Run Solver 2a - Multi-Stage Solver #1
SolutionCount=0 Schedule.Run Solver 3 - Multi-Stage Solver #2 Run this solver only if no solution is provided by solver #1
Note: You can specify False to skip a line.

The SolutionCount variable is used to check the result of a solver. If solution is not found by a solver, the value of the SolutionCount variable is set to 0.

The SolutionCount variable can be used when calling a macro that calls a solver as this variable is only set by the Schedule.Run Solver action.

For example:

Macro Action Result
RunSolver1 Schedule.Run Solver "Solver1" The ActionResult and SolutionCount variables are set to the result of the solver.
RunTest Automation.Run Macro "RunSolver1" The SolutionCount value is still the result of Solver1, but the ActionResult variable is reset to 0.