|
Prisms Development Toolkit DocumentationSide Effects Software Inc. 1997 |
/ufs/prisms/support/funcs/sample.func
You can (and should) copy this file to another location, and create your
own functions there. Let's say you copy the above file to
/usr/staff/bob/myfunctions.func
Then whenever you start a new action, type
exread /usr/staff/bob/myfunctions.func
in the textport, or use the SOURCE button at the bottom of the EXPR FUNC page in action. This will tell action where to find the expression functions. This information is stored in subsequent .bmot files, so it need not be entered again for saved .bmots.
To edit the custom function file, click on the Edit button in the Expression page; this opens the vi editor. To close, use the vi command ZZ. This reinterprets the functions, ready for use. You can edit the file outside of action, but then you will need to reload the file using the Source button or the exread command.
You can force action to always look elsewhere for the expression
functions. To do this, go to your home directory, and create a directory
called .prisms (if there isn't one already). In that directory, using a
text editor, create or modify the file action.rc to contain the line:
exread /usr/staff/bob/myfunctions.func
You can do the same thing by modifying $HOME/.action/123.rc, but here
you must place the exread... line before the line that reads
rcread $HOME/.prisms/action.rc
simple(val)
{
j = 0;
for (i = 0; i < val; i++)
j = j + i;
}
Because the language is interpreted, you may
reference other functions before you define them. For example:
dothis(val)
{
return(dothat(val)+val);
}
dothat(val)
{
a = sqrt(val);
return(a);
}
center(x, y, z)
{
dx = x - $CEX;
dy = y - $CEY;
dz = z - $CEZ;
return(sqrt(dx*dx + dy*dy + dz*dz));
}
Then in the point SOP, the expression $TY+center($TX, $TY, $TZ)in the 'pos Y' field will work properly. Used in other SOPs, it may not, depending on whether or not $CEX etc are defined within that SOP.
All of the mathematical functions are available within the function, as the use of sqrt() shows above. In addition, the other functions, such as point(), may be used. For example, a restricted version of the point() function could be defined as:
pt(p)
{
return(point(reference_obj, 1, p, TX));
}
$TY + print(center($TX, $TY, $TZ))will print each value to the textport as it is calculated. It is not possible to use the print() function within an expression function.