Instantiating a User Feature Using the Knowledge Pattern  

The task below shows how to instantiate a User Feature using the Knowledge Pattern. This scenario is based on ARM and on the new Knowledge directories structure. For more information, see CATIA Infrastructure User's Guide: Advanced Tasks: Using Knowledgeware Capabilities: Managing Knowledge Applications Resources.
To perform this scenario, you will need the following files:
This document contains a User Feature that will be instantiated from the Knowledge Pattern. For more information on how to create UDF see Creating a User Feature
This file contains the information concerning the typed User Feature.
This document will contain the Knowledge Pattern and you will instantiate User Feature in this document.
This document is the ARM catalog referencing the physical resources used in this scenario.
Before performing this scenario, make sure that you have:
  • Selected the directory that contains the Pkt_Cylinder.CATGScript in the Reference Directory For Types field in the Tools>Options>General>Parameters and Measures>Knowledge Environment tab.
  • Selected the Architect Resources Creation Path in the Tools>Options>General>Parameter and Measures>Knowledge Environment tab.  Remember that the directory selected here can only be the knowledge directory of the Knowledge directories structure.

    For more information about this structure, see CATIA Infrastructure User's Guide: Advanced Tasks: Using Knowledgeware Capabilities: Managing Knowledge Applications Resources.


 

  • You can create the new directory structure at any location convenient to you for accessing the files. You need to ensure that the folder structure is as shown below, without any typo errors.

 

Save the Required Data into the New Directories Structure

  1. Save the provided data in the appropriate directories:

    • After the save operation of files in the corresponding directory, it can be necessary to check that the above saved
      CATPart is pointing to the saved catalog. To ensure that new path of the feature is taken into account you need to
      perform the following steps,
  2. Open the Pkt_udf_Knowledge_Pattern.CATPart file.

Create the NbInstances Parameter

This parameter will enable you to determine the number of User Features you want to instantiate

  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 NbInstances. Click OK. The NbInstances parameter is created.

Create the Knowledge Pattern

This feature will enable you to instantiate the User Features

  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.

    • Click Add. List.1 = 0 elements is displayed in the Knowledge Pattern Lists field. This list will list the number of instantiated User Features. (See the image Below)

    • Click it and replace it with Boxes in the Name field.

      • For our scenario purpose edit its name to Points. Similarly create a second list called UDFs

    • In the Mode combo box, select Automatic execution (before root update). This way, when you change the number of desired instantiated User Features, the script will be launched automatically.


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

    Let udf (UserFeature)
    Let i (Integer)
    Let p (Point)

    i=1
    For i while i <= NbInstances
    {
    p= CreateOrModifyDatum("Point",`Instantiated Geometry` ,`Relations\Knowledge Pattern.1\points` ,i)

    p=pointoncurveRatio(`Base Geometry\Line.1` ,`Base Geometry\Point.1` ,i/(NbInstances +1),False)

    udf = CreateOrModifyTemplate("Knowledge_Pattern_Catalog|Cylinder_Normal_to_Surface",`Instantiated
    Geometry` ,`Relations\Knowledge Pattern.1\UDFs` ,i)

    udf > SetAttributeObject("Point.1",p)

    udf > SetAttributeObject("Surface.1",`Base Geometry\Surface.1` )

    EndModifyTemplate(udf)

    }
     
    While writing this code, you can select object from the specification tree or from dictionary of members to add it in the script.
    The script above can be explained as follows,
    • You first declare the three variables and set the value to the integer variable.

      Let udf (UserFeature)
      Let i (Integer)
      Let p (Point)
      i=1
      For i while i <= NbInstances 
    • One of the attribute required by the UDF is point, so the first step is to build an explicit point(p). Using the member CreateOrModifyDatum from Generative Function dictionary you can creates equally spaced points along the length of the line. 

      p= CreateOrModifyDatum("Point",`Instantiated Geometry` ,`Relations\Knowledge Pattern.1\Points` ,i)

      Inputs required,
      • Object Type - 'Point'
      • Location in Specification tree - 'Instantiated Geometry' Geometrical Set
      • Knowledge Pattern List that should track point geometry - 'Points' list
      • Index Number within the list - its derived by Number of Instances
    • Now explicit point exists but needs to be connected to existing geometry. using the member PointOnCurveRatio from Point Constructor dictionary following script will compute the distance ration between the instances.

      p=pointoncurveRatio(`Base Geometry\Line.1` ,`Base Geometry\Point.1` ,i/(NbInstances +1),False)

      Inputs Required,

      • Supporting Line - Base Geometry\line.1
      • Reference Geometry to which the ratio is computed - Base Geometry\Point.1
      • The ratio of distance on the curve, in this scenario it is calculated by an equation
      • The direction represented by Boolean
    • Now it sets the variable udf earlier defined as UserFeature. Using member CreateOrModifyTemplates from Generative Functions it refers to the catalog stored in Knowledge folder and instantiate the udf from the catalog.

      udf = CreateOrModifyTemplate("Knowledge_Pattern_Catalog|Cylinder_Normal_to_Surface",`Instantiated Geometry` ,`Relations\Knowledge Pattern.1\UDFs` ,i)

      Inputs required,
      • Location in Specification tree where instance to be created - 'Instantiated Geometry' Geometrical Set
      • Knowledge Pattern List that should track udf - 'UDFs' list
      • Index Number within the list - its derived by Number of Instances
    • This lines maps the udf object to the input in which UDF is instantiated.

      udf > SetAttributeObject("Point.1",p)
      udf > SetAttributeObject("Surface.1",`Base Geometry\Surface.1` )

      Inputs Required,

      • Object in UDF - Point.1, Surface.1
      • Object in which UDF is instantiated - P, Surface.1
    • The last line ends the instantiation process of our variable.

      EndModifyTemplate(udf)
  4. In the specification tree, click the NbInstances parameter. Use the spin box to indicate the number of instances you want to instantiate (3 in this scenario.)

  5. Click Execute now. The 3 cylinders are instantiated. Click OK to close the Knowledge Pattern window.

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

  7. Use the spin box to set the number of instances to 5 and click OK. 2 instances are added. Click here to open the Part containing the Knowledge Pattern.