Creating a Loop    

The task below illustrates how to interactively apply a loop to an existing document.
 
The KwrLoop1.CATPart is made up of a surface (2) and a solid (1) that symbolizes a hole. This hole is inserted into a User Feature (UDF) for a later instantiation. The User Feature (UDF) has 3 different inputs (a point, an axis and a surface). 2 parameters of the User Feature (UDF) are published (3).
  • Clearance=4mm
  • Diameter=8mm

 

   
The KwrLoop2.CATPart is made up of a surface (1) and of 12 points (3) inserted into a list. The Line.7 is the instantiation axis (2).

The aim of this scenario is to instantiate as many holes as existing points. It is divided into the following steps:

  • You create a loop.
  • You instantiate the User Feature (UDF) from the existing .CATPart file.
  • You valuate the required inputs to instantiate the holes.
To create a loop, you have to:
  1. Declare input data

  2. Define the context

  3. Specify iterators

  4. Write the body of the action script

Before creating a loop in a CATPart document, make sure that Manual input is unchecked in the Part Number field of the Tools>Options...>Infrastructure>Product Structure>Product Structure tab.
To perform this scenario, you will need the following files:
  1. Open the KwrLoop2.CATPart

  1. From the Start>Knowledgeware menu, access the Knowledge Advisor workbench.

  2. Click the Loop icon () in the Control Features bar. The Loop Edition window is displayed.

  3. In the specification tree, select the inputs of the loop.

    • Expand the Parameters node and select the List_Extract list. In the Input name field, enter the name of the list: PointsList.

    • Expand the Surface node and select the Revolute.1 feature. In the Input name field, enter the name of the list: SurfRef.

    • Expand the Result_Body node and select the Line.9 feature. In the Input name field, enter the name of the list: LineAxis.

    • Note that the name indicated in the Input name field is the one that will be used in the loop body.

  4. Select the context, that is to say, in this scenario, the feature that will contain the instantiated holes.

    • Click the Context field.

    • Click Result_PartBody in the specification tree.

  5. Indicate the number of holes that you want to instantiate into the surface.

    • In the From field, indicate 1.

    • Right-click the To... field and select Edit formula.... The Formula Editor is displayed.

    • In the specification tree, click ListSize=12. Click OK when done. The number of instantiated holes is now valuated by a formula based on the list, that is to say on the number of points contained in the list.

  6. Enter the following action script into the Editor.

    • Use the import keyword to indicate the path of the file containing the User Feature (UDF) to be instantiated. To indicate the path of the file, it is recommended to use Insert File Path available in the contextual menu to import KwrLoop1.CATPart. (1)

    • UDF_$i$ is the name that will be attributed to each instance of the hole. At each iteration, $i$ is replaced with the current iterator. (2)

    • Clearance_Hole_UDF is the name assigned to the User Feature (UDF) in the KwrLoop1.CATPart file. (2)

    • Position is a point and is also the first input that needs to be valuated when instantiating the holes. PointsList is the name of the List. (3)

    • Clearance_Surface is the second input required and defined when creating the User Feature (UDF) and SurfRef is the revolute into which the holes will be instantiated. (3)

    • Axis is the third input required and defined when creating the User Feature (UDF) and LineAxis is Line.9, that is to say the instantiation axis. (3)

    For more information about the syntax to be used (;, {}, $i$) in the loop body, see Using the Scripting Language.

  7. Click OK when done. The 12 holes are instantiated. (See picture below.)