//Used for finding nodes like skinning blendshape etc

//for getting selections like get vertices from a polygon selection

//Last Modified: Nov 23, 2011

//By: Nathaniel Anozie ogbonnwork at gmail dot com

////given string array of node and node type return array for name first occurence of node type

/*

    /////

    string array of node

    ex: [blendNode, tweakNode, shapeNode]

   

    string node type: tweak, blendShape

    /////

*/

global proc string[]

getFirstHasNodeType(string $nodeArray[], string $nodeType)

{

    string $result[];

    int $i= 0;

    string $tempType;//store node type of loop element,cleared on every step

    //loop nodes of input

   

    for ($i=0;$i< size($nodeArray); $i++)

    {

        $tempType = `nodeType $nodeArray[$i]`;

        //if found matching node return it

        if( $tempType == $nodeType  )

        {

            $result[0] = $nodeArray[$i];

            break;

        }

    }

 

    return $result;

}

/////return vertices given a polygon selection

/*

often user may need to user vertices from a polygon selection

this script helps with returning that

*/

global proc string[]

getVtxFromPoly(string $poly)

{

    string $result[];

    string $sel[] = `ls -sl`;

   

    //will be altering user scene

    //with constaint command

    //so added check necessary

    if(`objExists $poly`){

        print "hii";

        select -cl;

        select -r $poly;

        polySelectConstraint -type 0x0001 -shell true -m 3;//mode no constraint used

        string $expanded[] = `ls -sl`;

        $result = `filterExpand -sm 31 -expand true`;

        polySelectConstraint -shell false;

        select -cl;

        select -r $sel;

    }

    else

    {

        warning("no poly exists");

    }

    return $result;

}

/////give me the first index where input value matches input search array (returns int array)

//it behaves alot like pythons list.index(value) function, where search array acts as list

//it returns empty array if no index match found

/*

needs arguments

value           string

searchArray     string array

*/

global proc int[]

naIndex(string $value, string $searchArray[] )

{

    int $result[];

   

    //loop search array

    for($i=0; $i < size($searchArray); $i++){

        //if match found store index and break out of loop

        int $matchValue = strcmp($value, $searchArray[$i]);

        if(  $matchValue == 0 )

        {

            $result[0] = $i;

            break;

        }

    }

   

    return $result;

}