Sep 2010
1 / 5
Sep 2010
Sep 2010

Hi everyone.

Hi need a little help on a script that I made. In resume I need something that read the amount of poses of certain character and then create a window with buttons, each on relative to a pose.

This check the amount of poses.

global proc string[] currentCharacterPoses()
{
 string $allPoses[];
 string $characters[] = `currentCharacters`;
 int $n=0;
 int $nchars = size($characters);
 if ($nchars == 0) return allCharacterPoses();
 for ($i=0; $i < $nchars; $i++)
 {
 string $poses[] = `pose -q -n $characters[$i]`;
 for ($j=0; $j < size($poses); $j++)
 $allPoses[$n++] = $poses[$j];
 }
 return $allPoses;
}

And based on that information.

string $posesDo[] = `currentCharacterPoses`;	
int $i;
 for ($i=1; $i< size($posesDo);$i++)
 {
 symbolButton -i ($filePath + "Corpo\_P" + $i + ".BMP") -w 75 -h 75 -ann "$i" -c "doPose";
 }

But now I have a problem. Every button that I create will have as command "doPose" and I don't want that. Or I need a way to identify every button so later I can use that information to search and applied the correspondent pose.

Can anyone help me with this, please? 

modify do pose to accept a integer or string identiier and change the command flag to:

-c ("doPose(" + $i + ");")

or

-c ("doPose(\"" +$posesDo[$i] + "\");")

Thanks Joojaa for the reply.

I gonna post here all the code

1
2
3
4
5
6
7
8
9
10
11

string $fileUser = internalVar -userScriptDir;
string $filePasta = "Poses/Do/";
string $filePath = $fileUser + $filePasta ; // logo da janela
string $filePaththumb = ""; // thumbs
window -tlb off -rtf on -sizeable off -t "Poses Do";
columnLayout -adjustableColumn true;
image -w 450 -h 100 -i ($filePath + "logo.BMP");
rowColumnLayout -numberOfRows 3
-rowHeight 1 75
-rowHeight 2 75
-rowHeight 3 75;

Then I use a default global proc from Maya to check the amount of character poses the global proc is currentCharacterPoses.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

global proc string[] currentCharacterPoses()
{
string $allPoses[];
string $characters[] = currentCharacters;
int $n=0;
int $nchars = size($characters);

if ($nchars == 0) return allCharacterPoses();

for ($i=0; $i < $nchars; $i++)
{
	string $poses[] = `pose -q -n $characters[$i]`;
	for ($j=0; $j < size($poses); $j++)
		$allPoses[$n++] = $poses[$j];
}
return $allPoses;

}

Then with this information

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

string $posesDo[] = currentCharacterPoses;
int $i;
for ($i=1; $i< size($posesDo);$i++)
{
symbolButton -i ($filePath + "Corpo_P" + $i + ".BMP") -w 75 -h 75 -ann "$i" -c ("doPose(" + $i + ");");
}

global proc int doPose (int $i)

	{
		/*select -r "*Corpo\_P0";
		string $obj[]= `ls -sl`;
		string $character = "*DOcorpo";
		pose -apply -name $obj $character;
		return 1;*/

		string $corpoP = "*Corpo\_P";
		string $total = $corpo\_P + $i;
		select -r total;
		string $obj[]= `ls -sl`;
		string $character = "*DOcorpo";
		pose -apply -name $obj $character;
		return 1;
	}

showWindow;

I have follow your advice and use the command flag

-c ("doPose(" + $i + ");")

But first I need to tell proc $doPose what is variable $i. Unfortunately I can make this work because I get a error say that $corpo_P is an undeclared variable. :s But I already declared that this is a string variable.

Err...

I get a error say that $corpo_P is an undeclared variable.

Well yes offcourse because you dont declare it anywhere.

Anyway you prbably just want to pass the string instead. Becuse you go trough the pains of figuring out the name of the character beforehand. So what strikes me as a bit waste of time is that you go ahead and re figure out the name at each stage, which is a bit error prone.

OMG

I made a mistake. It wasn't $corpo_P but instead $corpoP. Sorry about that.

Another thing is about the variable $corpoP = "Corpo_P" and $character = "DOcorpo". The Corpo_P is the name of the pose and DOcorpo is the name of the character. My idea is to create a different script to each character. So I already know the name of the character and the pose too.

The correct code:

global proc int doPose (int $i)
		{
			/*select -r "*Corpo\_P0";
			string $obj[]= `ls -sl`;
			string $character = "*DOcorpo";
			pose -apply -name $obj $character;
			return 1;*/
			string $corpoP = "*Corpo\_P";
			string $total = $corpoP + $i;
			select -r total;
			string $obj[]= `ls -sl`;
			string $character = "*DOcorpo";
			pose -apply -name $obj $character;
			return 1;
		}

But now I have a doubt. When you gave to me the command flag -c ("doPose(" + $i + ");"), the variable $i will pass the value to the global proc doPose???