Creating a Knowledge Advisor Reaction: ValueChange Event

This task explains how to use the ValueChange event associated to the reaction feature.  
The CATPart file contains a cable going through 3 points. The user wants the cable length to be optimized each time he modifies the cable length.
The scenario is divided into 3 parts:
the user creates an optimization
the user creates a reaction
the user modifies the cable length value  
The Reaction capabilities require the Knowledge Advisor product. 
  1. Open the KwrEvent_ValueChange.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 Open_body.1\Point.3\Pointcoordinates.1\Z
    Algorithm Simulated Annealing
    Termination criteria Maximum number of updates: 100
    Consecutive updates without improvements: 20
    Maximum time (minutes): 5
    Constraints tab  
      New constraint `Open_body.1\Point.3\Point coordinates.1\Z` - max (Open_body.1\Point.2.coord(3) ,Open_body.1\Point.1.coord(3)) <= 0mm  
  3. Click Run optimization and click OK to close the window.
  4. 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.
In the Available events list, select ValueChange.
In the Action field, select VB action.
  1.  Click the Edit action... button, 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 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.

To know more about the Reaction feature window, see Using the Reaction Feature Window.

Back Up Next