PDA

View Full Version : Adding buttons on the fly - each with their own command


mlefevre
04-16-2009, 02:19 PM
Hi,

I'm trying to build a snapshot GUI (of current workspace), whereby clicking on a custom button, a procedure is run that will create a symbolButton, with the image being the current image of the workspace..and then to do this as many times as the user wishes, appending symbolButtons to the GUI.

This works fine, but I'm running into trouble trying to create a custom command for each symbol button produced.

For example, each button will print out the frame on which it was created.

Any suggestions would be great,

Thanks!

Keilun
04-16-2009, 05:22 PM
Are you defining the -c/command flag for your symbolButton creation? Alternately after you've created it, you can -e/edit and add the command with the -c/command flag.

If you post the line where you create your symbolButton, we can see if there are any issues with your call.

If you want to post the current frame at the time the snapshot was taken you could do something like:

int $curFrame = `currentTime`;
string $cmd = "print( \"Frame: \" +" + $curFrame + ")";
symbolButton -c $cmd myNewShinyButton

mlefevre
04-16-2009, 07:02 PM
Thanks for your help Keilun. This works perfectly, however the problem arises again if I try to edit the current time, based on the individual button.

I realise why it happens, if $curFrame is only storing the last value from the `currentTime -query` command, so every command I make for each button ends up doing the same thing.

Actually, I'm confused as to why print works fine, but this way does not. :o

If I can find out which button I've pressed, I'll be able to get around it.

Keilun
04-16-2009, 07:23 PM
Well currentTime reports the currentTime, at that particular time that the button is created. I'm unsure of what you're trying to achieve here now.

You want the button to print the current frame at the time the button was created, correct?

The code above is recording the currentTime, just before it's creating the button. If you want to edit the current time, then you'll want to just change the $curFrame number to the time you want it to be associated with.

I'm feeling that I'm missing something as to what you're trying to achieve..

mlefevre
04-16-2009, 07:35 PM
Ahh, well, if I add 10 buttons using your code, each one will print the frame at which it was created.

Is it possible, to have the button command for each button actually edit the current time, to the frame at which the individual buttons where created?

Keilun
04-16-2009, 07:45 PM
Oh I see. Yes, you can call currentTime -u $frameNumToSet to do that. So my code would then look like:


// Record current frame at which the button was created
int $curFrame = `currentTime`;

// Build a command that updates frame to time of button creation
string $cmd = "currentTime -u " + $curFrame + ";";

// Create button with the created command
symbolButton -c $cmd myNewShinyButton

Keilun
04-22-2009, 08:15 PM
Oops. I made a mistake. I should read the documentation more clearly. This is what the code should be:

// Record current frame at which the button was created
int $curFrame = `currentTime`;

// Build a command that updates frame to time of button creation
string $cmd = "currentTime " + $curFrame + ";";

// Create button with the created command
symbolButton -c $cmd myNewShinyButton

The -u/update [boolean] flag is just an optional way to change the time, but not update the scene. I was using it incorrectly. So as in the code above, the proper syntax is:

// Change frame to frame 30 in current time units
currentTime 30;

mlefevre
04-22-2009, 08:57 PM
Thanks alot Keilun, you've been a huge help!

CGTalk Moderation
04-22-2009, 08:57 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.