Parametric Part Script Editing
Available in TurboCAD Pro and Platinum only
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:
<Identifier>
and
<Expression>;
Identifiers
The <Identifier> 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:
<Function name> (<list of parameters>),
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 <Expression> must be defined. In other words it must have been used as:
<Identifier> = <Expression>;
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:
<Identifier> = <Expression>;
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 <Identifier> 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 <Identifier>.
For each object used in an <Expression> there should be one, and only one, instance of any <Identifier>.
Each identifier should be used only once as <Identifier>
Each identifier should be at least once in an <Expression> 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 = H*1.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:
<id> = Parameter(<name>, <default value>, <type>[, <condition1>][, <condition2>]..);
NOTE: The '<>' markers are used to designate elements in the expression, and the '[ ]' markers are used to indicate elements which are optional.
<name> | The name displayed in the user interface; |
<default value> | The default value of the parameter; |
<type> | Defines the parameter type. The following example values are possible: |
<condition> | These are optional. They define possible restrictions imposed on parameters. Restrictions can be listed in arbitrary order and may take on the following forms: |
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(<radius>[, <cx>, <cy>]);
<radius> | Defines the circle's radius |
<cx>, <cy> | 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(<width>, <height>[, <cx>, <cy>]);
<width> | Defines the rectangle width |
<height> | Defines the rectangle height |
<cx>, <cy> | 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(<list of arguments>);
<list of arguments> | 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 <list of arguments> consists of only 2D points, defined using Point(x,y) function.
Format:
Point(<cx>,<cy>)
<cx> | Defines the x coordinates of the point |
<cy> | 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(<cx>,<cy>),
Arc1(<cx>,<cy>),
<cx> | Defines the x coordinates of the arc center |
<cy> | 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 <list of arguments> 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(<radius>);
<radius> | 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(<Object>, <value>);
<Object> | Defines the initial graphic object |
<value> | Defines new value of Thickness |
Example of Thickness:
RectA = Rectangle(2, 5);
RectThick = Thickness(RectA, 3);
Example of Thickness Used to Create a Box Function:
Input(x0,y0,z0,x1,y1,z1)
R = Rectangle(x1-x0, y1-y0, (x0+x1)/2, (y0+y1)/2);
T = Thickness(R, z1-z0);
Output(Move(T, 0, 0, z0));
Another Example of Thickness:
//thickrect.ppm – draws a 2D rectangle and adds thickness
L = Parameter("Length", 4, LINEAR, Interval(0.1, 20));
W = Parameter("Width", 3, LINEAR, Interval(0.1, 20));
H = Parameter("Height", 1.5, LINEAR, Interval(0.1, 20));
Rect = Rectangle(L, W);
Box = Thickness(Rect, H);
Output(Box);
An Example of Thickness with a Circle:
// thickcircle.ppm – draws a circle and adds thickness
Cylind=Thickness(Circle(1,2,2),2);
Output(Cylind);
An Example of Changing Thickness:
// thickcircle2.ppm – draws a cylinder and changes thickness
Cylind=Thickness(Circle(1,2,2),2);
Cyl2 = Thickness(Cylind, 4); // changes the thickness of the first cylinder
Output(Cyl2);
Sweep
The Sweep function creates a 3D object by extruding a specified profile along a path, defined by a 2D polyline or circle. The profile is defined by a closed 2D polyline or circle.
Format:
Sweep(<profile>, <path>[,<rotation angle>]);
<profile> | This defines the profile using a 2D polyline |
<path> | This defines the path, along which the profile is "dragged"; the path is defined by a 2D polyline |
<rotation angle> | This optional argument, defines the rotation angle of the profile relative the Z axis; by default, the argument is equal to zero |
Example of Sweep:
Poly1 = Polyline(
Point(0,0),
Point(1, 0),
Point(1,2),
Point(0, 2),
Point(0,0) );
PolyProfile = RotateX(Poly1, 90); // the Rotate function will be explained later
PolyPath = Polyline(
Point(0,0),
Point(10, 0),
Point(10,10),
Point(0, 10),
Point(0,0) );
PolySweep = Sweep(PolyProfile, PolyPath);
Output(PolySweep);
Another Example of Sweep
//sweep1.ppm
R = 2;
D = 5;
C1 = RotateX(Circle(R, D/2+R, 0),90); // profile
C2 = Circle(D/2, 0, 0); // path
Torus = Sweep(C1,C2);
Output(C1, C2, Torus); //C1 and C2 shown for reference
An Extended Example of Sweep
//sweep2.ppm – another sweep example
L = Parameter("Length", 5, LINEAR, Interval(0.005, 1000));
W = Parameter("Width", 3, LINEAR, Interval(0.005, 1000));
H = Parameter("Height", 1, LINEAR, Interval(0.1, 3));
FR = Parameter("Fillet Radius", 0.3, LINEAR, Interval(0.001,100));
p = Polyline(Point(0,0), Point(0,H), Point(-FR,H), Point(-FR,0), Point(0,0));
p1a = RotateX(p,90,0,0);
p1 = Move(p1a, 0, W/2, 0);
p2 = Polyline( Point(0,0), Point(0,W), Fillet(FR), Point(L,W), Fillet(FR), Point(L,0), Fillet(FR), Point(0,0), Fillet(FR));
s = Sweep(p1, p2); Output(s);
Functions for Creating 3D Entities Directly
3D object may also be created directly without reference to a 2D entity.
Sphere
The Sphere function is used to create a 3D sphere.
Format:
Sphere(<radius>[,<cx1>,<cy1>,<cz1>]);
<radius> | This value specifies the radius of the sphere |
<cx1>,<cy1>,<cz1> | These are optional argument used to specify the x, y, z location of the sphere's center point. By default the values for these argument is zero |