Home Technical Talk

How to Select Smoothed Polygons through MEL in maya?

I am new to the 3d field , learning maya at present. I am trying to develop a script , one of the module aims at separating smoothed polygonal objects.

i am having problem in separating the smoothed polygons , though i have stored all the polygons in a an array.

Need help with it , plz help me.........:(

Replies

  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    By "smoothed polygons", do you mean polygons that have been physically subdivided using the "Smooth" method (resulting in a polySmooth node in the History), or just polygons sharing soft edges?
  • dip_land
    Actually, the script at which i am working aims at selecting a particular set objects in a given scene and apply smooth on them through the "polySmooth" command. I want the script to have functionality of listing objects on which smooth was previously applied and apply smooth on rest of the objects(leaving previously smoothed objects as they are). I was thinking of searching the history of selected object for polySmooth node but don`t know the proper method or command. If there is any other better way please guide me.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    Nope, that sounds like a pretty good method.

    So I guess you can get all objects, then use the listHistory command to find out if there are any polySmooth nodes. If there aren't any found, just call the polySmooth command for that object.

    It should be pretty straightforward - here's some example code (not 100% guaranteed to work since I don't have Maya here):
    string $transforms[] = `ls -tr`;
    for ( $transform in $transforms )
    {
        string $meshes[] = `listRelatives -ad -ni -type "mesh" $transform`;
        if ( `size $meshes` == 0 )
            continue;
        
        int $found = 0;
        string $history[] = `listHistory $meshes[ 0 ]`;
        for ( $node in $history )
        {
             if ( `nodeType $node` == "polySmoothFace" )
             {
                  $found = 1;
                  break;
             }
        }
        if ( !$found )
            polySmooth $meshes[ 0 ];
    }
    
    That might work.
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    Close MoP,

    the "nodeType $node == polysmooth" is wrong, the correct command is. Well I gotta get in front of the computer as they don't have maya for iPod.

    Also you forgot the "$", on found. Other than that, it will work.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    Good catch on the missing $, Lamont. Fixed in the code above now.

    Ah, and yeah, it's "polySmoothFace", not just "polySmooth". Fixed that too.
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    No, it's only the polysmooth command that is wrong. As it reads, it will smooth everything. The node that is listed in the history isn't polysmooth. It's missing one more word, like polysmoothXXXX. I ran into this before as the command it is looking for isn't in the documentation.
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    Sorry, edited while you were replying. Well spotted :)

    Here's a version that just selects instead of smoothing:
    string $transforms[] = `ls -tr`;
    string $result[] = {};
    for ( $transform in $transforms )
    {
        string $meshes[] = `listRelatives -ad -ni -type "mesh" $transform`;
        if ( `size $meshes` == 0 )
            continue;
        
        int $found = 0;
        string $history[] = `listHistory $meshes[ 0 ]`;
        for ( $node in $history )
        {
             if ( `nodeType $node` == "polySmoothFace" )
             {
                  $found = 1;
                  break;
             }
        }
        if ( !$found )
            $result[ `size $result` ] = $transform;
    }
    
    select -r $result;
    
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    Both work if you just change it to "polySmoothFace", now just need a checkbox for if you want to smooth on selected or not.

    You saved me from getting out of bed MoP :D!! Too cold!
  • dip_land
    Thank you MoP.

    I kinda figured out the node "polySmoothFace" and the "$found" errors myself, may be what i just needed the most was proper method of using listHistory command.

    i missed the listHistory command while running through the HelpDocs , be`coz i did`nt new the proper method.

    I completed my script and it works just fine. I used the following code, for separating the previously smoothed objects from the selected objects ,

    string $polySel[]=`listRelatives -ad -ni -type "mesh" $objSel`;
    int $objFound = 0;
    string $history[] = `listHistory $polySel[ 0 ]`;
    for ( $node in $history )
    {
    if ( `nodeType $node` == "polySmoothFace" )
    {
    $objFound = 1;
    $prevSmooth[$i]=$polySel[0];
    $i++;
    break;
    }
    }

    $objSel, refers to the selected object
    $prevSmooth, refers to the objects previously smoothed

    i am happy to get something like PolyCount forum,

    Thank you once again for replying to both of you, Mop and Lamont.
Sign In or Register to comment.