Exercise 12

Write a simple script
Select the handle object (the first cylinder we created). Select the Window>Script Editor menu item (Command-Y). The Script Editor palette will open. Type the following script exactly as shown:

WhatÕs going on?
LetÕs take a look at the script line by line. The first line uses the set command to create a new variable, zRot, and assign it the result of the getparam command. We must enclose the getparam command in brackets so that the result of this command is assigned to our variable. Without the brackets the computer would try and assign the getparam command itself to our variable, which would return an error.

The getparam call is a general purpose command for accessing specific information about objects in our scene. The file params.html on your PiXELS3D CD describes all of the options available in detail.

In this example we are using the -r.z option. This option will return, in degrees, the z component of the objectÕs rotation angle. The same value can be seen and altered using the Object Info palette.

Our variable, zRot, is now equal to the z rotation angle of the handle object. That alone is pretty useless, but we can use this information to control other objects in the scene. First, letÕs modify the value a little. In the second line of our script, we use the expr command to mathematically alter our variable. We also use the set command to assign the altered value to a new variable, yPos. Notice how we must place a $ in front of our variable. Anytime a variable is used in an expression or command, it must be preceded by a $.

In the third line, we introduce the setparam command. This command is the compliment of getparam. It is used to pass variables to objects in our scene.

In this example we are using the -p.y option. This option will set the y position of a given object to our variable. Notice how the variable is preceded with a $. We also added an objectÕs name to the end of this command. This directs the value to the named object, as opposed to the object that this script belongs to.

Set constraints
Click on the X Axis and Y Axis constraints to deactivate them, leaving only the Z Axis active. Rotate the handle Select the Control > Rotate tool. In the Front view, click and drag the mouse up. Notice how the Window object moves in relation to the rotation of the Handle object.