Generating Datum Features Using the Knowledge Pattern 

The task below shows how to generate datums from the Knowledge Pattern.  In this scenario, you are going to create a Knowledge pattern that will generate points and lines datums whose number will be driven by parameters.
To create a Knowledge Pattern, you have to:

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

  1. Click the Formula icon (). 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

  1. From the Start > Knowledgeware menu, select the Product Knowledge Template workbench.

  2. Click the Create a Knowledge Pattern icon (). The Knowledge Pattern Editor opens.

  3. Enter the following code in the editor or copy/paste the code contained in this file:

    let i (integer) (1)
    let p (Point)
    let p2 (Point)
    let l( line)

    let R (integer)
    let G (integer)
    let B (integer)

    i = 1

    For i while i <= NbPoints
              {
                         set p = CreateOrModifyDatum("Point", `Geometrical Set.1` ,Points, i)
    (2)

                         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)
    (3)
                         p.Name = "Point." + ToString(i)

                         if PointsHidden == True
    (4)
                                  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)

                                  }
                                  i = i +1
                }

                 if GenerateLines == True
                         {
                                     i = 1

                                     For i while i <= `Relations\Knowledge Pattern.1\Points` - 1
                                               {
                                                          set l = CreateOrModifyDatum("Line", `Geometrical Set.1` , Lines, i)
    (5)
                                                          l.Name = "Line." + ToString(i)
                                                          p = Points.GetItem(i)
                                                          p2 = Points.GetItem(i + 1)

                                                          l = line(p, p2)

                                                          R = mod(i , 255)
                                                          G = mod(i * 2, 255)
                                                          B = 255 - mod(i, 255)

                                                           l.Color = ToString(R) + "," + ToString(G) + "," + ToString(B)
    (6)

                                                           i = i + 1
                                              }
                         }

    In the script above, you first declare the local variables for points and lines then for colors: R= Red, G=Green, B=Blue (1). Then, 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 (2) and a formula based on a point constructor (3). Then, the system checks if the points are hidden or not. If not, a color is applied.  (4)
    The lines are generated in the Geometrical Set using the CreateOrModifyDatum method (5) and a color is applied.  (6)
  4. Click Add. List.1 = 0 elements is displayed in the Knowledge Pattern Lists field.

  5. Click it and replace it with Points in the Name field.

  6. Click Add. List.2 = 0 elements is displayed in the Knowledge Pattern Lists field.

  7. Click it and replace it with Lines in the Name field.

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

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

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

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

  12. Double-click the NbPoints parameter. Use the spin box to indicate the number of instances you want to instantiate (50 in this scenario.)

  13. Click Execute now. 50 datum features are created.

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

  15. Use the spin box to set the number of instances to 300 and click OK. 300 instances are created.

    Click here to open the Part containing the Knowledge Patterns.