Randomise Vertex Position – [Maya]

So I found a great little script here that will randomise the vertex positions in all the axis depending on how much you want it to, check it out below!

$mySelection = `ls- sl`;
$myVerts = `getVerts`; // this command grabs all the vertices of selected objects and put into a string array

for ($vert in $myVerts)
    float $min = -50;
    float $max  = 50; 
    float $randNumX = rand( $min , $max );
    float $randNumY = rand( $min , $max );
    float $randNumZ = rand( $min , $max );

    select -r $vert ;
    move -r $randNumX $randNumY $randNumZ ;
select -r $mySelection; // return to previously selected objects


Use an image sequence with texture emission – [Maya]

One of the great bugs in maya is that if you want to use an image sequence to use within any of its’ nodes, it manages to completely negate the effect of anything other than the first frame.

To fix this just create an expression in your scene and enter this code in to it, replacing the correct attributes as shown by the comments.

// Enter the name of the existing file node you want to drive here. "file1", "weightDrive_file", etc.
string $fileNode="fileIn";</code>

// Enter the directory and first part of the image name, before the numbers, here
// If your image sequence is called "animMap.0001.tif" and its in the images directory of your project
// then you would leave the $imagePrefix variable as it is.
string $imagePrefix="images/animMap";

// This is self explantory with the previous explanation in mind..
string $imageSuffix="tif";

// This is for you to offset the sequence if you need to
int $offset=0;

// Check the image name of the file node to make sure the name string is correct. Adjust previous entries to fix.
string $pythonCmd="import maya.cmds as cmds\noffset="+$offset+"\nframe=int(cmds.currentTime(q=1))+offset\ncmds.setAttr('"+$fileNode+".fileTextureName',('"+$imagePrefix+".'+str(frame).zfill(4)+'."+$imageSuffix+"'),type='string')";
python $pythonCmd;

Find the colour at the closest point to a locator

So it’s a bit of an odd one, but I needed to be able to calculate the RGB value of the colour at certain points on the mesh, and at first this seemed a bit tricky, but using the cloestPointOnMesh node and the colorAtPoint command I was able to use a locator and easily connect it up to give me the result I needed, hopefully it will help you out too.

// Select mesh
$mesh = `ls -sl`;

// Select locator
$locator = `ls -sl`;

//Name of the texture
string $texture = "noise1";

//Calculates the position of the locator.
float $position[3] = `xform -worldSpace -query -translation $loc`;

//Calcualtes the closest point on the mesh to the locator.
float $uv [] = `closestPointOnMesh -ip $position[0] $position[1] $position[2] -q -u -v $mesh`;

//Calculates the RGB colour of the texture at the point
float $rgb [] = `colorAtPoint -o RGB -u $uv[0] -v $uv[1] $texture`;

Draw a curve/line between two objects [Maya]

So I found this to be pretty useful, I used it to help visualise the direction of the wind I was pumping in to another variable, but it could be used for countless other things, just select the two objects you want to draw a curve between and run this MEL script.

string $sel[] = `ls -sl -tr`;
string $locA = $sel[0];
string $locB = $sel[1];
string $crv = `curve -d 1 -p 0 0 0 -p 0 0 0`;
connectAttr -f ($locA+".t") ($crv+".cv[0]");
connectAttr -f ($locB+".t") ($crv+".cv[1]");