Adding a Pre-Condition to Task 2

Add a pre-condition to Task 2.

You cannot create a region from a part if there are no parts in the simulation, so it makes sense to add a pre-condition to Task 2, that disables that task if no geometry parts exist.

The following code adds a pre-condition to Task 2 to check whether a part exists in the Geometry > Parts manager node. If no part exists, the task is disabled (greyed out). If a part exists, the condition is satisfied and the task is enabled. Pre-conditions only affect the task that they are placed in.

  1. Return to the Task02CreateRegionFromPart class.
  2. Locate the public Task02CreateRegionFromPart() constructor.
  3. Add the following code to this constructor:
    // Makes sure that a geometry exists before enabling this task.
    setPreconditions(Collections.singleton(InternalFlowConditions.createPartCondition()));

    where:

    • setPreconditions() sets the pre-condition for the task.
    • Collections.singleton(InternalFlowConditions.createPartCondition()) is the condition that checks for a geometry part.
  4. Add the missing import.
  5. Save and build your project.