Creating a Loop in a Reaction

If you want an action to be repeated several times, you can create a loop in a reaction.

  1. Create a Representation containing 3 points.
  2. From the Compass, click 3D Modeling Apps , and select Engineering Rules Capture.
  3. Click List to create the list that will contain the created points.
  4. Add a formula to complete the list.
    1. Click Formula from the Tools section. The Formulas editor appears. In the tree, select List.1 and click Add formula.
    2. Enter the following formula: List.1=PartBody.Query("Point", ""). Click OK three times when done.
  5. Click Reaction . The Reaction dialog box opens.
    1. In the Source type box, select Selection and select the list in the tree for the reaction to be applied when the list is modified.
    2. In the Select a source... dialog box, select List.1 and click OK.
    3. In the Available events list, select ValueChange.
    4. In the Action box, select Knowledge action and enter the following message action body:
      let x(Point)
      for x inside parameter
      {
        if (x.GetAttributeReal("Z") < 0.02)
          x.SetAttributeReal("Z",0.02)
      }
    5. Click OK when done.
      The reaction feature is added to the Relations node.
  6. Click Reaction . The Reaction dialog box opens.
    • In the Source type box, select Selection and select the list in the tree for the reaction to be applied when the list is modified.
    • In the Select a source... dialog box, select List.1 and click OK.
    • In the Available events list, select ValueChange.
    • In the Action box, select Knowledge action and enter the following message action body.
    let i =1
    let x(Point)
    for i while i<=parameter.Size()
    {
      x = parameter.GetItem(i)
      if (x.GetAttributeReal ("Y") < 0.04)
        x.SetAttributeReal ("Y",0.04)
    }
    • Click OK when done. The reaction is added to the Relations node.
  7. Create a point with the following coordinates:
    X: 36mm Y: 12mm Z: 0mm
  8. Update the representation twice. The Y and Z coordinates are set to 40 and 20 mm.
    Note: It is possible to use the While and the For constructs.