Home Technical Talk

MEL local procedures?

polycounter lvl 15
Offline / Send Message
ivars polycounter lvl 15
Hey, I'm a MEL noob, so maybe someone can help me.

I've got this script with two procedures.
One is global, and it creates the window with my fields and buttons the other one is the action that runs when you hit the apply-button.

I thought I'd make the second one local, but it doesn't work. Tried adding it before the global proc as well, but no difference. It just say error: can't find procedure "procedureName"

I've saved the script as a .mel file, sourced it, and I launch it by calling the global proc.

It works if I make both global though.... must be missing something.

Replies

  • Quillisia
    Options
    Offline / Send Message
    As far as I know, procedures that are called from an UI element need to be global.

    I ran into this problem before myself and was told as such.
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Yeah, any procedure to be called from a UI button has to be global.
  • ivars
    Options
    Offline / Send Message
    ivars polycounter lvl 15
    Well that explains it :D

    Thanks.
  • animatr
    Options
    Offline / Send Message
    animatr polycounter lvl 18
    ***edit***
    ah, i see. I missed the part where you said how you are running it. if that is the case, than yes, it needs to be global. there are still ways to get around it, but it's a bit silly.
    ***end edit***

    you can certainly have them be local, if they are contained in the same script. how are you running it? for UIs, I usually use script nodes to embed them in the rig file. I've never had a problem when I've done it that way.


    I'll post an example snippet here:




    /////////////////////////////////////////////////////////////////////////////////////////////


    proc ExampleOfLocal ()
    {
    polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;;
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    if (`window -ex ExampleGUI`) deleteUI ExampleGUI;

    window
    -title "ExampleGUI"
    -widthHeight 150 150
    ExampleGUI;


    scrollLayout -horizontalScrollBarThickness 0 -verticalScrollBarThickness 1 ;
    string $tabs = `tabLayout ExampleTabs`;

    //declaring variables
    string $ExampleImage = `internalVar -userPrefDir` + "icons/ExampleImg.jpg";

    string $tab1= `columnLayout -w 150 -h 150`;
    string $form = `formLayout`;

    //creating the buttons

    string $AnExample= `iconTextButton -style "iconOnly" -image $ExampleImage -label " " -w 50 -h 50 -command "ExampleOfLocal ;" `;

    window -e -wh 150 150 ExampleGUI;

    showWindow ExampleGUI;
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Oh, another tip, for people unaware of it (and I've met some seasoned Maya users who didn't know!), if your procedure name is the same as the .mel file name, you don't have to source it or anything, it will load automatically.

    Eg. a "global proc myProc()" declaration in "myproc.mel" (case insensitive) in any of your Maya default script locations can be run just by calling "myProc" instead of having to source it or otherwise load it first.

    edit: Jeremy, how good are script nodes? Do you find them very useful for rig controls? I've never really looked into using them, so I don't really understand all that much, I guess you can just tell them to be executed when the file is opened/closed/saved? In that case if you have a whole UI in script node form, do you need to call commands to destroy it on file close etc.?

    Also, I hope you don't comment your real files like that ;)
  • animatr
    Options
    Offline / Send Message
    animatr polycounter lvl 18
    hehe, no. I just whipped something up real quick. hopefully it wasnt too confusing.

    I love script nodes. usually, for rig UIs, I dump all of the code into a new script node, and at the very end, after showWindow exampleWindow;
    I just throw a call to the global proc for the UI
    exampleUI;

    then there are options in the script node for setting it to open on file open(what I usually choose) or open on demand.(like calling the global proc in the command line)

    this method is also much nicer for animators who refuse to copy over your scripts or put them in the wrong place. there is nothing to copy here(except UI images if you have any)

    hope that helps. I can whip up a more clear explanation/mini tut if need be

    cheers
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Nah, that sounds pretty cool. I guess it all still works ok if your rig has script nodes in it, and you reference that rig file into your main animation scene? You can still execute referenced script nodes as usual?
  • animatr
    Options
    Offline / Send Message
    animatr polycounter lvl 18
    I haven't tried referencing, but I think it would work. Importing into a scene works though. it's just like having a cube in a scene, or any node. It should all come over.
Sign In or Register to comment.