Getting to Know PixelScript
Power to the People

Using the History Palette & Expression Editor

Introduction

PixelsScript is PiXELS' built in scripting language. It is based around TCL (Tool Command Language). Pretty much anything you can do in PiXELS can be done using PixelsScript. PiXELS provides a rich set of commands to aid the user in controlling the application via scripting. You can even extend the set of commands by dropping in shared libraries that contain code that implements other commands. This tutorial provides the user who knows nothing about PiXELS Script with a firm foundation for learning the language. Future tutorials will concentrate more on scripting.

Getting Your Feet Wet in TCL

TCL stands for “Tool Command Language”. It was created during the late 1980s. TCL can be found on more modern operating systems. As of this writing TCL 8.3.2 is available for MacOS. This version has preliminary Carbon support. TCL is like any other sophisticated scripting language. There is the notion of variables, subroutines, lists, sockets, and conditional statements.

To create a variable and set its value, you use the following syntax :


set myVar theValue

The name 'theValue' can be any value you wish. To get the value of “theValue” you attach '$' before the string 'theValue'.

puts $theValue

TCL has a suite of math functions that you would expect, such as sin(), cos(), tan(), abs(), and log(). TCL even supports the hyperbolic functions. This is useful for anyone interested in the math behind 3D graphics. The arguments to these trigonometric function is expected to be in radians.

A good source for learning TCL are the many books available at your local book store, or the Scriptics website.



The History Window is Your Friend


While using PiXELS you will probably see the “history” window. This window contains a history of all the commands executing. Studying the commands in this window is helpful in learning PixelsScript. For example consider the code below :


Figure One - History Dump
select -cl
sphere -name Sphere -radius 10.0000 -endSweep 360.0000 -uSteps 10 -vSteps 10
select -r Sphere
setparam -ub 2
setparam -vb 2
scale -relative -worldSpace 2.1800 2.1800 2.1800 Sphere
addkey -a -scale
sculpt -u 0.0646 -v 0.2019
sculpt -u 0.0639 -v 0.2078
sculpt -u 0.0751 -v 0.2118
sculpt -u 0.1176 -v 0.2453
sculpt -u 0.1308 -v 0.2643
sculpt -u 0.1372 -v 0.2723
sculpt -u 0.1459 -v 0.2902
sculpt -u 0.1466 -v 0.3238
sculpt -u 0.1451 -v 0.3304



The code above creates a sphere, scales it, and then sculpts it. You can learn a great deal of what goes on by looking at the commands that appear in the history window.



This history window also has another benefit. You can quickly type in commands, thus the history window acts as a mini console. Lets say you quickly want to set a selected object’s shader all you have to do is type setshader theObject theShader, where theObject corresponds to the object name and theShader corresponds to the shader name. Knowing your way around in the history window can save some time just as knowing your way around the UNIX command line can save time. Speaking of UNIX. TCL can be used as a shell. So commands like “ls” and “cd” can be used. Try typing the following in PiXELS :

cd :
set dirListing [ls]
puts $dirListing


This piece of code will change the working directory and print out a list of the files. Just like UNIX!




Using the Expression Editor & Script Editor

The “Expression Editor” is a way to attach a expression to each object in a scene. To attach an expression to an object you open the expression editor window and type in the script. This script will be executed for that object. The ScriptEditor provides user a place where they can type scripts that may take more than one line of code. While in the ScriptEditor, users can run scripts and see their output immediately.




Getting More Information

If this tutorial has whet your appetite for PixelsScript you should take a look at the user community located on the Pixels web site. There are numerous users who provide scripts and the code for free. This is a good way to learn more about PixelsScript. Stay tuned for more exciting articles on scripting PiXELS.