# Parametric Part Script Editing

(Available in Platinum)

Default UI Menu: Tools/Palettes/Parametric Part Script Editor

Parametric parts (PPM) are defined using a text description (script). The script defines the structure, editable properties, and output that result in a parametrically editable part. The script must be saved with a *.PPM extension. The name of the file determines the name of the part.

Examining a Script

A simple example of a parametric part is a rectangle where the width, height and rotation angle are defined though parameters. The script of such part might look as follows: // Here is a description of simple rectangle. H = Parameter("Height", 5, LINEAR, Interval(0, 100)); L = Parameter("Length", 10, LINEAR, Interval(0, 200)); Angle = Parameter("Angle", 0, ANGULAR, Interval(0, 360)); Rect1 = Rectangle(H, L); Rect = RotateZ(Rect1, Angle); Output(Rect); Let's examine each line of this example: LINE 1 // Here is a description of simple rectangle. The '//' indicates a comment. Comments do not affect the behavior of a part. All text following '//' to the end of the line are contained by the comment. LINE 2 H = Parameter("Height", 5, LINEAR, Interval(0, 100)); The second line specifies the definition of the 'H' parameter. Let's break out each element of the line to define its function: H This is the identifier (name) of the parameter in the part description = The equals sign associates the identifier with its definition Parameter This is a function. 'Parameter' defines that H is a Parameter ( Specifies the start of the Parameter function's properties "Height" The name of the parameter that will appear in the Properties dialog , Indicates the end of one property and the beginning of the next 5 Assigns the default value for H , Separates properties LINEAR Specifies that H is a linear value , Separates properties Interval(0, 100) Specifies the allowable values for H as an interval from 0 to 100 ) Specifies the end of the Parameter function's properties ; End of definition for H LINES 3 – 4 L = Parameter("Length", 10, LINEAR, Interval(0, 200)); Angle = Parameter("Angle", 0, ANGULAR, Interval(0, 360)); The next two lines in the example are similar to the previous one. They define the characteristics of L and Angle parameters in a similar layout. Note that the 'Angle' parameter uses an ANGULAR interval rather than LINEAR. LINE 5 Rect1 = Rectangle(H, L); This line uses the Rectangle function to define a rectangle called 'Rect1'. It uses the previously defined H and L parameters to specify its properties, height and length. The center of this rectangle will be at the world origin (x=0,y=0,z=0) in the drawing. More on the rectangle tool will be covered later. LINE 6 Rect = RotateZ(Rect1, Angle); This line defines a new rectangle called 'Rect' which is a rotated version of 'Rect1', using the Angle parameter to define the rotation. LINE 7 Output(Rect); The last line specifies that the output of the script will be the rotated rectangle called 'Rect'. This is what the be drawn as the part.

Script syntax

The description of a parametric part consists of the entire contents of a text file, except comments, tabs, and other control characters, which are ignored. Comments are specified either using "//" characters that mean that all subsequent characters up to the end of the line are comments, or using the pair "/" and "/" that denote beginning and end of thecomment, respectively. A text description is a set of two types of operators: and ;

Identifiers

The defines the symbolic name of an object. It is a set of Roman letters and Arabic numerals, which must start with a letter. For example valid names would be: PART2a MyPart A134 Object identifiers may not be the same as names of functions or such names as PI, or LINEAR. These are reserved words that are used to designate the constants of the scripting language. The list of all reserved names is provided in the reserved word list which appears at the end of this chapter.

Expressions

Expressions define the associated identifier. Expression syntax matches the expression syntax in the majority of programming languages. They may define numeric value, arithmetic operations, the dependence of the defined object on other objects and function calls. The structure of a function call is: (), Examples of correct expression syntax: (D --1/4) * k; Polyline(Point(0, 0.25 - 1/8), Point(0, D), Arc1(L-C, - m, m), Point(0,0)); A = B + 0.5; B = 7;

Arithmetic Operations

Arithmetic operations may use the standard arithmetical operators '+' (addition), '--'(subtraction), '*' (multiplication), '/' (Division) and parenthesis '('and ')', to determine the sequence of performing arithmetic operations. Object identifiers and numbers serve as operands.

Script Semantics

