Creating a Reaction: BeforeUpdate Event  

This task explains how to use the BeforeUpdate event in a reaction feature. In the scenario below, you are going to optimize the position of a point each time you modify the length of the cable (spline). You create  your geometry and insert all the components in a User Feature (UDF). This UDF contains the geometry of a cable going through 3 points:
  • The two points located at both extremities are to be specified in input.
  • The coordinate of the third point is optimized to reach a target length for the cable. 

This target parameter is a published parameter of the UDF. The optimization is launched by using a VBMacro with argument, called in a Reaction to the "Before Update" event of the UDF.  

This scenario requires the Product Engineering Optimizer product.
  1. Open the KwrEvent_BeforeUpdate.CATPart file: It contains 3 points and a spline (called cable in this scenario).

     
  1. From the Start > Knowledgeware menu, access the Product Engineering Optimizer workbench and click the Optimize icon (). The Optimization window opens.

  2. Enter the following data in the Optimization window:

    Problem tab  
      Optimization type Minimization
    Optimized parameter distance
    Free parameters Geometrical Set.1\Point.3\Z
    Algorithm Simulated Annealing Algorithm
    Termination criteria

    Maximum number of updates: 100
    Consecutive updates without improvements: 20
    Maximum time (minutes): 5

    Constraints tab  
      New constraint Geometrical Set.1\Point.3\Z` - max (Geometrical Set.1\Point.2\Z) ,Geometrical Set.1\Point.1\Z) <= 0mm 
  3. Click OK in the opening dialog box, click Run optimization.

  4. Select an output file and click Save.

  5. Click OK  when the optimization process is over.

  6. From the Start > Knowledgeware menu, access the Knowledge Advisor workbench and click the Macros with argument icon (). The Script Editor opens. Enter the following data in the editor and click OK:

    Argument optim
    Script body optim.Run false
  1. Click the Reaction icon (). The Reaction dialog box opens. 

  •  
In the Source type field, select Owner.
  •  
From the Available events list, select BeforeUpdate.
  •  
In the Action field, select Knowledgeware action.
  1. Click Edit action..., paste the following script in the editor, and click OK twice:

if (CableLength <= distance (Geometrical Set.1\Point.1 ,Geometrical Set.1\Point.2 ))
Message ("Incompatible inputs: cable length is less than distance between points!")
else
{
`VB Script.1` .Run(Relations\Optimizations.1\Optimization.1 )
}
  1. Double-click the root of the specification tree and select Insert > UserFeature > UserFeature Creation.... The User Feature Definition window opens.

  2. In the Name field, enter the name of the UDF: Cable1 in this scenario.

  3. Select the Spline, Point3, Reaction.1, VB Script.1, Optimization.1, the 4 formulas, and the parameters: they are displayed in the User Feature definition window.

Note that the UDF becomes the owner of the reaction. This reaction will be fired before the update of the UDF instance.
  1. Click the Parameters tab, select CableLength, click the Published name check box and click OK.

  2. Save the file and close it.

  3. Create a .CATPart file, access the Generative Shape Design workbench,  and create 3 points. 

  4. Select Insert > Instantiate From Document.... The File Selection window opens. Select the KwrEvent_BeforeUpdate.CATPart file you saved and click Open.

  5. The Insert object dialog box opens. Select Point.1 and Point.2 in the geometry or in the specification tree and click OK. The cable (UDF) is instantiated and the optimization is launched before the update.

  6. Repeat steps 14 and 15: select Point.2 and Point.3 when instantiating the UDF: the cable lengths are optimized.

  1. Double-click the CableLength=400mm parameter and change its value to 200mm. This cable length is optimized once again before the update.

For more information about the Reaction feature window, see Using the Reaction Feature Window.