# snapVertexToGrid.mel Maya 2010?

**URL:** https://forum.highend3d.com/t/snapvertextogrid-mel-maya-2010/587
**Category:** Maya
**Tags:** mel
**Created:** [January 31, 2011, 7:08am UTC](https://forum.highend3d.com/t/snapvertextogrid-mel-maya-2010/587 "2011-01-31T07:08:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![q-s--2](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/q/76d3ee/32.png) [@q-s--2](https://forum.highend3d.com/u/q-s--2)
#### Post date: [January 31, 2011, 7:08am UTC](https://forum.highend3d.com/t/snapvertextogrid-mel-maya-2010/587/1 "2011-01-31T07:08:22Z")

</div>

Hi,

Im looking to move every selected vertex to it's nearest grid point in Maya i found this script does anybody knows if it would work with Maya 2010? i can't make it work myself

Thanks

// snapVertexToGrid.mel  
// by Naughty (naughty\_genepool@hotmail.com)  
//  
// This script simply moves every selected vertex to it's nearest grid point&nbsp;  
// (based on current grid settings).  
//  
// Usage:  
//  
// snapVertexToGrid;  
 // moves every selected vertex to it's nearest grid point  
//  
//  
// goto:  
// [http://www.naughtynathan.supanet.com/mel.htm](http://www.naughtynathan.supanet.com/mel.htm)  
// for more detailed explanations, pictures and even more MEL scripts...

global proc snapVertexToGrid()  
{  
float $gridSpace = `grid -q -sp`;  
float $gridSubD = `grid -q -d`;  
float $gridSize =($gridSpace/$gridSubD);  
// print ("grid size: " + $gridSize + "\n");

string $selVerts[] = `filterExpand -fullPath 1 -expand 1 -sm 31`;  
if(!size($selVerts)) error "No Vertices selected!\n";  
for ($vertex in $selVerts)  
{  
float $xyzPos[] = `xform -q -ws -a -t $vertex`;  
// print ("X position: " + $xyzPos[0] + "\n");  
// print ("Y position: " + $xyzPos[1] + "\n");  
// print ("Z position: " + $xyzPos[2] + "\n");

$xyzPos[0] = $gridSize \* ( int( ( $xyzPos[0] + $gridSize / 2.0 \* `sign $xyzPos[0]` ) / $gridSize ) );  
$xyzPos[1] = $gridSize \* ( int( ( $xyzPos[1] + $gridSize / 2.0 \* `sign $xyzPos[1]` ) / $gridSize ) );  
$xyzPos[2] = $gridSize \* ( int( ( $xyzPos[2] + $gridSize / 2.0 \* `sign $xyzPos[2]` ) / $gridSize ) );

xform -ws -a -t $xyzPos[0] $xyzPos[1] $xyzPos[2] $vertex;  
}  
}

---

<div class="post-metadata">

### Author: ![nowayfra](https://forum.highend3d.com/user_avatar/forum.highend3d.com/nowayfra/32/76_2.png) [@nowayfra](https://forum.highend3d.com/u/nowayfra)
#### Post date: [January 31, 2011, 10:20am UTC](https://forum.highend3d.com/t/snapvertextogrid-mel-maya-2010/587/2 "2011-01-31T10:20:57Z")

</div>

The author of this script resides at cgsociety if you want to ask him. But i doubt it would be nesseccary. I guess you pasted the script into your Script Editor and executed it as it is? If so you only make maya familiar with the procedure, you do not execute the script this way. To execute it select your vertices and just type

snapVertexToGrid();

---

<div class="post-metadata">

### Author: ![q-s--2](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/q/76d3ee/32.png) [@q-s--2](https://forum.highend3d.com/u/q-s--2)
#### Post date: [January 31, 2011, 8:32pm UTC](https://forum.highend3d.com/t/snapvertextogrid-mel-maya-2010/587/3 "2011-01-31T20:32:06Z")

</div>

Hi,&nbsp;

Thanks so much for your answer that made it work!!!
