View Full Version : $Strings[0] in expressions

06-10-2010, 02:22 PM
So I'm trying to use a string in an expression although I'm not having any luck. There is something in the help for expressions that says you need an escape \" for quotes or it'll get confused, well that's just down right confusing me. Maybe there is a better way to go about this, I read somewhere that I could write a script that writes an expression??? sounds wild to me. Anyways here's what I have.

expression -s "polyExtrudeFace1.localTranslateZ = WheelMeasuringDevice69.SideWallHeight * (.01) * polyCylinder1.height" -o $wmd[1] -ae 1 -uc all ; // this works but only for objects named exactly that.

expression -s "($sw[0] + ".localTranslateZ") = 0.01* ($wmd[0] + ".SideWallHeight") * .01 * ($wmd[1] + ".height")" -o $wmd[1] -ae 1 -uc all ; // This is how I expected it to work.

expression -s "$swhLTZ = $wmdSWH * (.01) * $wmdSWH" -o $wmd[1] -ae 1 -uc all ; // yells at me for putting something in an expression ???

well if anyone has suggestions or need more info let me know.

06-11-2010, 03:30 AM
it can be done it can just be annoying at times.

so lets say we have 3 cubes and we want to make an expression similar to yours on them:

string $s[] = `ls -sl`; //Get the selection

//Add your attributes
addAttr -ln "localTranslateX" -at double -dv 0 $s[0];
setAttr -e-keyable true ($s[0] + ".localTranslateX");
addAttr -ln "sideWallHeight" -at double -dv 0 $s[1];
setAttr -e-keyable true ($s[1] + ".sideWallHeight");
addAttr -ln "height" -at double -dv 0 $s[2];
setAttr -e-keyable true ($s[2] + ".height");

//Now lets make the expression
string $expString = $s[0] + ".localTranslateX = 0.01 * " + $s[1] + ".sideWallHeight * 0.01 * " + $s[2] + ".height;";
print $expString;
expression -s $expString -o $s[2] -ae 1 -uc all ;

i hope this helps ;)

06-11-2010, 02:02 PM
Worked perfectly! Thank you!

I replaced my strings where you had yours and it works great. If your up to it could you explain why the " and + go where you have them in the string? with the setAttr it makes sense with the ( and all but in the string it kind of blows my mind and I can't see the method. I'm sure if I look at it long enough and play with it more I'll figure out why it works.

Thanks again!

oh if your interested in a script thingy that makes a tire measuring device lemme know and I'll post it up.

CGTalk Moderation
06-11-2010, 02:02 PM
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.