2017/10/01

Polygon UDF



The goal is to create an UDF to generate polygons. The inputs are point (center point), plane and a line (which controls orientation). The UDF allows user to change number of sides, radius of reference circle and to switch between inscribed and circumscribed polygon.

Follow these steps to create a Polygon UDF.
1. Create a new .CATPart, name it Polygon UDF, create two geometrical sets - Inputs and Polygon.
2. In Inputs geometrical set create isolated point, plane and line.
3. Create three parametres - Number of sides (type - Integer), Circle radius (type - Length), Switch (type - Integer). Drag and drop these parameters into Polygon GeoSet - Fig.1.
Fig.1

4. Add range to the Number of sides parameter. Click RMB on it, go to ...object > Definition, in new window Edit Parameter click RMB on the value box and select Add Range..., assign minimum value - 3, maximum value for the number of sides can be also assigned - Fig.2.
Fig.2
5. Add Range also to the Circle radius parameter. Minimum value is 0mm, but 0 is not included.
6. Add Multiple Values to the Switch parameter, multiple values are -1 and 1 - Fig.3. To add multiple values click RMB on the parameter, go to ...object > Definition, in new window Edit Parameter click RMB on the value box and select Add Multiple Values.
Fig.3
7. Start creating geometry in the Polygon GeoSet. Project the reference point (Point.1) on reference plane (Plane.1), name it REF PT.
8. Use it as a center point to create a circle, use Plane 1 as a support, use the parameter Circle radius as a radius value - Fig.4. Name the circle REF CIRCLE.
Fig.4
9. Create a line, type Angle/Normal to curve, select Line.1 from the Inputs as a Curve, Plane.1 as a Support and REF PT from the Polygon GeoSet as a Point. Make Angle value 0deg and Start 0mm, in Length Type select Infinite End Point - Fig.5. Name the line DIRECTION.
Fig.5
10. Create an intersection between REF CIRCLE and DIRECTION, name it INS PT 1.
11.  Create a point on curve, name it INS PT 2. Curve is REF CIRCLE and Reference Point is INS PT 1, as a Distance to reference set Ratio of curve length, use following formula as Ratio (more details on Fig.6):

1/`Polygon\Number of sides`

Fig.6
12. Create a line between INS PT 1 and INS PT 2, name it INS SIDE.
13. Create a middle point on INS SIDE, name it MID PT.
14. Create a line on Plane.1 which is perpendicular to the INS SIDE, goes through MID PT and is infinite. Name it LINE NORMAL (Fig.7)
Fig.7
15. Between LINE NORMAL and REF CIRCLE create an intersection. It is a multiple element, extract the near element, Reference Element is MID PT. Name it CIRCUM REF PT. See more details on Fig.8.
Fig.8
16. Create an infinite line, Point-Direction type, Point is REF PT and Direction is Plane.1, name it ROTATION AXIS.
17. Use the ROTATION AXIS as a reference for the complete crown circular pattern. Object to Pattern is the INS SIDE line, number of the instances is the Number of sides parameter - Fig.9. Name it INS PATT.
Fig.9

18. Join the INS SIDE and INS PATT, name the join POL INS.
19. Use the POL INS to create a parallel curve. Plane.1 is the support, use the CIRCUM REF PT as a reference point, make sure that corners type is sharp (Fig.10). Name the feature POL CIRCUM.
Fig.10
20. Create a point on curve, use INS PT 1 and DIRECTION as references, name it NEAR PT and use following formula as Length:

`Polygon\Switch` * `Polygon\Circle radius`

21. Join POL INS and POL CIRCUM, make sure that the Check connexity option is turned off - Fig.11. Name it POL JOIN.
Fig.11
22. Create a Near feature, use POL JOIN as a Multiple Element and NEAR PT as a Reference Element. Name it POLYGON.
23. Drag and drop all the formulas to the Polygon GeoSet (Fig.12), hide all geometry except REF CIRCLE and POLYGON.
Fig.12
 24. Check if all parameters work correctly. It should be possible to use only integers >= 3 as the Number of sides and length >0mm as the Circle radius, changing Switch between 1 and -1 should switch the POLYGON feature between inscribed and circumscribed polygon - Fig.13.
Fig.13
25. To create an UDF go to Insert ® Knowledge Templates ® User Feature...
26. In Userfeature Definition window (Fig.14) enter a name and select Polygon Geometrical Set. Polygon should appear in Selected components and all three inputs (not more) should appear in Inputs of components.
Fig.14
27. Go to the tab Parameters and publish the parameters (Number of sides, Circle radius, Switch). Optionally you can go to tab Properties to a chose new icon.
28. Go to Outputs tab and set POLYGON (Near Feature created in step #22) as a Main result and optionally REF CIRCLE as a second output - Fig.15. Click on OK.
Fig.15
29. Save the file and close it. The UDF can be used now.

Related posts: