continued from Mel Lesson 4 Practical Usage 1A
//====================================
//----------------------copy-------------------
$objTx = getAttr ("pCylinder1.translateX");
$objTy = getAttr ("pCylinder1.translateY");
$objTz = getAttr ("pCylinder1.translateZ");
$objRx = getAttr ("pCylinder1.rotateX");
$objRy = getAttr ("pCylinder1.rotateY");
$objRz = getAttr ("pCylinder1.rotateZ");
Lets modify the above codes to make it take value from any object instead of pCylinder.
---------------------------------------------------------------------------------------------------
ARRAY
string $myObject [] = `ls -sl`;
The above code basically means list selected it stores all the objects name that are selected in maya in the variable called $myObject. Note that this is a variable array unlike a variable it can store more than one value. If you run the above comman after selecting a cone, a cylinder and a cube $myObject will have all the three names stored in it. (Remember the variable stores just the names of the objects and not the object itself.)
You can find the values of the variable $myObject by the using the below command.
print ($myObject[0]);
//result "cone";
print ($myObject[1]);
//result "cylinder";
print ($myObject[2]);
//result "cube";
I guess you have understood what array is.---------------------------------------------------------------------------------------------------
Now select any object you wish to copy the transform value. Say for example you have selected R_Hnd_Cntrl
Run the below command.
string $myObject [] = `ls -sl`;
//result: R_Hnd_Cntrl
since you selected one object only, the object you selected would be in $myObject[0];
check whether you are right by executing the below.print $myObject [0];
//result: R_Hnd_CntrlNow replace $myObject [0] instead of pCylinder in the command we used in our earlier exercise.
$objTx = getAttr ("pCylinder1.translateX");
Since $myObject [0] is a variable and not a string like pCylinder, you have to use it without quotes, which will tell maya to fetch the value of the variable.
$objTx = getAttr ($myObject[0]+".translateX");
You use the "+" to join a string and a variable or a variable and a variable. It is called concatenate-ing
Try the following command to understand better
print ($myObject[0]+".translateX")
//result: R_Hnd_Cntrl.translateX
To be continued...






