PDA

View Full Version : Apply Maya Expression to similarly named objects


Blurisere
08-20-2010, 06:35 PM
Yup its exactly as the title states, I want to apply the same expression to a group of objects with similar names. the only difference between the names are the numbers. An example of the expression is below this post. Alse if you could drop a few hints on how to improve this expression, that will be very much appreciated.

$r = rand(BlueLocator.WindShakePos,BlueLocator.WindShakeNeg); MP_Planet|Ball_SurfaceGroup|Blue_Cube_Group|Blue_Cube_1.rotateZ = noise(time)*0


$r = rand(BlueLocator.WindShakePos,BlueLocator.WindShakeNeg); MP_Planet|Ball_SurfaceGroup|Blue_Cube_Group|Blue_Cube_2.rotateZ = noise(time)*0

ArrantSquid
08-20-2010, 10:54 PM
Whether it's right or wrong, here's how I'd do it:

string $sel[] = `ls -sl`;
for($node in $sel){
expression -s ("$r = rand(BlueLocator.WindShakePos,BlueLocator.WindShakeNeg);\n" + $node + ".rotateZ = noise(time)*0;") -o $node -ae 1 -uc all;
}


Basically whatever objects you have selected will have that expression applied to it. Alternatively, you could provide a list of objects like this:


string $sel[] = {"pSphere1", "pSphere2", "pSphere3"};


replacing the pSphere's with the names of your objects.

The other thing is that, while you've declared $r for some reason, you're not using it anywhere within your expression. More importantly, you're multiplying the end result by 0, which anyone can tell you, is going to give you a 0 right back. So as far as improvements go, I really can't say other than that it'd be helpful to know a bit more about what you're trying to accomplish because it's rather confusing right now. HTH.

Blurisere
08-20-2010, 11:11 PM
Thanks for the reply and i will try that method soon to varify that its working, and whilst waiting for a reply i did it all manually anyways ((Microsoft word: find & replace = Life saver)) and the expression I posted was incomplete, the ending has + $r; and i multiplied by zero so the 1st frame wasnt affected.....

I just started learning expressions today so all these things quite confusing but so far this script is giving me the result I predicted.

ArrantSquid
08-21-2010, 12:00 AM
Glad I was able to help and I assume you're using the divide by 0 because nothing happens on frame 1, thus you're getting no output from the wind shake pos or wind shake neg. If that's the case, then you don't need to divide by zero (unless of course I'm misunderstanding how you're code is going).

As an aside, instead of using Word for your text editing, you could alternatively use an IDE that doesn't add in extra things like Word does (if you happen to ever save your code as a mel file it won't work). You can use Notepad++ (http://notepad-plus-plus.org/) or JEdit (http://www.jedit.org/) for free/open source programs. I've used notepad++ (when I'm developing on my windows box) and while it's nice, the syntax highlighting for mel doesn't allow for code collapsing and when you use a theme with it, things become unreadable. Jedit looks pretty nice and I know folks that swear by it. If you don't mind paying for a product you can use either Maxya (http://www.tarzworkshop.com/index.php?categoryid=10) or E-Text Editor (http://www.e-texteditor.com/). Maxya is more integrated into Maya than E is, but I use Textmate on my Mac so I prefer E (as I've also never used Maxya). Maxya is the more expensive of the two, but they also have a free edition that works the same as the others. I do most of my development on my Mac, so I use Textmate for almost everything. HTH and glad your stuff is working.

CGTalk Moderation
08-21-2010, 12:00 AM
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.