...
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); |
...
Code Block |
---|
Rect = RotateZ(Rect1, Angle);
|
Code Block |
Output(Rect);
|
Let's examine each line of this example:
LINE 1
Code Block |
---|
// 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
Code Block |
---|
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
Code Block |
---|
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
Code Block |
---|
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
Code Block |
---|
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
Code Block |
---|
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.
...