Home Technical Talk

Mel Help

polycounter lvl 14
Offline / Send Message
haiddasalami polycounter lvl 14
Hey been working on a pivot tool for maya just so it makes it easier to put the pivot easier for common areas. I have that all up and running though where I'm running into a problem is putting the pivot on a selected vertex. I get the xform of the vertex but my problem is how would I split the selection array.

Example:

string $selection[] = `ls -sl`;
this prints for example pSphere1.vtx[300];

how would I terminate pSphere1.vtx[300] to just the object name unless theres a way I can get the name of the object another way? Would defintiely like to hear some other ways. I tried doing a string to string array but apparently mel will not let me do that :(

Looked a bit into the list command and saw there is a way to get all objects in the scene and the one that caught my eye was the tail flag so I might be able to use that to see what the last one selected was...on the bus home so gonna try that.

Replies

  • claydough
    Options
    Offline / Send Message
    claydough polycounter lvl 10
    mel code
    [php]
    {
    string selection[] = `ls -sl`;
    string $selObject[] = `ls -o $selRequirement`;
    print $selObject;
    }
    [/php]
  • claydough
    Options
    Offline / Send Message
    claydough polycounter lvl 10
    how would I terminate pSphere1.vtx[300] to just the object name unless theres a way I can get the name of the object another way? Would defintiely like to hear some other ways

    technically you can actually have a component selected without being "hilite"-ed
    and or have a hilite ed object without having a component or object/component selection of any kind.
    Otherwise... n( and normally if not bulletproof )

    $selection[] = `ls -hl`;


    will return your pSphere1.vtx as pSphere1
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Cool thanks Claydough. I found out about the filterexpand command though from the looks of it you can't store it into an array or maybe I'm doing something wrong but the ls -hl worked.

    PS The Mel code you have there, is $selRequirement just polygon as a string? Cause I looked through the doc and couldn't find anything besides just the flag by itself.
  • claydough
    Options
    Offline / Send Message
    claydough polycounter lvl 10
    Cool thanks Claydough. I found out about the filterexpand command though from the looks of it you can't store it into an array or maybe I'm doing something wrong but the ls -hl worked.

    for example: a poly -sm 12 filterExpand will only return objects if an object is selected.
    If using your pSphere1.vtx[300] selection as an example... nothing will be returned if that object is not in object mode.

    filterExpand will return an array.. depending on your selection you may need to use the -expand "true" flag to assign every member it's own address.

    filterExpand -sm 31 expand 0; will return poly.vtx[0:1]
    whereas,
    filterExpand -sm 31 expand 1; will return each to it's own addy ( poly.vtx[0] poly.vtx[1] )
    depending on which version of Maya you have... I believe the latest versions of Maya will expand by default.

    PS The Mel code you have there, is $selRequirement just polygon as a string? Cause I looked through the doc and couldn't find anything besides just the flag by itself.

    nope, I made 2 lazy copyPaste errors. It should have reflected yer code like:
    {
    string $selection[] = `ls -sl
    `;
    string $selObject[] = `ls -o $selection
    `;
    print
    $selObject
    ;
    }
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Thanks for that writeup Clay.
  • Bal
    Options
    Offline / Send Message
    Bal polycounter lvl 17
    Just out of curiosity, what exactly are you making the pivot do?
    Isn't setting a pivot on a vertex just a matter of holding d (pivot mode) and v (vertex snap) and middle clicking over the vertex you want?
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    @Bal: Making a tool to simplify placing pivots. So for example if you want it at bottom left just click bottom left and pivot is there and can also do mass pivot moves. Wanted selected vertex for meshes where they arent square otherwise I would just use the bounding box.
  • Warheart
    Options
    Offline / Send Message
    Warheart polycounter lvl 17
    Bit late to the party here but going from the problem in the initial post -- if for some reason you need to get the object name when all you have is the vertex name (e.g. "pSphere1.vtx[300]") then you can do that with just a bit of string manipulation.

    string $vertName = "pSphere1.vtx[300]";
    string $objName = `match "^[^\.]*" $vertName`;
    print ($objName + "\n");
    // prints "pSphere1"

    The "match" and "tokenize" functions are really good for doing this sort of thing
Sign In or Register to comment.