So I wanted to visualise a field in maya, as I needed to know what it was looking like, and I found a pretty simple way to do it.
Create a 3D fluid container:
Dynamics > Fluid Effects > Create 3D Container
Connect your field to the container:
Window > Relationship Editors > Dynamic Relationships
In the fluid container, turn on velocity draw:
Display > Velocity Draw
Feel free to change the options, increase the resolution of the container if you need more fidelity.
So sometimes you want to add some notes to your objects in maya, the quick python script below will add a string attribute to the node you input
from maya import cmds
def add_notes(node = None, default_text = "Input note here"):
if not node:
sel = cmds.ls(sl=1)
node = sel
cmds.warning("Please select a node to apply the notes field too")
if not cmds.attributeQuery("notes", n = node, ex = True):
cmds.addAttr(node, ln = "notes", sn="nts", dt="string")
cmds.setAttr("%s.notes"%node, default_text, type="string")
cmds.warning("%s already has a notes attribute"%node)
add_notes("my_node_name", "Remember to rewind to 0 when opening this file")
notes_val = cmds.getAttr("%s.notes"%node)
So I ended up with a few issues when attempting to set the keyframe on an object using the layout specified in the python command, I was trying to do something like:
cmds.setKeyframe("pCube1", value=True, attribute="visibility")
However as I was using instancing, this would also keyframe the visibility on the pCubeShape1 which I didn’t want, even if I explicitly passed in only the name of the transform, to avoid this you need to pass in the transform name and the attribute in the same go, so something along the lines of:
and this should only change it on the transform.
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
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.
// 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.
// This is self explantory with the previous explanation in mind..
// This is for you to offset the sequence if you need to
// 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')";
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;
string $locB = $sel;
string $crv = `curve -d 1 -p 0 0 0 -p 0 0 0`;
connectAttr -f ($locA+".t") ($crv+".cv");
connectAttr -f ($locB+".t") ($crv+".cv");
Here is a little script I found from here, that allows you to query the amount of points (or cv’s) on a curve, where curveShape1 is the name of the curve you have created.
string $curve = "curveShape1";
int $numSpans = `getAttr ( $curve + ".spans" )`;
int $degree = `getAttr ( $curve + ".degree" )`;
int $form = `getAttr ( $curve + ".form" )`;
int $numCVs = $numSpans + $degree;
// Adjust for periodic curve:
if ( $form == 2 ) $numCVs -= $degree;
I then used this to be able to spread the cv’s along the y axis, where ‘curve1’ is the name of your curve.
for ($i = 0; $i < $numCVs; ++$i )
vector $low = `pointPosition -w curve1.cv`;
vector $high = `pointPosition -w curve1.cv[$numCVs-1]`;
float $gap = ($high.y - $low.y)/($numCVs-1);
vector $pos = `pointPosition -w curve1.cv[$i]`;
$var = $lowNew.y + $i*$gap;
move -y $var;