Friday, March 11, 2016

Simple Maya Script Snippets

 I sort of started doing the rigging dojo challenge of putting out a super simple script snippet a day, that not only does "something" but also displays something interesting in the world of scripting for Maya . None of this is mind bending and I'm sure not new to a lot of people, but maybe it will help someone with an intro


day one:
so this is a super simple script to just get the number of objects you have selected.. I have gotten so use to writing this script that I tend to just pop it into the script editor without thinking
the nice thing here is I'm not creating any variables so they wont be global or overwrite anything in my current Maya session.
mel:
size `ls -sl`;
python:
len(cmds.ls(sl=True))

also since the "select" command does not have a type flag. I use this same sort of method for quickly selecting all of a given node type
mel:
select `ls -type "mesh"`;
python:
cmds.select(cmds.ls(type='mesh'))


day two:
ok, so this one is not so different from the previous, so I'll just call it "super simple script" that can be helpful ( i just ran out of time today)
This one just takes your current object's type and makes a set of every object of that type in your scene . Since I'm dropping this on the shelf or running in the script editor, I scope it inside curly braces to keep the variables from going global. I highly recommend scoping whenever you are prototyping in the script editor with mel.. or you will bang your head against an illegal re-declaration , or an array of the wrong items from time to time.
{ 
string $s[] =`ls -sl ` ;
string $c[] =`listRelatives -c -s $s[0]`;
string $type = `nodeType $c[0]` ; 
sets -n ($type + "s") `ls -type $type`;
}
for the Python version I was able to get rid of all the variables as you can nest functions better ( with Mel you only can do it once)
(the following should read as just 2 lines, the first being the import of the maya commands module )
import maya.cmds as cmds
cmds.sets(cmds.ls(type=cmds.nodeType(cmds.listRelatives(cmds.ls(sl=True)[0],c=True,s=True))),n='SET')


day three: 
this is an experiment in fixing up an old script and streamlining it a little bit. the top this time is in Python, and I added the nope variable & print statement just to demonstrate that nope is actually list of booleans and I have to A) pull out the first item using [0] and then use str() to force it into a string for printing
sel=cmds.ls(sl=True,dag=True,shapes=True,noIntermediate=True)
for e in sel:
nope =not(cmds.displaySurface(e,query=True,xRay=True))[0]
print ("the ! issue is : " + str(nope) ) 
cmds.displaySurface(xRay=not(cmds.displaySurface(e,query=True,xRay=True))[0])
pretty much the same thing, but I don't have the same power in MEL to pull the first item out of the int array, and so I have to first make an int array variable and then use that in the action part of the script,, note that in MEL you can use ! for ( opposite or not) while in Python it's "not" to do the same thing
{
string $sel[] = `ls -sl -dag -s -noIntermediate`;
for ($each in $sel)
{
int $x[] =`displaySurface -q -xRay $each`; 
displaySurface -xRay ( !$x[0] ) $each;
}
}

Thursday, January 14, 2016

Python Equivalent of mel whatIs command

A common Maya debug for any mel script in All of Maya is the mel whatIs command. It basically tells you the location of any sourced script on your computers file system. It's a great way to melSteal and figure out what a script is doing.  

for mel you just use whatIs and the name of the command

whatIs BuildDisplayMenu;
// Result: Script found in: C:/Program Files/Autodesk/Maya2015/scripts/startup/buildDisplayMenu.mel // 

whatIs duplicate;
// Result: Command // 

if the command is not a script, but an internal maya command it will return "command".

Then you can use the help or help -doc to look up that command in the maya help reference.


 In python the equivalent to mel whatIs is to envoke its __file__ command.

so if not already imported. use the python import command

import mysteryScript

and then run it's __file__

mysteryScript.__file__

and it should return the scripts file path

C:\Program Files\Autodesk\Maya2016\Python\Lib\site-packages\maya\mysteryScript.py 







Wednesday, November 25, 2015

quick select set by "type" quick tip

Was just discussing how to quickly get a set of all your lights in a scene and thought I'd try some fast mel code, and low and behold it worked.. 
 super easy and fast and works great. 


this is one for  "meshes" :

 sets -name "meshes" `ls -type "mesh"` ;




oh and in python it looks like this

import maya.cmds

maya.cmds.sets(maya.cmds.ls(type="mesh") ,name="meshes")

Monday, May 18, 2015

Customizing Maya 2016

Just a look into how I customize Maya. With the new Maya 2016 out, I decided to try and reboot some of my tutorials.  This is just an overview. as the 1 hour long "how to" is brutal.


Monday, April 27, 2015

Seton "Welcome to Humancare"

This was an interesting project for Seton Hospital in that it was all done in 3D with Maya.  so the shadows and cuts in the paper are all 3D rendered.   It created some interesting challenges to get the animation of paper to look right.


Seton – "Welcome to Humancare" from CHRLX on Vimeo.

Tuesday, January 13, 2015

fun with Geo Paint

I always love playing around with geometryPaint....


Wednesday, December 31, 2014

Setting up the Maya Environment

Happy New Years eve.

 I'm trying to get back on the tutorial kick again, this one was painful, and it's long, but I think there are some good nuggets here and there..

I'll add more to this as time and comments continues..
-=s