Home General Discussion

Need help with Mel Script, if possible

Hi guys n' gals,

I'm not sure if this is the right place to post this... But here it goes anyway.

I'm not a super-active user, I plan on correcting that... Regardless, I'm looking for some advice as to how to approach this issue I have. I'm trying to create a panel that pops up to the left of the docked window when you click a button, it toggles.

The toggle button should be able to change its text from "<-" to "->" when you click on it, so basically, it swaps itself out.

I was referencing some scripts but the issue is that I cannot figure out how to call a procedure and change the button as well.


For reference, this is what I have thus far (I know it's taken out of context but I'll fill you in on the details in a moment)...
[some code above labeled that dock be reinitialized if it's already there with some strings]
$CB = `window
-t "Channel Box / Tool"
-tlb true -wh 260 1000`;
columnLayout -adj true;
rowColumnLayout -nc 1;
button -e -l "<-" -w 260 -h 32 -c "ToggleMergeToolbar";
columnLayout -adj true;
// create a channel box widget
channelBox -h 600;
setParent..;
[a bunch of buttons under it]
setParent..;
showWindow $CB;

*BREATHES*
global proc ToggleMergeToolbar(){
global string $TestIt;
global string $MergeWndDisplay;
$TestIt = `paneLayout -q -vis MergeWindow`;
if ($TestIt == 0){
$MergeWndDisplay = "on";
paneLayout -e -vis 1 MergeWindow;
button -e -l "->" -c "ToggleMergeToolBar;";
}
if ($TestIt == 1){
$MergeWndDisplay = "off";
paneLayout -e -vis 0 MergeWindow;
if (`dockControl -ex CB`){
dockControl -e -w 400 CB;
}
}
button -e -l "<-" -c "ToggleMergeToolbar;";
}

[MergeWindow]

$CB/ CB is for my ChannelBox Widget. I'm having issues because I think what I came up with was correct, but I'm missing something... Can someone help me out with this? Maybe provide a few answers or a script that summarizes what I'm trying to achieve?




Thank you for at least taking the time to look this post! Any comments are appreciated and would probably be helpful!

-Criso

Replies

  • Ben Apuna
    I don't know MEL... gonna take a wild guess...
    global proc ToggleMergeToolbar() {
    
    global string $TestIt;
    global string $MergeWndDisplay;
    $TestIt = `paneLayout -q -vis MergeWindow`;
    
    if ($TestIt == 0) {
    
    	$MergeWndDisplay = "on";
    	paneLayout -e -vis 1 MergeWindow;
    	button -e -l "->" -c "ToggleMergeToolBar;";
    
    } else if ($TestIt == 1) {
    
    	$MergeWndDisplay = "off";
    	paneLayout -e -vis 0 MergeWindow;
    	button -e -l "<-" -c "ToggleMergeToolbar;";
    
    	if (`dockControl -ex CB`) {
    
    		dockControl -e -w 400 CB;
    	}
    }
    
    }
    
    [MergeWindow]
    
    

    You've got
    }
    button -e -l "<-" -c "ToggleMergeToolbar;";
    }
    

    dangling out there by itself when it looks like it should be run if $TestIt == 1 since button -e -l "->" -c "ToggleMergeToolBar;"; is run if $TestIt == 0

    Good luck, hope that helps :)
  • crisosphinx
    Nah, I have it set up so the button replaces the previous button.

    Currently, I have my script working EXCEPT that it cannot find an object in my script. Apparently, it's looking for the object "MergeWindow" which is a procedure I have stated before it. So I'm not really understanding what I'm missing...

    Thank you for the idea though! I might try to mess around with it if I get it working and my replaced button doesn't show. :)

    -Criso
  • Ben Apuna
    Okay, here are some other possible problems that I see now.

    (also: it might be pedantic, and more typing, but personally I'd type out the full names of parameters like -edit rather than -e, -command rather than -c. It makes the code a lot easier to understand IMHO.)

    NOTE:
    Red code means how the code was originally.
    Green code means what the code should be changed to.
    (I hope you're not colorblind... If so sorry in advance.)
    global proc ToggleMergeToolbar() {
    
    // $TestIt is being compared to integer values below rather than strings
    // so it seems better to declare it as a int type. Also it probably shouldn't
    // be a global unless you are using it outside of ToggleMergeToolbar(),
    // possibly the same for $MergeWndDisplay...
    [COLOR="Red"]global string $TestIt;[/COLOR]
    [COLOR="Lime"]int $TestIt;[/COLOR]
    [COLOR="Red"]global string $MergeWndDisplay;[/COLOR]
    [COLOR="Lime"]string $MergeWndDisplay;[/COLOR]
    
    // If MergeWindow is a variable declared somewhere I think it needs a "$"
    // in front of it.
    [COLOR="Red"]$TestIt = `paneLayout -query -visible MergeWindow`;[/COLOR]
    [COLOR="Lime"]$TestIt = `paneLayout -query -visible $MergeWindow`;[/COLOR]
    
    if ($TestIt == 0) {
    
    	$MergeWndDisplay = "on";
    	// Possibly the same missing "$" deal as above...
    	[COLOR="Red"]paneLayout -edit -visible 1 MergeWindow;[/COLOR]
    	[COLOR="Lime"]paneLayout -edit -visible 1 $MergeWindow;[/COLOR]
    	button -edit -label "->" -command "ToggleMergeToolBar;";
    
    } else if ($TestIt == 1) {
    
    	$MergeWndDisplay = "off";
    	// Possibly the same missing "$" deal as above...
    	[COLOR="Red"]paneLayout -edit -visible 0 MergeWindow;[/COLOR]
    	[COLOR="Lime"]paneLayout -edit -visible 0 $MergeWindow;[/COLOR]
    	// I still think you should put this here or else it'll always execute
    	[COLOR="Lime"]button -edit -label "<-" -command "ToggleMergeToolbar;";[/COLOR]
    
    	if (`dockControl -exists CB`) {
    
    		dockControl -edit -width 400 CB;
    	}
    }
    
    // If you leave this here like so it'll always change your button's
    // label to "<-" even if ($TestIt == 0) is true.
    [COLOR="Red"]button -edit -label "<-" -command "ToggleMergeToolbar;";[/COLOR]
    }
    
    // Is this where the declaration of MergeWindow is in your .mel file?
    // If so you might want to place it above the ToggleMergeToolbar() procedure.
    //
    // The reason being: if Maya interprets MEL line by line from top to bottom
    // then it might not understand what "MergeWindow" is when it first encounters
    // it within the ToggleMergeToolbar() procedure above.
    //
    // I don't know if that's really how Maya interprets MEL, but some other
    // programming languages are picky about such things.
    [MergeWindow]
    

    If none of that helps post up all of your code. It'll be easier to see what's going on that way.
  • Ben Apuna
    Oops! I almost forgot to mention some MEL tutorials that I've run across that might be useful to you:

    http://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/mel/index.html
    http://ewertb.soundlinker.com/mel/mel.095.php
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    You mind posting or pming the code? For example:
    button -e -l "<-" -w 260 -h 32 -c "ToggleMergeToolbar";
    

    You cannot edit a button when you are creating it.
  • crisosphinx
    Hey guys, thank you for getting back with me.

    I had done a revamp of everything that I had listed (I realized I posted some incorrect code and proceeded to check things and fix them). Still having an issue, but I'll get to that in a moment. At the time I posted this, I was stressed out beyond all reason so I'm sorry that some of the code seems flaky, I was just not thinking straight at this point in time. That aside...


    I would like to keep some of the code confidential, so instead of posting it up, I'll PM it to you guys. It's nothing special, I just would like to keep some of it somewhat private.



    Ben,thank you for the suggestions. I'll try to implement them with the original code and see if it works. I used global strings because I have a couple strings that needed to be repeated a few times within the code. So, it was outside of just that toolbar. I've only been coding for about a month, mel script being the first thing I learned and python being the second. I've previously studied a bit of both of those websites, very helpful. I'm not sure how I'm doing after a month of programming...



    Haiddasalami Yeah, I realized afterwards that I was being a bit stupid on that portion. I'll PM you.
  • crisosphinx
    Ben Apuna wrote: »
    (I hope you're not colorblind... If so sorry in advance.)

    That would be fun if I was. ;D
Sign In or Register to comment.