Using the Loop Behavior  

The aim of this scenario is to show the user how to use the loop behavior as a "while" object. The expert user defines rules and checks to set the instantiation context of dominoes and the loop is automatically stopped during its execution. The expert user defines a number of iterations which is too large and he wants to send a window to inform the user when and why the loop stops.

The scenario is divided into the following steps:

Remember to:
  • Save your .CATScript files in the startup\automation directory and your .CATfct file in the directory corresponding to the CATGraphicPath environment variable.
  • Modify the path of the LoadDocument behavior if you use the provided .CATfct file.
  • To perform this scenario, you will need the following files:

Create the technological type

  1. From the Start>Knowledgeware menu, access the Business Process Knowledge Template workbench.

  2. Create the DominoesSet technological type.

    • Click the Create Technological Type icon () to create the technological type. The Create technological type dialog box is displayed. Enter DominoesSet.
    • Click OK to validate.

Add the "Instantiation in Context" Sequence to the DominoesSet Technological Type

  1. Click the DominoesSet type and click the Sequential Combination behavior () to create a combination of behaviors. 

  1. Double-click the SequentialCombination in the Behaviors View and DominoesSet in the Behaviors tab to access the sequential combination.

  2. Double-click the SequentialCombination node that is displayed in the Behaviors tab. (Expand the DominoesSet node if need be.)

  3. Enter the name of the combination, Instantiation in context in this scenario, in the Name field of the opening dialog box and click OK to validate.

  4. Select the Instantiation in context combination in the Behaviors tree and click the Bind Object Behavior icon ().

  5. Double-click the BindObject behavior. The Bind Object window is displayed.

    • Enter Bind Part in the Name field.
    • Enter ../../.. in the Relative Name field. Click OK to validate.
  6. Select the Instantiation in context combination in the Behaviors tree and click the Bind Object Behavior icon ().

    • Enter Bind PartBody in the Name field.
    • Click the Starting from field, expand the BindPart variables node and select the Link. =BindPart\Link is displayed in the Starting from field.
    • Enter PartBody in the Relative Name field. Click OK to validate.
  7. Select the Instantiation in context combination in the Behaviors tree and click the Bind Object Behavior icon ().

  8. Double-click the BindObject behavior. The Bind Object window is displayed.

    • Enter Sketch Support in the Relative Name field.
    • Click the Starting from field, expand the Bind PartBody variables node and select the Link. =Bind PartBody\Link is displayed in the Starting from field. Click OK to validate.
  1. Select the Instantiation in context combination in the Behaviors tree and click the Load Behavior icon ().

  2. Double-click the LoadDocument node. The Load Document editor is displayed.

    • Click the ... button and select the BktUDFDomino.CATPart in the File Selection dialog box and click Open when done.
    • Click OK to validate.
  3. Select the Instantiation in context combination in the Behaviors tree and click the Bind User Feature icon ().

  4. Double-click the BindUserFeature in the Behaviors tree. The Bind User Feature editor is displayed.

    • Select the From object: field, expand the LoadDocument variables node and select the Document output. =LoadDocument\Document is displayed in the From object: field.
    • Click OK to validate.

Create the Loop of Behaviors

  1. Select the Instantiation in context combination in the Behaviors tree and click the Loop icon ().

  2. Double-click the Loop in the Behaviors tab. The Loop editor is displayed.

    • Enter the number of iterations: 15.
    • Click the Attributes tab and add the following attribute:
      Name Inst_Ratio Type Real Quality Input Value 0.1
    • Click OK to validate.
  3. Select the Loop combination in the Behaviors tree and click the Knowledge Relations  Behavior icon ().

  4. Double-click the KnowledgeRelations behavior. The Knowledge Relations editor is displayed.

  5. Click the Attributes tab and add the following attributes:

