Home Technical Talk

MEL Scripting help

greentooth
Offline / Send Message
CheeseOnToast greentooth
When character modeling I tend to use mostly Silo/Zbrush/UVlayout and avoid Maya until the very last cleanup and export stages of a model. Recently I'm doing a lot more environment work where I pretty much have to use Maya for the majority of the process. It feels horribly clunky after using Silo for so long, so I'm looking to try to replicate some of Silo's functionality into Maya via mel scripts. Unfortunately I'm no scripter, beyond cobbling together some bits from the script editor. Hopefully some of the fine Mel gurus here can help.

The main thing I'd like to do is make a bunch of Maya's tools more context-sensitive, presumably using IF/THEN/ElSE type scripts. For example :

Hotkey "M"

Context 1 : Two or more shells selected in object mode - perform polygon combine
Context 2 : Two or more vertices selected - perform merge to center
Context 3 : Two or more UVs selected - perform merge
Context 4 : Two edges selected - Bridge edges

Hopefully you get the idea. Is it possible to do this?

Replies

  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Yaeh, it's possible to do this.

    Basically you start with the "most likely" case (well, it doesn't really matter what order, but I do it that way since it makes more sense to me), test for it, and if the test passes then execute that part of the script.

    So in your case here I'd have something like this:
    global proc MyAwesomeContextButton()
    {
        // Get all selected transforms.
        string $transforms[] = `ls -sl -l -tr`;
        
        // If we have transforms selected, continue...
        if ( `size $transforms` )
        {
            string $meshes[];
            for ( $transform in $transforms )
            {
                // Check if they've got polygon mesh shape nodes.
                if ( size( `listRelatives -ad -ni -s -type "mesh" $transform` ) > 0 )
                {
                    $meshes[ `size $meshes` ] == $transform;
                }
            }
            // If we have more than one mesh selected, combine 'em!
            if ( size( $meshes ) > 1 )
            {
                // Insert combine function here
            }
            // Get out of the function now since we don't want to do anything else.
            return;
        }
        
        // Now check vertices...
        if ( size( `filterExpand -sm 31` ) > 1 )
        {
            // Insert merge to centre function here since we know we now have more than one poly vert.
            return;
        }
        
        // Now check edges...
        if ( size( `filterExpand -sm 32` ) > 1 )
        {
            // Insert bridge edge function here since we know we now have more than one poly edge.
            return;
        }
        
        // Now check UVs...
        if ( size( `filterExpand -sm 35` ) > 1 )
        {
            // Insert merge UV function here since we know we now have more than one UV vert.
            return;
        }
    }
    

    Something to bear in mind is that you can sometimes have multiple conditions be true (eg. I might have 2 vertices selected, but also have a couple of whole objects selected at the same time), so you might also want to have checks in for those situations and handle appropriately.
    Otherwise you might find yourself merging objects when you wanted to merge verts...
  • CheeseOnToast
    Options
    Offline / Send Message
    CheeseOnToast greentooth
    Cheers mop, good to know it's do-able. I'll take a look at it myself, or more likely get one of the coders to sort something when we have a bit of down time.
  • Lamont
    Options
    Offline / Send Message
    Lamont polycounter lvl 15
    Cheers mop, good to know it's do-able. I'll take a look at it myself, or more likely get one of the coders to sort something when we have a bit of down time.
    Well all you have to do now is just open the script editor and copy and paste the procedure (with the params you want) you want to perform where MoP put the quotes/comments to do so. Most things are visible, but if you think you're missing something turn on echo all commands.
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Disclaimer: I just wrote this in notepad and didn't actually test it, but at a glance I think it should work. If nothing else it will point you in the right direction :)
Sign In or Register to comment.