Friday, 13 January 2012

Maya: Starting scripts on load - userSetup.mel

To execute scripts, whether custom or local, each time you startup maya (in the studio ours check important prefs, timeUnits etc) is very simple.

All you need to do is create a mel script called "userSetup.mel" and place it into you maya/scripts folder in your documents (of course there are instances, depending on what the script is doing, if its messing with mainWindow states etc, you need to make sure they load first by using the "evalDeferred" command - at least that's what I've come to believe.

For example if you created a mel script like this;
string $win=`window` ; columnLayout -adj true ; text -label "Hello World" -align "center" ; setParent.. ; showWindow $win ;
called it "userSetup.mel" and placed it into maya/scripts/  folder, on starting maya, you can expect to see a window with the text "Hello World" pop up when maya starts.
Generally this idea is taken further (if in a studio) and either each user's environment vars point to a userSetup.mel on the network, or each have their own userSetup.mel on their local machine that points to a separate startup script on the network, which then its fairly simple for the user to modify their own startup, based on their preferences.

At some point, once I get some time, I do intend on revisiting and furthering most of my posts, taking the time to actually explain what's going on and why, and giving links the right documentation.

Comments welcome.

Maya: IK Handles not updating on undo

I had this problem a few times (even back on maya 5), where you set up a rig, and you point constrain the ikHandle to a control object. It moves around fine, up until you undo. The handle just doesn't seem to behave properly, and scrubbing or moving it again will snap the ikHandle to where it should be.
So I thought I might give a workaround.
Directly constraining an IkHandle seems to have the issue of not updating when undoing.
It seems to be a clash with the way the ik handles and constraints evaluate, and something seems to get missed.
You can avoid this by parenting the ikHandle under the controller, or (if you want the outliner to be tidy) you can parent the ikHandle under a null or locator and constraint that instead.

EDIT:
Brad Clark (Co-founder - riggingdojo.com) provided more info and suggested a better solution.
You shouldn't have this problem if you turn off the snap setting on the ik handle. Then it won't be trying to get back to the end of the chain and should stick with the constraint target. There is a bug with Maya Undo though that if you are moving a node and hit the undo hot key before releasing the mouse button for the current transform, it will undo the previous transform, leaving the move you just did outside of the que, causing an offset that has to be fixed by hand.

Comments welcome.

Maya: Typical Sound/Audio issues during playback.

Another frequent problem is not being able to hear audio during playback, but working fine whilst scrubbing.

Typically, the issue could be down to your playback settings.
Just open your maya preferences, and under "Time Slider", check your "Playback Speed" is at Real-time. If its at anything else you wont hear the audio during playback.

Maya: Window display issues - "...Panel is torn off."

This seems to be a frequent problem, in which some people result in doing a complete reinstall!.

Problem:
Cant show my graph editor/outliner/etc window, keeps telling me "... Panel is torn off."

What this typically means is that somewhere along the line the window has been placed off-screen, usually happens when users either switch monitors around or remove a monitor.
A few very simple fixes, and any one of them should solve your problem.

1.  You can reset your maya's window preferences simply by deleting the "windowPrefs.mel" located in your maya prefs folder ("USER\My Documents\maya\2011-x64\prefs\") whilst maya is CLOSED. Dont worry, once opening maya again, it will automatically create the "windowPrefs.mel" file again, all windows should now load at their default position.
2. You can edit the "windowPrefs.mel" file, to tell maya where to place the windows, just open it in a text editor (notepad usually does the trick, and again whilst maya is closed), and for each window you'll see a "-topLeftCorner" flag with 2 numbers after it. Change them to something like 10 10, save the mel file and load maya.
3. If you only have 1 rogue window you can use mel to reposition the window (you will of course need to know the name of the window, found when trying to load the window - as long as you have "Echo all commands" ticked on in the script editor)
window -e -tlc 10 10 "graphEditor1Window" ;
Now depending on the window your trying to reposition, the naming convention might differ from ending in "Window" or "Panel#Window" ("#" is the number id of the window, typically its 1).
Again, any questions etc, please feel free to comment.

Thursday, 12 January 2012

Python: Create a file listing a folders contents

Our co-ord was just trying to get some info together so I come up with this simple little script to print the contents of a specified folder into a dated file.
I'm aware there are better methods of writing the file (using the list and write each item individually in loop etc), but it was short and does the job.

To get the date, I simply used the datetime module and retrieved today's date (as stipulated on local machine), then converted it to a familiar format.
For writing the file, I simply joined a sorted list of files found into a string separated by a newline, opened a writeable doc, deposited the data and closed it to allow access. import os import datetime def ld_listFiles(path,resultPath): fileString='\n'.join(sorted(os.listdir(path))) d=datetime.date.today() date=d.isoformat() filePath=resultPath+'filesListResults_'+date+'.txt' thefile=open(filePath,'w') thefile.write(fileString) thefile.close() return fileString # ld_listFiles('C:/Users/Lee/Desktop/Documents/','C:/Users/Lee/Desktop/')
...and of course this can then be furthered for error checking (making sure paths exist, folders contain files etc), nativePath conversion (not sure of correct terminology), specify file extensions/types, folder contents, file sizes, modification date etc. This is just a very simple example (and perhaps not a great one, but it works).
In fact I think I might spend some time in creating a decent version.
Any tips, suggestions etc, are more than welcome!

Tuesday, 10 January 2012

Mel: Parenting shape nodes to new parents (ie polyMesh to Joint)

Was asked about combining a polySphere/nurbsSphere to a joint, so selecting the sphere still selects the joint.

Its fairly simple actually, its the same way as you would combine two nurbs curves under one transform node (to get more complex/detailed control objects).

string $parent="joint1"; string $shape="pSphereShape1"; parent -add -shape $shape $parent;
As simple as!

Saturday, 7 January 2012

Mel/Python: Splitting a string by a string (tokenize vs .split)

I know its only a small post and I don't go into detail, more of an outline... it really did bug me was how there are no expressions for tokenize.
I spent a bit of time trying to split a string (ie "L_clavicle_bind_jnt") by with the string "_bind_".
What I found with using tokenize was that it will split the string by the characters instead of the entire string, which to me, was a pain in the backside as I wanted {"L_clavicle","jnt"} but what i'd get with tokenize was {"L,"clav","cle","j","t"}. Now this wouldn't do, and I could find any out of the box way of doing this (I wanted to replace "_bind_" with "_IK_", etc to search), so I ended up turning to python (yet again).
It couldn't be simplier.
"L_clavicle_bind_jnt".split("_bind_")
Which translated as -
python("'"+$child+"'.split('_"+$namespace+"_')") ;
Thinking about it now, im sure there is a command to do this in mel, I just cant find it...