A script contains full description of a parametric part. The collection of script operators determines which actions need to be performed to create the resultant object(s). Correct understanding of a script, requires having a clear understanding of how its operators are interpreted. Identifiers that are used in a must be defined. In other words it must have been used as: = ; The list of resultant objects is defined in the Output(..) operator. The Output(..) operator contains a list of which objects are to be displayed in the resulting part. This operator must be present in the script. Each object in the list of arguments for Output(..) must be defined. In other words it must have been used as: = ; This operator must be present in the script. At least one object must be listed in the Output operator, but you need not output every object used in the script. The Output operator determines the method that will be used to create an object with this name. A correct script describing a parametric part should conform to the following rules:

• A script may have more than one Output(..) operator, but any should contained in only one Output(..) operator_._
• For each object used in the Output(..) operator there should be one, and only one, instance of any .
• For each object used in an there should be one, and only one, instance of any .
• Each identifier should be used only once as
• Each identifier should be at least once in an operator or in an Output(..)operator_._
• Circular calculation and interdependent referencing are not allowed. The script must not contain interdependent where "Item One" is defined by "Item Two", and "Item Two" is defined by "Item One".

The following situations: A = B + 0.5; B = sin(A); or A = C+5; B = D+42; C = (3(2+A)); D = A/2; are not allowed. The first case A and B define each other directly. In the second case A is defined by B through C, and B is defined by A through D. This also means that an identifier is not allowed to depend on itself. For example, you cannot use an operator of this form: H = H1.05; NOTE: The sequence of script operators is not important (except certain special cases that will be described later); because operators are sorted before the script is run.

Basic Functions

Probably the most significant advantage of this method of creating parametric parts is the compact size and clarity of the text description of parametric parts in script form. The set of basic functions used in such a description, determines the level of clarity and simplicity of scripts for a particular class of parametric parts. Note: It is intended that the set of basic functions will expand from version to version.

Description of Parameters

It is important to understand the structure used to within a Parameter function. Format: = Parameter(, , [, ][, ]..); NOTE: The '<>' markers are used to designate elements in the expression, and the '[ ]' markers are used to indicate elements which are optional.

The name displayed in the user interface;
The default value of the parameter;
Defines the parameter type. The following example values are possible: LINEAR, means that the parameter is a linear value in the selected linear units of measure. ANGULAR, means that the parameter is an angular value in the selected angular units of measure. (only degrees are available at this time) TEXT, a text string; FONT, a font name; COLOR, an RGB color value; MATERIAL, a material name; CHECKBOX, a logical value, either ON or Off
These are optional. They define possible restrictions imposed on parameters. Restrictions can be listed in arbitrary order and may take on the following forms: Set(,...) — a list of permissible values of the parameter Interval(, ) — sets the minimum and maximum values of the parameter; LessThan() — indicates that parameter value should be less than the specified value LessOrEqual() — indicates that parameter value should not be greater than the specified value GreaterThan() — indicates that parameter value should be greater than the specified value GreaterOrEqual() — indicates that parameter value should not be smaller than the specified value Set(FolderList) --- particular case of Set operator, when a list of permissible values are defined by operator FolderList. Restrictions should not contradict each other. For example, you cannot combine GreaterThan(5) with LessThan(2). When specifying parameter restrictions, it is not allowed to use identifiers or expressions that directly or indirectly depend on other parameters, as arguments of the above-mentioned functions. Only constants or constant expressions can be used, for example: LessOrEqual(PI/2).

Example of Parameter Description: Alpha = Parameter("Rotation Angle", 45, ANGULAR, Interval(-90, 90)); // This creates a parameter used to define a rotation angle. The name is 'Rotation Angle', the default is 45, the value type is ANGULAR, and the Interval is from '-90' to '90'

Functions for Creating 2D Entities

The following functions are used to create 2D graphic entities

Circle

The Circle function is used to create circles Format: Circle([, , ]);

, Defines optional arguments that set the (x, y) coordinates of the circle center. By default, cx = 0, cy = 0

Example: N = Circle(D/2, 0, y0); A more extensive example: //circle.ppm – two circles r1 = Parameter("Radius1", 2.5, LINEAR, Interval(0.0, 10.0)); r2 = Parameter("Radius2", 1.25, LINEAR, Interval(0.0, 10.0)); xc = Parameter("CenterX", 3, LINEAR, Interval(-100, 100)); yc = Parameter("CenterY", 3, LINEAR, Interval(-100, 100)); c1 = Circle(r1); // circle centered on the origin c2 = Circle(r2, xc, yc); // circle offset from the origin Output(c1, c2);

