Home Technical Talk

Simple(?) MEL Script

interpolator
Offline / Send Message
jStins interpolator
I am attempting to write what I assume is a pretty simple mel script to achieve this behavior:

• Select shortest edge path based on current selection of two verts
• Switch to edge component mode
• Set selected edges to hard

I got as far as finding this: polySelect -shortestEdgePath 10 100 pPlane1;, but got stuck trying to query the selected verts / object. I can get vertex numbers using string $objects[]=`ls -sl -fl`;, but cant sort out how to use those values in the -shortestEdgePath command. I'd be grateful for any assistance.

I'd also appreciate any recommendations on good resources for learning mel script. I don't want to go full tech artist, but I'm finding myself more and more frustrated with repetitive tasks / key strokes. I'd love to learn enough to automate simple, repetitive tasks. Thanks!

Replies

  • Klaudio2U
    Offline / Send Message
    Klaudio2U polycounter lvl 8
    Here it is a quick one. Probably could be done better and with fewer lines but....
    Just select two vertices and run the script, should work:


    // get two selected vertices
    string $compSel[]= `ls -sl -fl`;
    // get object name 
    string $objSel[] = `ls -hilite`;

    // get  the number of first sel vertice
    string $buffer1[];
    $numTokens1 = `tokenize $compSel[0] ".[]" $buffer1`;
    print $buffer1[$numTokens1 -1]; // print last item in array

        // make number as int 
        int $firstVert = $buffer1[$numTokens1 -1];

    // get number of second selected vertice
    string $buffer2[];
    $numTokens2 = `tokenize $compSel[1] ".[]" $buffer2`;

        // make number as int 
        int $secondVert = $buffer2[$numTokens2 -1];

    // enter edge selection mode
    dR_DoCmd("modeEdge");
    // clear selected edges - if there is any from before
    select -cl;

    // select the path
    polySelect -shortestEdgePath $firstVert $secondVert $objSel[0];

    // make edges hard
    SoftPolyEdgeElements 0;
  • [Deleted User]
    Offline / Send Message
    [Deleted User] insane polycounter
    The user and all related content has been deleted.
  • jStins
    Offline / Send Message
    jStins interpolator
    Awesome! Thanks @Klaudio2U. The script works and the comments are really helpful in giving me more to dig into. Cheers! 
  • throttlekitty
    I don't know about the others, but I've learned the most from reading through the docs and taking apart scripts that others have written. And a lot of googling and reading old forum threads, looking for similar solutions or suggestions like: "Oh you want to [thing]? Try doing [keyword to research further] like this..."
  • Klaudio2U
    Offline / Send Message
    Klaudio2U polycounter lvl 8
    Glad you find it useful. ;)

    For learning basically this:
     throttlekitty said:
    I don't know about the others, but I've learned the most from reading through the docs and taking apart scripts that others have written. And a lot of googling and reading old forum threads, looking for similar solutions or suggestions like: "Oh you want to [thing]? Try doing [keyword to research further] like this..."
    The best way is to have some sort of a project, script you want to do and then llearn how to do it by google it around with "maya mel.....". 
    The book are ok to look a bit but i didn't find it super useful so just check YouTube and/or Vimeo instead. 
Sign In or Register to comment.