Prompting for an Integer Entry

You can edit the macro to prompt for an integer entry.

Integer entries are used in various Simcenter STAR-CCM+ features, such as stopping criteria.



For this example, a simple macro was recorded to change the Maximum Steps property of the corresponding stopping criterion from 1000 to 500.



The macro, named integer.java, contains the following code:

// STAR-CCM+ macro: integer.java
package macro;
import java.util.*;
import star.common.*;
import star.base.neo.*;
public class integer extends StarMacro {
  public void execute() {
    Simulation simulation_0 = 
      getActiveSimulation();
    StepStoppingCriterion stepStoppingCriterion_0 = 
      ((StepStoppingCriterion) simulation_0.getSolverStoppingCriterionManager().
         getSolverStoppingCriterion("Maximum Steps"));
    stepStoppingCriterion_0.setMaximumNumberSteps(500);
  }
}

This typical macro code contains the value for the stopping criterion that is entered during recording—it remains constant. However, when the macro contains code for user input, it pauses to activate a dialog in which you can specify that value.



Once you click OK, the macro continues.

The code of integer.java is modified as follows to make this work:

// STAR-CCM+ macro: integer.java
package macro;
import java.util.*;
import star.common.*;
import star.base.neo.*;
public class integer extends StarMacro {
  public void execute() {
    Simulation simulation_0 = 
      getActiveSimulation();
    StepStoppingCriterion stepStoppingCriterion_0 = 
      ((StepStoppingCriterion) simulation_0.getSolverStoppingCriterionManager().
        getSolverStoppingCriterion("Maximum Steps"));
    int ret = promptUserForInput("Maximum Steps", 1000); /* <---- NEW CODE */
    stepStoppingCriterion_0.setMaximumNumberSteps(ret); /* <---- "ret" replaces
         * the numeric entry that was recorded automatically */
  }
}