Name TempRatio Type Real Quality Internal    
Name RatioforUDF Type Real Quality Output    
Name ratio Type Real Quality Input    
Name UDF_Act Type Boolean Quality Output Value False
Name Info_Act Type Boolean Quality Output Value False
  1. In the Content tab, right-click the TempRatio attribute and select Edit Formula. The Formula editor is displayed.

  2. Enter the following formula: TempRatio=ratio + `DominoesSetMDL\Instantiation in context\Loop\Iteration` / 2 * 0.1. Click OK when done to close the editor.

  3. Click the Content tab and click the Rule icon (). Enter the following rule body into the rule editor, click OK when done and OK to exit the Knowledge Relations editor.

    if TempRatio <= 1
    {
    RatioforUDF = TempRatio
    UDF_Act = TRUE
    Info_Act = FALSE
    }
    else
    {
    RatioforUDF = TempRatio
    `DominoesSetMDL\Instantiation in context\Loop\NumberOfIterations` = `DominoesSetMDL\Instantiation in context\Loop\Iteration`
    UDF_Act = FALSE
    Info_Act = TRUE
    }
  4. Expand the Knowledge Relations variables node as well as the Loop variables node.

  5. Right-click the ratio variable located below the Knowledge Relations node, select ratio object>Link To, and click the Inst_Ratio variable located below the Loop node. Both variables are now linked.

  6. Select the Loop combination in the Behaviors tree and click the Instantiate Template  Behavior icon ().

    • Click the Template feature field, expand the BindUserFeature node and select the UserFeature. =BindUserFeature\UserFeature is displayed in the Template feature field.
    • Click the Destination field, expand the Bind Part node and select the Link. =Bind Part\Link is displayed in the Destination field.
    • Click Add in the Defined inputs and parameters field and add the following attributes:
      Name: ratio, Type: Real, Quality: Input, Value: 0.1
      Name: Sketch.1, Type: Pointer, Quality: Input
    • Click OK when done.
  7. Expand the Instantiate Template variables node, right-click the ratio variable located below the Knowledge Relations node, select ratio object>Link To, and click the RatioforUDF variable located below the Knowledge Relations node.

  8. Right-click the Sketch.1 variable, select Sketch.1 object>Link To, expand the Bind Sketch Support variables node and select the Link.

  9. Right-click the Activity variable, select Activity object>Link To, and click the UDF_Act variable located below the Knowledge Relations node.

  10. Select the Loop combination in the Behaviors tree and click the Synchronize Parameters  Behavior icon ().

  11. Double-click the SynchronizeParameters behavior in the Behaviors tree. The Synchronize Parameters editor opens:

    • Click the From Parameter field, expand the Knowledge Relations node and click the RatioforUDF variable. =KnowledgeRelations\RatioforUDF is displayed in the From Parameter field.
    • Click the To Parameter field, expand the Loop node and click the Inst_Ratio variable. = Loop\Inst_Ratio is displayed in the To Parameter field.
    • Click OK to validate.
  12. Expand the SynchronizeParameters behavior node in the Behaviors tree. Right-click the Activity variable, select Activity object>Link To and click the UDF_Act variable located below the Knowledge Relations node.

  13. Select the Loop combination in the Behaviors tree and click the Add To List  Behavior icon ().

  14. Double-click the AddToList behavior. The AddToList editor is displayed:

    • Click the List field, expand the Loop variables node and select the List feature. = Loop\List is displayed in the List field.
    • Click the Object: field, expand the BindUserFeature variables node and select the UserFeature. =BindUserFeature\UserFeature is displayed in the Object field.
    • Click OK when done.
  15. Expand the AddToList behavior node. Right-click the Activity variable, select Activity object>Link To and click the UDF_Act variable located below the Knowledge Relations node.

  16. Right-click the Index variable, select Index  object>Link To and click the Iteration variable located below the Loop node.

  17. Select the  Loop combination in the Behaviors tree and click the VB Script Behavior icon ().

  18. Double-click the VBScript behavior in the behaviors tree. The VBScript editor is displayed.

    • Click Add in the Defined inputs and parameters field and add the following attributes:
      • Name: Iteration, Type: Integer, Quality: Input, Value: 1
      • Name: Ratio, Type: Real, Quality: Input, Value: 0.1
      • Name: NextRatio, Type: Real, Quality: Input, Value: 0.15
    • Click OK when done.
  19. Expand the VBScript behavior node. Right-click the Iteration variable, select Iteration object>Link To and click the Iteration variable located below the Loop node.

  20. Right-click the Ratio variable, select Ratio object>Link To and click the Inst_Ratio variable located below the Loop node.

  21. Right-click the NextRatio variable, select NextRatio object>Link To and click the RatioforUDF variable located below the Knowledge Relations node.

  22. Right-click the Activity variable, select Activity object>Link To and click the Info_Act variable located below the Knowledge Relations node.

 

At this stage of the scenario, the Behaviors tab is similar to the graphic opposite.

The definition of the behaviors is now over. Save your file and generate your workbench. (Click here to display the generated .CATfct file).

Generate the Workbench

  1. Click the Applicative Workbench Generation icon () to generate a user workbench. Enter the name of the workbench in the Workbench name field, Dominoes in this example, and select the workbench type, Part in this scenario.

Test the Workbench

  1. From the Tools>Options>Knowledgeware>Business Knowledge Template menu, select All Users from the Access Rights scrolling list and click OK to work in a User environment.

  2. Open the BktDominoSystem.CATPart file.

  3. Click the root of the specification tree, the icon, the root of the specification tree, and click the DominoesSet icon to type the product.

  4. Right-click DominoesSet (Part2) object and select DominoesSet(Part2) object>Instantiation in Context. The Dominoes are instantiated and a message is displayed indicating that the instantiation will stop at iteration 6.

For more information about: