Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   Help with a Script (https://simplymaya.com/forum/showthread.php?t=11768)

TheElement 08-05-2004 04:53 AM

Help with a Script
 
Hey guys, this is my first post on simplymaya.com, but I heard this is a pretty good forum. Here's the deal: I'm trying to write a script that takes a group of selected objects and sets the translateY for each object equal to the translateZ. In the script below, no matter what I try, I get the error message:

// Error: for ($i = 0, $i < $tempArrSize, $i++){
//
// Error: Syntax error //
// Error: }; //
// Error: Syntax error //

Here's the script. If anyone has any idea how I can fix this, PLEASE help me out. I've tried a post in other forums with little success so I'm running out of resources. Thanks in advance.

//sinfunc: function takes a group of selected objects and
//graphs them according to the equation y = z

global proc sinfunc(){

//stores each selected object in an array

string $sel[];
$sel = `ls -sl`;

//defines some variables and sets the
//$tempArrSize as the number of selected objects

int $tempArrSize;
int $i;
string $tempObj;
$tempArrSize = size($sel);

//Moves through each object in $sel and sets
//the translateY equal to the translateZ

for ($i = 0, $i < $tempArrSize, $i++){
$tempObj = $sel[$i];
setAttr ($tempObj + "." + "translateY") ($tempObj + "." + "translateX");
}
};

dannyngan 08-05-2004 05:00 AM

Looks like you have an extra curly bracket ( } ) at the end of your script. Just delete it.

Also, no need to cross-post in different forums. People will see your one post. :)

TheElement 08-05-2004 10:22 PM

The last curly bracket is to close the procedure, the second to last one is to close the for loop. When I try deleting the last } I this error:

// Error: for ($i = $tempArrSize, $i > 0, $i--){
//
// Error: Syntax error //

Any ideas?

dannyngan 08-05-2004 10:29 PM

The For loops are declared incorrectly. Instead of commas (,) you should use semicolons (;) between the loop parameters. So for instance, your for loop should look like this:

Code:

for ($i = $tempArrSize; $i > 0; $i--){......}

Nametag 15-05-2004 03:08 AM

Hi ive had a quick look at your code and simplified it alittle.
Basically it gets the value of transZ from the current obj and sets transY to the same for each obj in the array.

code:
-----------------------------------------------------------
float $translatez = 0;
string $SelectedObj[] = `ls -sl`;
int $size = size($SelectedObj);

for ($i = 0; $i<$size; $i++)
{
$translatez = `getAttr ($SelectedObj[$i] + ".translateZ")`;
setAttr ($SelectedObj[$i] + ".translateY")$translatez;

}

-------------------------------------------------

Hope this helps :)


All times are GMT. The time now is 01:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018