PDA

View Full Version : Two function in one button


asah
11-24-2012, 05:32 PM
Hi :)

I want to make button for mute muisc So if click the button, the music is off and when pressed again on the button , the music is on

How do this ???

djx
11-25-2012, 02:17 AM
Not really sure what you mean by "music", so I'll assume you mean an audio track in the timeline. Anyway it will show how you can do a toggle command.

If you have a track called "MyMusic" then this could be your button command:

string $music = "MyMusic";
string $timelineMusic = `timeControl -q -s $gPlayBackSlider`;
if(size($timelineMusic))
setSoundDisplay $music 0;
else
setSoundDisplay $music 1;

David

asah
11-25-2012, 03:43 AM
Thanks :)

I tried your code but Maya says setSoundDisplay is an unknown procedure

djx
11-25-2012, 05:02 AM
Fair enough. Apparently it is a global proc in C:/Program Files/Autodesk/Maya2013/scripts/others/updateSoundMenu.mel (you can find that out by "whatIs setSoundDisplay"). So one solution would be to source the script first...

source updateSoundMenu.mel ;

Another (better) solution would be to have a look at that mel and work out what the proc was doing.
In this case the main two lines are

global string $gPlayBackSlider;
timeControl -e -ds $state -s $node $gPlayBackSlider;

So you could rewrite the code I suggested and turn it into your own global proc as follows:

global proc toggleMusic(string $music){
global string $gPlayBackSlider;
string $timelineMusic = `timeControl -q -s $gPlayBackSlider`;
if(size($timelineMusic))
timeControl -e -ds 0 $gPlayBackSlider;
else
timeControl -e -ds 1 -s $music $gPlayBackSlider;
}

Then you can toggle with

toggleMusic("MyMusic");

David

CGTalk Moderation
11-25-2012, 05:02 AM
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.