Generating Datum Objects Using the Knowledge Pattern

You can create a feature that enables you to instantiate templates or datums into documents in batch mode (without user interaction). In this scenario, you are going to create a Knowledge pattern that will generate datum points and lines datums whose number will be driven by parameters.

This task shows you how to:


Before you begin: You must have added the list to the pattern, entered the body of the pattern, selected the execution options, selected the options and opened the document.
Related Topics
About the Knowledge Pattern Feature
About the Knowledge Pattern Editor

Create the Parameters Driving the Pattern: NbPoints, YFactor, XFactor, ZFactor, PointsHidden, GenerateLines

You can create the parameters driving the pattern.

  1. In the Knowledge toolbar Click Formula , The Formula editor opens.

  2. In the New parameter of type combo box, select Integer and click New parameter of type.

  3. In the Edit name or value of the current parameter field, double-click Integer.1 and enter NbPoints. Click OK.

    The NbPoints parameter is created.

  4. In the New parameter of type combo box, select Integer and click New parameter of type.

  5. In the Edit name or value of the current parameter field, double-click Integer.1 and enter YFactor. Click OK. The YFactor parameter is created.

  6. In the New parameter of type combo box, select Integer and click New parameter of type.

  7. In the Edit name or value of the current parameter field, double-click Integer.1 and enter XFactor. Click OK.

    The XFactor parameter is created.

  8. In the New parameter of type combo box, select Integer and click New parameter of type.

  9. In the Edit name or value of the current parameter field, double-click Integer.1 and enter ZFactor. Click OK.

    The ZFactor parameter is created.

  10. In the New parameter of type combo box, select Boolean, and in the Edit name or value of the current parameter field, enter PointsHidden. Click New parameter of type.

  11. In the New parameter of type combo box, select Boolean. In the Edit name or value of the current parameter field, enter GenerateLines. Click New parameter of type. Click OK to validate.

Create the Knowledge Pattern

You can create the knowledge pattern.

  1. Click > Knowledgeware > Templates > Knowledge Template.

    The Knowledge Template workbench opens.

  2. Click Create a Knowledge Pattern .

    The Knowledge Pattern Editor opens.

  3. First, before entering the code, it is necessary to create:


    • Two Geometrical sets ; one for points and one for lines: BodyPoints and BodyLines in this example.
    • It is also necessary to create Parameters as seen hereabove (NbPoints, XFactor, YFactor, ZFactor, PointsHidden, GenerateLines.

    Enter the following code in the editor:

    /* Local variables declaration. First declare the local 
    variables for points and lines then for colors: 
    R= Red, G=Green, B=Blue */
    let i (integer) 
    let p (Point)
    let p2 (Point)
    let l( line)
    
    let R (integer)
    let G (integer)
    let B (integer)
    
    i = 1
    
    /*The pattern ensures associativity regarding number of
    objects created. If it changes from one execution to 
    another, the pattern can delete or create new objects */
    
    For i while i <= NbPoints
        {
           /* Let's create a datum point controlled by the 
           pattern. Its life cycle is managed thanks to the 
           pattern list. Depending on the number of points
           determined, a loop is run to generate the desired 
           number of points in the Geometrical Set using the
           CreateOrModifyDatum method */
           set p = CreateOrModifyDatum("Point", BodyPoints ,
           `Relations\Knowledge Pattern.1\Points` ,  i) 
         
           /* The datum point is "valuated" by a point 
           constructor */
           p  = point(PartBody\Point.2\X + cos(i*XFactor) * 
           10mm, PartBody\Point.2\Y + cos(i*YFactor) * 10mm, 
           PartBody\Point.2\Z + cos(i*ZFactor) * 10mm)
      
           /* Its properties can be modified */
           p.Name = "Point." + ToString(i)
    
           /* the system checks if the points are hidden or
           not. If not, a color is applied */
           if PointsHidden == True 
                   p.Show = False
           else
           {
                   p.Show = True
    
                   R = mod(i	, 255)
                   G = mod(i * 2, 255)
                   B = 255 - mod(i, 255)
    
                   p.Color  = ToString(R) + "," + ToString(G)
                   + "," + ToString(B)
           }
           */ Incrementing i is not mandatory here : +1 
           increment is the default increment. It can be more,
           or it can be negative... but beware of infinite
           loops */
           i = i +1
        }
    
    /* The GenerateLines parameter controls the creation - or
    deletion if they already exist - of lines between points */
    if GenerateLines == True
    {
    
          i = 1
    
          For i while i <= `Relations\Knowledge Pattern.1\
          Points`->Size()   - 
          {
              /* Let's create a datum line controlled by the 
              pattern. Its life cycle is managed thanks 
              to the pattern list. The lines are generated
              in the Geometrical Set using 
              the CreateOrModifyDatum method */
              set l = CreateOrModifyDatum("Line", BodyLines ,
             `Relations\Knowledge Pattern.1\Lines` , i) 
     
              p = `Relations\Knowledge Pattern.1\Points` 
              .GetItem(i)
              p2 = `Relations\Knowledge Pattern.1\Points`
              .GetItem(i + 1)
    
              /* The datum line is "valuated" by a Line
              constructor */
              l = line(p, p2)
    
              /* Its properties can be modified */
              l.Name = "Line." + ToString(i)
    
              R = mod(i	, 255)
              G = mod(i * 2, 255)
              B = 255 - mod(i, 255)
    
              /* a color is applied */
              l.Color  = ToString(R) + "," + ToString(G)
              + "," + ToString(B) 
    
              i = i + 1 
          }
     }

  4. Click Add. List.1 = 0 elements is displayed in the Knowledge Pattern Lists field. Click it and replace it with Points in the Name field.

  5. Click Add. List.2 = 0 elements is displayed in the Knowledge Pattern Lists field. Click it and replace it with Lines in the Name field.

  6. In the Mode combo box, select Automatic execution (before root update). Click OK when done.

  7. In the specification tree, double-click the YFactor parameter and enter 1. Click OK.

  8. Double-click the XFactor parameter and enter 2. Click OK.

  9. Double-click the ZFactor parameter and enter 3. Click OK.

  10. Double-click the NbPoints parameter.

    Use the spin box to indicate the number of instances you want to instantiate (50 in this scenario).

  11. Click Execute now.

    50 datum objects are created.

  12. Double-click twice the parameter in the specification tree. The Edit parameter dialog box displays.

  13. Use the spin box to set the number of points to 300 and click OK.

    300 points are created.