PDA

View Full Version : getting informations back -out of for loop



Marcel_
09-06-2010, 04:12 AM
Hi everyone.
I´m having troubles with a mel script I try to write.
after hitting a button on myWindow I want the appropriate camera selected.
But in this case the topShape cam gets always selected whatever button is used (except new Camera Button).

This is the part of the script:


string $myWindow = `window`;
columnLayout;

button - label "new Camera" -command "camera -n newCam001";

string $allCams[] = `ls -et "camera"`;

for($camera in $allCams) {
button -label $camera -command "select $camera";
}

showWindow $myWindow;


Hope anyone can help me.
thanks in advance
Marcel

chrisg
09-06-2010, 09:22 AM
Hi Marcel,

Ah, pretty common problem. When you say -command "select $camera", you are passing along each button's command to be select $camera, not select FrontShape, select pespShape, etc. This happens because when you put quotes around something, Maya treats it as a literal string and does not evaluate anything in between the quotes.

So, to fix this, you need to have your select in between the quotes, but the $camera variable outside the quotes. This introduces some issues, so let's deal with them on by one. First, -command "select" $camera, will see camera as a new command and error out. So we need to find a way to tell command that select and camera are part of the same argument. This can be done with parenthesis. -command ("select" $camera) is seen as a single piece that gets copied to command. However, we will still error out, because there is no separator between the select and $camera, so we need to add a plus sign. This means 'when you write the -command, make sure that select and $camera stay together. Now our window opens, but when we click ERROR! This is an easy fix, let's just add a space after "select " to make a separation between the command and the $camera. Ta-da! It should now work.


button -label $camera -command ("select " + $camera);

Let me know if you run into any other issues, I love answering MEL questions.

Marcel_
09-06-2010, 05:53 PM
thank you for your quick and exact respond. now it works.
since this is my first script,(just starting to get my head round mel) I will probably come up with the one or other question.