Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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:

Code Block

// 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

Code Block

// Here is a description of simple rectangle.

...

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

Code Block

Rect = RotateZ(Rect1, Angle);

...

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:

...

Panel

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.

...

Format:
<id> = Parameter(<name>, <default value>, <type>[, <condition1>][, <condition2>]..);

Panel

NOTE: The '<>' markers are used to designate elements in the expression, and the '[ ]' markers are used to indicate elements which are optional.

...

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

...

<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.

...

//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.

...

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>);

...

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:

...

SR1 = Sphere(10,1,3,5.5);

Another Sphere example:

//sphere.ppm – simple sphere example
R = Parameter("Radius", 2.5, LINEAR, Interval(0.01, 20));
cx = Parameter("CenterX", 0, LINEAR, Interval(-100, 100));
cy = Parameter("CenterY", 0, LINEAR, Interval(-100, 100));
cz = Parameter("CenterZ", 0, LINEAR, Interval(-100, 100));
S = Sphere(R, cx, cy, cz);
Output(S);

...

PolyProfile = Move(Poly1, 1, 3);

Another Example:

//move.ppm – illustrates the Move function
RB = Parameter("BaseRadius", 2, LINEAR, Interval(0.1, 10));
RT = Parameter("TopRadius", 0.5, LINEAR, Interval(0, 10));
H = Parameter("Height", 4, LINEAR, Interval(0.1, 20));
con1 = Cone(H, RB, RT);
cx = Parameter("CenterX", 5, LINEAR, Interval(-10, 10));
cy = Parameter("CenterY", 0, LINEAR, Interval(-10, 10));
cz = Parameter("CenterZ", 0, LINEAR, Interval(-10, 10));
count = Parameter("Copies", 2, LINEAR, Interval(1, 10));
con2 = Move(con1, cx, cy, cz, count);// create count copies, offsetting each by cx, cy, cz
Output(con1, con2);

...

PolyProfile = RotateX(Poly1, 90);

Another Example of Rotate:

...

