PDA

View Full Version : help for randomizing translate for objects in array:


i-studio
11-22-2011, 11:37 PM
hi i wanted to randomize the object in array as you can see my array is list of selected object;

this is my program;
i wanna make the translates random or random between two values for each selected object in array;

string $object[] = `ls -sl`;
for ($obj in $object) {
setAttr ($obj + ".translateX") 10;
setAttr ($obj + ".translateY") 10;
setAttr ($obj + ".translateZ") 10;

setKeyframe -at "translateX";

setKeyframe -at "translateY";

setKeyframe -at "translateZ";

};


help me please;

i-studio
11-24-2011, 08:28 PM
it means there aren't any good programers here.please help me.

bendingiscool
11-25-2011, 02:38 PM
I doubt that's the case ;)


import maya.cmds as cmds
import random as random

for s in cmds.ls(sl=True):
cmds.xform(s,ws=True,t=[random.uniform(-10,10),random.uniform(-10,10),random.uniform(-10,10)])
cmds.setKeyframe(s,at="translate")


cheers,
Chris

i-studio
11-25-2011, 02:50 PM
thank you because of your advice but i can't use python.could you type that with MEL;

mlefevre
11-25-2011, 06:26 PM
global proc randomIt(int $min, int $max)
{
string $obj[] = `ls -sl`;
for($x in $obj)
{
vector $vec = `rand <<$min, $min, $min>> <<$max, $max, $max>>`;
xform -ws -t ($vec.x) ($vec.y) ($vec.z) $x;
}

}

randomIt(1, 10);

i-studio
11-25-2011, 07:45 PM
global proc randomIt(int $min, int $max)
{
string $obj[] = `ls -sl`;
for($x in $obj)
{
vector $vec = `rand <<$min, $min, $min>> <<$max, $max, $max>>`;
xform -ws -t ($vec.x) ($vec.y) ($vec.z) $x;
}

}

randomIt(1, 10);


thank you verymuch mlefevre (http://forums.cgsociety.org/member.php?u=301370).
could you explain this line xform -ws -t ($vec.x) ($vec.y) ($vec.z) $x; for me.
explain about flags and specially xform.how does it work? and what is xform.
best regards.

NaughtyNathan
11-25-2011, 08:39 PM
http://download.autodesk.com/us/maya/2010help/Commands/xform.html

you should have this stuff installed with Maya, open your Maya Help menu and click on Mel Command Reference

CGTalk Moderation
11-25-2011, 08:39 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.