Using a Reaction with a User Feature: Instantiation Event  

This task explains how to use a reaction in a User-Defined Feature. The scenario described below is divided into two major steps:
  • In the first step, you first create a formula that returns the length of the line, you create a reaction that will add items of length type to a list when the document is instantiated and then you create a UDF containing the line, the reaction and the formula.
  • In the second step, you open a second document, you create a rule based on a list that will display the total length, and then you instantiate the UDF that you previously created in this document.
A basic understanding of the Part Design workbench and of Product Knowledge Template is required to perform this scenario.
Note that the Instantiation event is available for User Features only. It cannot be used with Power Copies.
  1. Open the KwrUDFandReaction.CATPart file.

  2. Create a parameter of Length type and assign it a formula.

  • Click the icon, select Length from the New Parameter of Type scrolling list, click New Parameter of type, and click Add Formula.
  • In the Dictionary, click Measures, and  double-click length (Curve,): Length.
  • Position the cursor between the parentheses and double-click Line.1 in the specification tree. Click OK, Yes, and OK. (Length.1=length(Geometrical Set.1\Line.1)).
  1. Access the Knowledge Advisor workbench, click the List icon () to create a list, and click OK. An empty list appears under the Parameters node.

 

  1. Click the Reaction () icon. The Reaction editor opens:

    • From the Source type list, select Owner.

    • In the Available events, select Instantiation.

    • In the Action area, select Knowledgeware action and click Edit action. The Action editor opens.

    • Click the list in the specification tree and, in the Dictionary pane select List, and in the Member pane, double-click List.AddItem.

    • Position the cursor between the parentheses and enter Length.1 before the comma, and 0 after the coma. Click OK twice. The Reaction feature is created.

  2. Access the Part Design workbench and select Insert > UserFeature > UserFeature creation. The Userfeature Definition window opens: in the Definition tab, enter the name of the User Feature (UserFeature1 in this scenario) and select the Line, the Reaction, and the Length parameter in the specification tree. Click OK.
    The UserFeature1 is created and displayed under the Knowledge Templates node.

  3. Save your file, close it, and open the KwrUDFandReaction2.CATPart file This is the file into which you will instantiate the UDF you previously created.

  4. Access the Knowledge Advisor workbench, and click the List icon () to create an empty list and click OK.

  5. Create a parameter of Length type (called Length.1 in this scenario) and apply a formula to it.

    • Click the icon, select Length from the scrolling list, click New Parameter of type, and click Add Formula.

    • Select the list in the specification tree, in the Dictionary pane select List, and in the Member pane, double-click List.sum. Click OK three times.

  6. Click the Rule icon (), click OK, enter the following script in the Rule Editor, and click OK:

    Message("Total Length : #",Length.1 )

    The total length is displayed: 0mm.

  7. Access the Part Design workbench and select Insert > Instantiate from Document.

  8. Select the file you created (from step 1 to step 5, KwrUDFandReaction.CATPart in this scenario) and click Open. The Insert Object window opens:

  • Select Point.1 in the specification tree or in the geometry.
  • Select Point.2 in the specification tree or in the geometry.
  • Select List.1 in the specification tree and click OK. The rule is fired and the Total Length is displayed.