// staticsym2.ppm – loads an external symbol from a different folder than Macro
DrawingName = Parameter("Drawing", "Drawing1", Set(FolderList("..\..\..\Drawings", "*.tcw")));//quantity of "..\..\" (before folder Drawings) is equal to quantity
//of steps over folder tree starting from the Macro sub-folder.
S0 = StaticSymbol("..\..\..\Drawings\"DrawingName".tcw");
//here a static symbol is loaded from a file with a tcw-extension,
// and a filename picked from the FolderList obtained via the DrawingName parameter.
Output(S0);

When specifying a relative path, you must remember that the path is always assumed to start, not at the folder that contains the ppm file, but in a folder below that named "Macro". In the example above, assume for the moment that staticsym2.ppm is located in:

C:\Users\Me\Documents\MyCAD\PPM Documentation Samples

The path used in the FolderList path and the StaticSymbol path must then implicitly begin at

C:\Users\Me\Documents\MyCAD\PPM Documentation Samples\Macro

The external symbol is being loaded from:

C:\Users\Me\Documents\MyCAD\Drawings

That means the script must navigate up three directories to the MyCAD folder, then back down one level to the Drawings folder, so the correct relative path is:
..\..\..\Drawings

Another example, which loads a specific .tcw file from the Drawings folder:

//staticsym3.ppm – loads a specific file from a different folder
S = StaticSymbol("..\..\..\Drawings\3DSliceTest.tcw");
//only loads the specific file 3DSliceTEst.tcw.
//Remember that the relative path is still rooted in the Macro subfolder.
Output(S);

A parametric part (a file with a *.ppm extension) can loaded by calling the name of the parametric file as if it were a function, whose arguments are the parameters of the part to be loaded, in the order in which they are described in the file. Refer to "Creating Custom Functions" below for more details on this process.

...

S1 = Sphere(5);
S2 = Sphere(5,5,5);
S3 = Sphere(5,5,-5);
S4 = Sphere(5,-5,5);
S5 = Sphere(5,-5,-5);
S6 = BooleanUnion(S1,S2,S3,S4,S5);
Output(S6);

Another Example:

R = Parameter("Radius", 8, LINEAR, Interval(0.001, 1000));
s = Sphere(R);
c = Circle(R/3);
c1 = Thickness(c, R*2);
c2 = Move(c1, 0, 0, R); //Cylinder
s1 = BooleanUnion(s, c2); //Sphere with cylinder
Output(s1);

...

Format:
BooleanSubtract(<PrimaryObject>, <SecondaryObject>, ...);

<PrimaryObject>

Defines an object to be used in the Boolean operation. There is only one primary object

<SecondaryObject>

Defines a secondary object to be subtracted from the primary object There must be at least one or more secondary objects

...

S1 = Sphere(5);
S2 = Sphere(5,5,5);
S3 = Sphere(5,5,-5);
S4 = Sphere(5,-5,5);
S5 = Sphere(5,-5,-5);
S6 = BooleanSubtract(S1,S2,S3,S4,S5);
Output(S6);

Another Example of BooleanSubtract:

...

Format:
BooleanIntersect(<Object>, <Object>)

<Object>

Defines an object to be used in the Boolean operation. There must only two objects

...

Array(Point(x1,y1,z1), Point(x2,y2,z2), Point(x3,y3,z3)); //defines 3 edges for filleting
//Point(x1,y1,z1), Point(x2,y2,z2), Point(x3,y3,z3); – 3 middle points on 3 edges to be filleted

Another Example:

Array(r1, r2)-- //array of radius values for rounding the selected edge. It defines rounding //radiuses for 2 ends of the selected edge.
//r1 – start radius of fillet
//r2 – end radius of fillet.

Example of Filleting 1 Edge:

G3Fillet(PartA,Point(xc,yc,zc), Array(r1, r2)); //where Point(xc,yc,zc) - middle of the edge.

Another Example:

Door= G3Fillet(Door0, Point(0, -1, (Height-FHeight-4-3/4)/2), Array(1, 1));
For example (fillet of 1 edge of the box):
x = Parameter("size", 5, LINEAR, GreaterThan(0));
r1 = Parameter("r1", 1, LINEAR, GreaterThan(0));
b0 = Box(0, 0, 0, x, x, x);
b1 = G3Fillet(b0, Point(x/2, 0, 0), Array(r1, r1*2));
Output(b1);

Example of Filleting 4 Edges of a Box:

...

Format:
G3Chamfer(<Object>, <Edges>, <Offsets>);

<Object>

Defines the 3D object whose edges are to be chamfered

<Edges>

Defines the edge or multiple edges, which are to be filleted. Each edge is defined by Point(xc,yc,zc) or Array of Points.
Point(xc,yc,zc) is the middle point of an edge to be filleted (for example in the TurboCAD "ChamferEdges" operation, this point is marked with a blue square). Array of Points defines a set of edges to be chamfered.

<Radiuses>

Defines the Chamfer distances. These are set by Array function. For a single edge the Array contains a pair of distance values, for multiple edges - multiple pairs of distance values.

...

Array(d1, d2)-- //array of 2 offset values at the ends of an edge.

Another Example:

Door= G3Chamfer(Door0, Point(0, -1, (Height-FHeight-4-3/4)/2), Array(1, 1));
//Here Door0 -is the object whose edge is to be chamfered.
//Point(0, -1, (Height-FHeight-4-3/4)/2) – indicates this edge.
//Array(1, 1) sets 2 chamfer distances

Another Example:

x = Parameter("size", 5, LINEAR, GreaterThan(0));
r1 = Parameter("r1", 1, LINEAR, GreaterThan(0));
b0 = Box(0, 0, 0, x, x, x);
b2 = G3Chamfer(b0, Point(x/2, x, x), Array(r1, r1+r1));
Output(b2);

...

G3Offset(PartA, Point(xf, yf, zf), dist);
Where:
PartA — is the 3D object whose faces are to be offset
Point(xf, yf, zf) — is a point for selecting the face to be offset
dist — is the value of face offset

Another Example:

x = Parameter("size", 5, LINEAR, GreaterThan(0));
r1 = Parameter("r1", 1, LINEAR, GreaterThan(0));
b0 = Box(0, 0, 0, x, x, x);
b3 = G3Offset(b0, Point(x,x/2,x/2), r1/2);
Output(b3);

...

<Object>

Defines the 3D object whose edges are to be shelled

<Face>

Defines the face that should remain open. It is defined by the Point(xc,yc,zc) function which describes a point belonging to this face

<Thickness>

Defines the shell thickness. A positive value creates an outward shell, and a negative value creates an inward shell

...

G3Shell(PartA, Point(xf, yf, zf), thickn);
Where:
Part3 — selects the object which is to be shelled
Point(xf, yf, zf) — is the point on the face, which should remain open
thickn — is the shell thickness

Another Example:

L = Parameter("Length", 5, LINEAR);
W = Parameter("Width", 3, LINEAR);
H = Parameter("Height", 1, LINEAR);
T = Parameter("Thickness", 0.2, LINEAR);
g0 = Box(0,0,0,L,W,H);
g1 = G3Shell(g0, Point(L/2, W/2, H), T);
Output(g1);
//After inserting a shelled object in the drawing, shell thickness can be edited in the Selection Info palette (as well as Length, Width and Height parameters)

...

G3Bend(Part3, Point(x1, y1, z1), Point(x2, y2, z2), Angle, R, 0);

Another Example:

P1=Thickness(Rectangle(10,20),3);
B0 = G3Bend(P1, Point(3, 3, 0),
Point(3,8,0), 90, 2, 0);
Output(B0);

...

Format:
SetProperties(<Object>, <PropertyName> = PropertyValue, <PropertyName> = PropertyValue, ...);

<Object>

Defines the object to be used as the base for the new object with set properties

<PropertyName>

Defines the name of the property to be set. The name should be surrounded with quotation marks

<PropertyValue>

Defines the value to be assigned to the property


Example of SetProperties:

BlueRect=Rectangle(10,5);
RedRect = SetProperties(BlueRect, "PenColor" = 0xff, "PenWidth" = 0.2);
Output(RedRect);

Another Example:

Side2M = SetProperties(Side2, "Material" = "Wood\Pine", "PenColor" = 0xff);

Another Example:

PL1 = SetProperties(PL0, "Brush" = "SOLID");

Another Example:
SetPlastic = ("Material" = "Plastics\Plain white");
BoxMaterial = SetProperties(MyBox,SetPlastic);

In the Parametric Part manager there is a special tool to choose the required value for such properties as Material, Pen Color and Brush Style. To activate it, right-click on the property name. This will open the Local Menu either for Material table or PenColor table or BrushStyle table. The appropriate table will appear where the desired value can be chosen.

...

Functions can be nested within a single expression to optimize scripting efficiency.

For Example:
BF = BooleanSubtract(B1,Move(RotateZ(RotateY(Box(-5,-5,-5,5,5,5),45),45),-1,-1,-1));

Example Used in a Small Script:

...

<Text object>

Defines the text string. Text string can be specified either directly here (with quotation marks) or via an identifier of text object

<Text Font>

Defines the text font

<Text Style>

Defines the text style


Example:

bsb = Text("BS(b)", Tfont, Tstyle);

...

<mode>

Defines the mode of the text: Standard (when mode=0) or Scalable (when mode=1 or any other value different from 0)

<Height>

Defines the text font size

<Angle>

Defines the angle of text line

<font>

Defines the text font


Example:

Tfont = TextFont(0,2, 45, "Arial");

Where:
0 — means that text is Standard
2 — text height
45 — text line is located at 45 degrees
Arial — font

...

Tstyle = TextStyle(LEFT, TOP, UNDERLINE);

Another Example:

//Standard text of Times New Roman font with 5in of font size,
//with Left,Top justification, with TextBox effect, Bold, Italic, at 45 degrees of Angle
ht=5;
font_name = "Times New Roman";
Tfont = TextFont(0, ht, 45, font_name);
Tstyle = TextStyle(LEFT, TOP, BOX,BOLD, ITALIC);
bsb = Text("BS(b)", Tfont, Tstyle);
Output(bsb);

...


The presence of X, Y or Z characters in the function name determines axis along which the extents will be calculated.
1 or 2 index--indicates whether minimum or maximum value should be calculated.

Example of Extents:

xmin = ExtentsX1(PartA);
xmax = ExtentsX2(PartA);
ymin = ExtentsY1(PartA);
ymax = ExtentsY2(PartA);
zmin = ExtentsZ1(PartA);
zmax = ExtentsZ2(PartA);
P1 = Box(xmin, ymin, zmin, xmax, ymax, zmax);

Another Example of Extents:

...

<N>

Defines the number of the parametric point

<xc>,<yc>,<zc>

Defines the coordinates of parametric point


Example of ParameterPoint:

...

<Condition>

Defines the condition under test using the following comparison operations:
== (equal)
< (less than)
> (greater than)
<= (not greater than)
>= (not less than)

<ExprOnTRUE>

Defines the value of the IF function when the value of <Condition> is TRUE;

<ExprOnFALSE>

Defines the value of the IF function when the value of <Condition> is FALSE;


IF Example:

A = IF(L >= H, Rectangle(L, H), Rectangle(H, L));
//Regardless of the specified size of L and H, the created rectangle A will be positioned //horizontally (the longer side will be along the X axis).
/* In this example "Rectangle(L, H)" is the TRUE result and "Rectangle(H, L" is the FALSE result. */

Another Example:

Tstyle = IF(dir > 0, TextStyle(MIDDLE, RIGHT), TextStyle(MIDDLE, LEFT));
//Regardless of the specified size of dir, Text Style will be specified with Right or Left justification.

...

<N>

Defines object scale

<units of dimension>

Defines the units in the English or Metric systems

Units (1[in]) — this means that the main units of measurement are inches. It is possible to use other units for some particular values even when the entire drawing is created with the default unit. In order to use millimeters for particular values while inches are default units, you can explicity declare the desired unit for these values.

...

Units(1[in]);// means that default unit of drawing is inches
Units(1[mm]);// means that default unit of drawing is millimeters

For example, you can use value M=5[mm]; and Units(1[in]) in the same script. It means that only M value is measured in mm while all others are measured in inches.
Moreover, this function allows for scaling the created objects down (when N<1) or up (when N>1).

For Example:

Units(2[in]);//created object is scaled up 2 times compared with the case of Units(1[in]);
_Units(0.5[in]);// created object is scaled ½ as large as compared with the case of Units(1[in]);_

...

Format:
Input(<list of variable identifiers, separated with commas>);
Output(<list of variable identifiers, separated with commas>);

<list of variable identifiers, separated with commas>

Defines the list of variables or objects for input or a list of results for output


For Example:

Input(H, W, D, A, Dis);
Output(SideA_L,Bottom_B,Back_I, Face1, FalseD1, E1,E2,E3,E4, N1, T1, Door, FF,
SideA_R);

Example of the Output with Conditional Output:

...

<set of values>

Defines the set of numerical values, identifiers of variables or Array of variables


For Example:

r=min(2,5,1,7,9);//r=1
R=max(2,5,1,7,9);//R=9

For Example:

A=2; B=5; C=1; D=7; E=9;
A1=2; B1=5; C1=1; D1=7; E1=9;
r=min(A,B,C,D,E);//r=1
R=max(A1,B1,C1,D1,E1);//R=9

Example of using Array of Values:

A=2; B=5; C=1; D=7; E=9;
r=min(Array(A,B,C,D,E));//r=1

...

Note:

...

A Group of objects cannot be used as argument of these functions, because a Group is a collection of graphic objects, rather than a collection of numbers.

...

Mod

The Mod function is used for finding the remainder of the integer division. For example, Mod(5,4) is 1, because 5/4 = 1, with a remainder of 1. Mod(7,4) is 3, because 7/4 = 1, with a remainder of 3. Mod(7,3) = 1, because 7/3 = 2, remainder 1.
Note: The Mod function is often used to determine if a number is odd or even, because Mod(AnyOddNumber, 2) = 1, while Mod(AnyEvenNumber, 2) = 0.

...

<value1 >

Defines the expression or identifier that represents the dividend

<value2>

Defines the expression or identifier that represents the divisor


For Example:

A = 7;
B = 4;
C = Rectangle(A, Mod(A,B));
Output(C);

...

<value1>

Defines the dividend

<value2>

Defines the divisor


 

For Example:

A=7;
B=3;
result1 = A/B;
result2 = Div(A, B);
rect = Rectangle(result1, result2)
Output(rect);

...

Format:
Array(<list of objects>)

<list of objects>

list of numerical values or geometric objects
An <object> can be represented by either a value, or the <identifier> of a value, or by a Point(x,y,z) function.

...

Array(Point(L/2, 0, 0), Point(0, W/2, 0), Point(L/2, W, 0), Point(L, W/2, 0))
// It is the array of points defining the edges for G3Fillet.
Array(R, R, R, R, R, R, R, R)
//It is the array of radius values for filleting the array of edges.

Another Example: Can

txt = Parameter("text", "Simple text example", TEXT);
a = Array(TextFont(0,10,"Arial"), TextStyle(CENTER, MIDDLE, ITALIC));
//Array of 2 items: TextFont and TextStyle)
s0 = Text(txt, a);
Output(s0);

...

bse = Group(bse_below, bse_above); //group of 2 graphic objects
Br2 = Group(Br0, Br1);

For Example:

Bx = Group(Move(BxL, -Dis*1.5), Move(BxR, Dis*1.5));
ShelfFBx = BooleanSubtract(ShelfF, Bx);
Output(ShelfFBx, Bx);

...

The PI function calculates the value of Pi = 3.14159...

...

Creating custom functions

When scripts of the same type are created, which describe a particular class of parametric parts, it can be convenient to have the sequence of repeated actions as a separate specialized function. To achieve this, the repeated actions can be put into a separate <name>.ppm file.
In this case, all input variables should be listed in the Input operator:

...

Input(<list of variable identifiers, separated with commas>);

For Example:

Input(x0,y0,z0,x1,y1,z1);

The Output operator should also be defined.

Format:

Output(<list of variable identifiers, separated with commas>);

A custom function created in this manner must be placed in a Macro folder, which is always located inside the folder of the calling script. When the custom function is used, the script's file name (without the .ppm extension) is used just as if it was a built-in function.

...

<file name>(<list of input parameters>)

Below is an example of a custom function. The file box.ppm can be found in the PPM Documentation Samples/Macro folder:

// box.ppm – defines a custom Box function.
// The custom function is called in this way:
// B = Box(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
// The function creates a 3D box with given min/max values
Input(x0,y0,z0,x1,y1,z1);
R = Rectangle(x1-x0, y1-y0, // Rectangle with Xmin = x0, Xmax= x1
(x0+x1)/2, (y0+y1)/2); // Ymin = y0, Ymax = y1
T = Thickness(R, z1-z0); // depth = Zmax - Zmin
Output(Move(T, 0, 0, z0)); // move result along z to Zmin
The script below is box_ blend.ppm, which calls the custom function box.ppm
//box_blend.ppm uses the custom Box.ppm function in the Macro folder.
x = Parameter("size", 5, LINEAR, GreaterThan(0));
r1 = Parameter("r1", 0.5, LINEAR, GreaterThan(0));
b0 = Box(0, 0, 0, x, x, x);
b1 = G3Fillet(b0, Point(x/2, 0, 0), Array(r1, r1*2));
Output(b1);

File location is crucial when using parametric scripts as custom functions. In the example above, if blend_box.ppm lies in the folder D:/Symbols, then it can only find the box.ppm script if box.ppm is located in the folder D:/Symbols/Macro.

...