Creating a Patch (Rectangle)

Create a rectangle by searching and navigating the documentation.

  1. Search1 for rectangle in the integrated help.
    The results returned in response to the rectangle query includes Rectangle (object).
  2. Double-click Rectangle (object).
    View the code snippet (example) on how to create a rectangle.
    app = cf.GetApplication()
    project = app:NewProject()
    
     -- Create a rectangle with its base corner at the specified 'Point'
    
    corner = cf.Point(-0.25, -0.25, 0)
    rectangle = project.Geometry:AddRectangle(corner, 0.5, 0.5)
  3. View the Rectangle (object).
    Note: Since there can be multiple rectangles in the model, the rectangle object is part of a collection.


    Figure 1. A snippet of the Rectangle object which shows the Parent collection list.
  4. Click the GeometryCollection hyperlink to navigate to the GeometryCollection description.


    Figure 2. A snippet of the GeometryCollection which shows the Usage locations (collections).

Under GeometryCollection you will find Method list. The list shows the syntax for creating geometry primitives, including a rectangle.



Figure 3. A snippet of the GeometryCollection which shows the first method (of many) in the Method list.

  1. View the method list and click :AddRectangle(cornerpoint, width, depth) hyperlink to navigate to a short description for each parameter.


    Figure 4. A short description for the :AddRectangle method and its parameters.

The parameters width and depth are both of type, Expression and cornerpoint is a Coordinate type.

  1. Click the Coordinate hyperlink to obtain more information regarding coordinates.


    Figure 5. A short description for the parameter, Coordinate.
  2. Click Point and navigate to the Point description.
    View the code snippet (example) on how to create a point.
        -- Create a default 'Point' at (0,0,0)
        
    p1 = cf.Point.New() 
    
        -- Assign values to each component of the point
    
    p1.x = 1
    p1.y = 1
    p1.z = 1
    
        -- Create a 'Point' with number values
        
    p2 = cf.Point(2,2,2) 

You can find the Property list on the same help page that shows the properties of .X, .Y and .Z are numbers.

  1. Create the corner point using the following syntax:
    corner1 = cf.Point(-0.25, -0.25, 0)

You still need the syntax to prepend to the :AddRectangle method.

Note: The :AddRectangle method resides under the Geometry (object) and Project is the highest level (the .cfx file).

  1. Create the rectangle using the following syntax:
    my_rectangle = my_project.Geometry:AddRectangle(corner1, 0.5, 0.5)
    Tip: The my_Rectangle part of the syntax is the handle or reference in Lua to your newly created geometry part.

    If you create the rectangle manually in the graphical user interface (GUI), you will see that Rectangle1 will appear in the construct tree.

  2. Run the script created up to this point to view the progress in the GUI.


    Figure 6. The result in the CADFEKO after running the script.
    Tip: You can change the handle to Rectangle1, but in the automation script, Rectangle1 refers to the label of the rectangle object.

    For this example, in order to emphasize the difference between the handle and label of an object, handle names are created with the “my_” prepending syntax.

1 Use “Look for” on the Index tab