Scripting an expression

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 12 December 2003   #1
Scripting an expression

I'm trying to figure out to add an animation expression to the attribute of an object through a script... let me show you what I have so I can better explain my problem. This just a simple example to explain what I want to acheive. This script creates 3 locators and adds an expression to one that will cause it maintain a center point between the other two locators just on the X axis. As you can see the name I'm casting into the script is "bob". So it creates the locators adding "bob" to the name of the locators. Now the animation expression works at this point because I used the string "bob" but what if I use "carl"?... the animation expression no longer works because its looking for the string
"bob". So my question is how can I cast any string I want into the procedure and the animation expression will accept it. I'd imagine that there are many times when you want to add animation expressions to a lot of different objects.... but it shouldn't be necessary to alter your code for the name of every different object. Thanks for any help.

scripter "bob";

global proc scripter (string $name)

spaceLocator -p 0 0 0 -n ($name + "_locator");

spaceLocator -p 0 0 0 -n ($name + "_locator2");
move -r -os -wd 10 0 0 ;

spaceLocator -p 0 0 0 -n ($name + "_middle");
move -r -os -wd 5 0 0 ;

select -d;

//the exprression that only likes "bob"

expression -s "bob_middle.translateX =(abs (bob_locator.translateX - bob_locator2.translateX)) /2;"
-o bob_middle -ae 1 -uc all ;

Rest In Peace... Dime....

Last edited by kmp3d : 12 December 2003 at 02:12 AM.
Old 12 December 2003   #2
Your script cannot understand "carl" since "bob" is hard coded to the expression.

To have the expression be more flexible try using variables instead of constant string.

Here is an example, I just add 3 string variables to hold the locators name and 1 string variable for the expression (you don't really needed if you want to put it directly into the expression command.

Quote: global proc scripter (string $name)
string $locator[] = `spaceLocator -p 0 0 0 -n ($name + "_locator")`;
string $locator2[] = `spaceLocator -p 0 0 0 -n ($name + "_locator2")`;
move -r -os -wd 10 0 0 ;

string $middle[] =`spaceLocator -p 0 0 0 -n ($name + "_middle")`;
move -r -os -wd 5 0 0 ;

select -d;

//the exprression that only likes any string

string $expression = $middle[0] + ".translateX = (abs (" + $locator[0] +
".translateX - " + $locator2[0] + ".translateX)) / 2;";

expression -s $expression -o $middle[0] -ae 1 -uc all ;
My Profile
Old 12 December 2003   #3
thanks for the help, thats what I needed
Rest In Peace... Dime....
Old 01 January 2006   #4
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 12:00 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.