Mesh Query Script

Simple script for adding meshes to vertices of another mesh.

Programming Language(s): Maya Environment Language (MEL)

A script that queries the selected vertices of a mesh and stores the information in a variable. Uses various parts of the query to generate the appropriate number of meshes to be added to the selected vertices, move those meshes into place, constrain the newly created meshes to the vertices and parent them to the base mesh so they can be moved as a group.

MEL Script

/*
ModMultiPurposeQueryMesh.mel

Procedures suitable for querying objects.
*/

string $verPos;
vector $trans;
string $sel[], $selPrim[], $grouping[];

//Beginning of Procedures---------------------------------------------------------------------------------------- 

global proc selectVertices(string $sel[], string $selPrim[]) 

     PolySelectConvert 3; 
     string $sel[] = `filterExpand -ex true -sm 31 -sm 28`; 
     string $selShape[] = `listRelatives -p $sel[0]`; 
     string $selPrim[] = `listRelatives -p $selShape`; 


global proc geometry(string $grouping[]) 

     string $grouping[] = `polySphere -r 0.1`; 


global proc trans(vector $trans, string $sel[], string $grouping[]) 

     for ($i=0; $i < size($sel); $i++) 
     { 
         vector $trans = `xform -q -ws -t $sel[$i]`; 
         move ($trans.x)($trans.y)($trans.z) $grouping[0]; 
     } 


global proc constrainGeo(string $sel[], string $selPrim[], string $grouping[]) 

     for ($j=0; $j < size($sel); $j++) 
     { 
         aimConstraint -aim 0 1 0 $selPrim $grouping[0]; 
     } 


global proc groupMoveGeo(string $sel[], string $selPrim[], string $grouping[], string $verPos, vector $trans) 

     string $geo[]; 
     for ($k=0; $k < size($sel); $k++) 
     { 
         geometry($grouping); 

         //move spheres to verts
         trans($trans, $sel, $grouping); 

         //constrain sphere to verts
         constrainGeo($sel, $selPrim, $grouping); 

         //conform spheres to follow
         $verPos = ("vector $xyz;" + "\n" + "$xyz=" + ("`xform -q -ws -t " + $sel[$k] + "`") + "; \n" + 
         "setAttr " + $grouping[0] + ".translateX " + "($xyz.x);" + "\n" + 
         "setAttr " + $grouping[0] + ".translateY " + "($xyz.y);" + "\n" + 
         "setAttr " + $grouping[0] + ".translateZ " + "($xyz.z);"); 
         //print ($verPos + "\n"); 
         expression -s $verPos; 

         $geo[$k] = $grouping[0]; 
         //print ($geo[$i]); 
     } 
     group -n qMeshGroup $geo; 


selectVertices($sel, $selPrim); 
groupMoveGeo($sel, $selPrim, $grouping, $verPos, $trans);