Creating a Reaction: ValueChange Event  

This task explains how to use the ValueChange event associated with the reaction feature.  
The CATPart file contains a cable going through 3 points. You want the cable length to be optimized each time you modify the cable length.
The scenario is divided into 3 parts:
  • you create an optimization
  • you create a reaction
  • you modify the cable length value  
  1. Open the KwrEventValueChange.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-Convergence speed
    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 Reaction icon (). The Reaction dialog box opens. 

  • In the Source type field, select Selection and select the CableLength parameter in the specification tree for the Reaction to be applied to the CableLength parameter.
  • From the Available events list, select ValueChange.
  • In the Action field, select VB action.
  1. Click Edit action..., paste the following script in the editor, and click OK twice:

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim relations1 As Relations
Set relations1 = part1.Relations
Dim optimizations1 As Optimizations
Set optimizations1 = relations1.Optimizations
Dim anyObject1 As Optimization
Set anyObject1 = optimizations1.Item("Optimization.1")

anyObject1.Run False

The reaction is added to the specification tree. 

  1. Double-click twice the CableLength=400mm parameter and change its value to 600mm: The optimization is launched (the RealLength and the distance parameters have changed) and the geometry is changed accordingly.

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