[maya][mel] get mesh from material

maya mel get mesh from material

hyperShade -objects materialName;
//結果のmeshは選択される

Function



global proc string get_MeshTransform_from_Material_v2(string $mat){   
   string $selected[];
   //選択を取っておく
   $selected =`ls -sl`;
   string $mesh_arr[];
   //$mesh_arr =`hyperShade -objects $mat`;
   //結果のmeshは選択されるので
   hyperShade -objects $mat;
   //選択からとる
   $mesh_arr =`ls -sl`;
   int $mesh_arr_len=size($mesh_arr);
   string $returnStr;
   print("$mesh_arr_len= "+$mesh_arr_len+"\n");
   if($mesh_arr_len==0){
       $returnStr="";
   }else{
       print("$mesh_arr= "+ stringArrayToString($mesh_arr, ", ") +"\n");
       string $mesh= $mesh_arr[0];
       string $trans_arr[] = `listRelatives -noIntermediate -fullPath -parent $mesh`;
       print("$trans_arr= "+ stringArrayToString($trans_arr, ", ") +"\n");
       $returnStr=$trans_arr[0];
   }
   //選択を戻す
   select -cl;
   string $sel;
   for($sel in $selected){
       select -add $sel;
   };
   return $returnStr;
}