MEL Syntax

polycounter lvl 5
Offline / Send Message
Bartalon polycounter lvl 5
Hey everyone,

I've been teaching myself MEL scripting but I'm sort of stuck on a particular syntax. I've searched all over for my specific problem but I'm not sure which key words I should be searching for and can't find anything, so thank you in advance to anyone who can help.

I have a button setup with a command within parentheses, however this seems to only be good for a single command. The portion of code in bold is what I'm having issues with. I need to keep this parenthetical format but also have it work with two or more commands. An example would be to have the command delete $materials[$i] as well as print "Deleted " + $material [$i];
button -label "D" -bgc .5 0 0 -command [B]( "delete " + $materials[$i] )[/B];
Normally I would just put the whole command inside quotations, however doing so seems to break the scope of my variables which kicks out an error about how $materials and/or $i are undefined.

Replies

  • passerby
    Offline / Send Message
    passerby polycounter lvl 6
    use the ' key the one that is on the same key as ~ not the other one to encase the command.
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 5
    I've tried every method I understand to try to get this -command flag to accept more than one line of code but I've never had to write a script this way, so I can't figure it out. In this case, if you could provide an example line of code it would help me immensely with how to write the rest of my scripts.

    Below is an operable chunk of my code if that helps anyone better understand what I'm trying to accomplish.

    The line in green has the exact same syntax as the line in orange; they both work just fine as is, but my hangup is getting the orange line to contain multiple commands using the same syntax: for instance, having it print two separate times.



    You should just be able to throw this into Maya's Script Editor and run/edit it that way.
    
    global proc matList() {
    
    if (`window -exists materialList`)
    {
        deleteUI materialList;
        windowPref -remove materialList;
    }
    
    $remove = { "particleCloud1" };
    $mats = `ls -mat`;
    $materials = stringArrayRemoveExact($remove, $mats);
    $count = `size $materials`;
    
    window -title "Material List" -w 275 -h 400 materialList;
        string $scrollLayout = `scrollLayout
            -horizontalScrollBarThickness 16
            -verticalScrollBarThickness   16`;
    gridLayout -numberOfColumns 1 -cellWidthHeight 250 25;
        button -label "Refresh" -command "matList;";
        setParent..;
    columnLayout -w 250 -h 50;
        text -w 300 -h 50 -label "   Material List                      Assign/Select";
    setParent..;
    gridLayout -numberOfColumns 1 -cellWidthHeight 250 ( $count * 25 + 25 );
        gridLayout -numberOfColumns 2 -cellWidthHeight 200 ( $count * 25 );
            gridLayout -numberOfColumns 1 -cellWidthHeight 175 25;
                for ( $i=0; $i<$count; ++$i )
                {
                    text -label $materials[$i];
                }
                setParent..;
            gridLayout -numberOfColumns 2 -cellWidthHeight 25 ( $count * 25 );
                gridLayout -numberOfColumns 1 -cellWidthHeight 25 25;
                    for ( $i=0; $i<$count; ++$i )
                    {
                        [COLOR=SeaGreen]button -label "A" -command ( "hyperShade -assign " + $materials[$i] );[/COLOR]
                    }
                    setParent..;
                gridLayout -numberOfColumns 1 -cellWidthHeight 25 25;
                    for ( $i=0; $i<$count; ++$i )
                    {
                       [COLOR=DarkOrange] button -label "S" -command ( "select " + $materials[$i] );                 [/COLOR]}
                    setParent..;
                setParent..;
            setParent..;
        setParent..;
    
    showWindow materialList;  
    
    }
    
    matList;
    
    
  • PolyHertz
    Offline / Send Message
    PolyHertz polycounter lvl 10
    You have to create a procedure to have a single command execute multiple other commands. for example:

    global proc testing(){print "words \n"; print "more words";}
    print (`testing`);
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 5
    I tried that too! The proc was outside of the scope of $materials[$i] and kicked out undefined variable errors. I don't know how to make that work either.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 7
    Its been a while since I've done Mel but this should work. Basically concatenating a whole command into String. Nice idea btw.
        for ( $i=0; $i<$count; ++$i )
        {
            string $command = "hyperShade -assign " + $materials[$i] + "; print (\"My cool second command\")";                     
            button -label "A" -command ($command);
        }
    
  • Bartalon
    Offline / Send Message
    Bartalon polycounter lvl 5
    That's exactly what I needed! Thanks! I'm going to post my script when I'm all done.
Sign In or Register to comment.