Rectangle

The Rectangle function is used to create rectangles. Format: Rectangle(, [, , ]);

Defines the rectangle width
Defines the rectangle height
, Defines optional arguments that set the (x, y) coordinates of the rectangle center. By default, cx = 0, cy = 0

Example: rect = Rectangle(W, H, W/2. H/2); // Left bottom corner is in (0,0) point

Polyline

The Polyline function is used to create polylines consisting of straight line segments and arc segments. Format: Polyline();

Defines the list of arguments, delimited with commas. Arguments define individual segments of a polyline

A line segment is defined by 2 Points. An arc segment is defined with a Fillet function or with an Arc0 or Arc1 function and two Points on the ends of the arc. For polylines that contain only straight line segments, the consists of only 2D points, defined using Point(x,y) function. Format: Point(,)

Defines the x coordinates of the point
Defines the y coordinates of the point

For example, a rectangle can be defined in the following way: rect = Polyline( // no end-of-line is used semicolon here Point(0,0), // since this function in on multiple lines Point(W, 0), Point(W,H), Point(0, H), Point(0,0) ); It should be noted that when a polyline's, first and last points are coincident, is called a closed polyline. This type of polyline bounds a certain area, and can be used for creating 3D objects. Polylines with arc segments are defined by adding auxiliary functions Arc0 and Arc1 to the list of arguments. Arc0 builds the circular arc clockwise, while Arc1 builds the circular arc counterclockwise. Format: Arc0(,), Arc1(,),

Defines the x coordinates of the arc center
Defines the y coordinates of the arc center

The start and end point of an arc are defined by the preceding and the following arguments. Arc0 and Arc1 cannot be the first or last argument in the list of arguments. For a polyline that contains only one arc segment, the consists of 2 Points defined with Point(x,y) function and an arc defined with either the Arc0 or Arc1 function. Example of arc0 and arc1 in a polyline: //Polyarc.ppm – polyline with arcs YSize=5; XSize=6; R = 1; Path = Polyline(Point(0, R), // start at top of rounded lower left corner. Point(0, YSize-R), // go to bottom of rounded top left corner. Arc1(0, YSize, R), // make this corner a "cutout" Point(R, YSize), // left side of top edge Point(XSize-R, YSize), Arc0(XSize-R, YSize-R, R), // make this corner a "fillet" Point(XSize, YSize-R), Point(XSize, R), Arc0(XSize-R, R, R), // another fillet Point(XSize-R, 0), Point(R, 0), Arc1(0, 0, R), // another cutout Point(0, R)); Output(Path); Another method of creating an arc in a polyline is to use the auxiliary function Fillet, which "smooths" two linear segments that start and end in the preceding point, by adding an arc with the specified radius into the corner. This ensures smoothness at the junction points. Format: Fillet();

Defines the radius of the fillet

Example of fillets in a polyline: // polyfillet.ppm – polyline with fillets H = 5; L = 10; FR = 1; p2 = Polyline(// Rectangle with rounded corners Point(0,0), // lower left corner Point(L,0), // lower right corner Fillet(FR), // places fillet at bottom right Point(L,H), // upper right corner Fillet(FR), // places fillet at top right Point(0,H), // upper left corner Fillet(FR), // places fillet at top left Point(0,0), // closes rectangle Fillet(FR) // fillets start/end corner. Since this is a closed shape, // no following Point function is needed. ); Output(p2); Fillet and Arcs can be used together in the same Polyline function. Example of Arcs and Fillet in a polyline: Poly1 = Polyline( // Rectangle with rounded corners Point(0,0), Point(W - r, 0), Arc1(W - r, r), Point(W, r), Point(W, H - r), Arc1(W - r, H - r), Point(W – r ,H), Point(0, H), Fillet(r), Point(0,0), Fillet(r) );

Functions for Creating 3D Entities from 2D Entities

You can use 2D entities as the basis for creating 3D objects.

Thickness

The Thickness function creates a 3D entity based on the 2D entity by adding thickness. It also allows you to change the thickness property of the 3D object. Format: Thickness(