May 22

I saw a post on www.cgtalk.com where a user wanted to render the selected meshes bounding box as a render region using the current render settings. He gave this example:

I thought this was an interesting challege that the Python API could handle since it can access the M3dView class which lets you test points in the Maya 3d space and get what pixel they are at in the viewport. Here is the finished script, also posted in my downloads section:

rtRenderSelectedMeshesRegion.zip

Cheers,
Ryan

May 18

In response to an e-mail I received I wrote back this response. I figured I would post it.

So I was given this example and asked what the u charter was for in front of each string name returned in the list.


aList = cmds.ls(selection=True)
print aList

>>[u'pSphere1', u'pSphere2', u'pSphere3', u'pSphere4']

The long and the short of it is Unicode allows more characters than ASCII. ASCII can hold 256 values and Unicode can hold 65,536 values. This allows computers to support complex languages with many characters. If you want a more complex explanation go here:

http://www.amk.ca/python/howto/unicode

Getting back to the example. So the aList returns a list of string names using Python Unicode. Thats what the u stands for. It shouldnt bother you though nor affect anything.

So if you have two spheres in your scene and you run this in the script editor it will return u’pSphere2′ and u’pSphere1′ like this:


import maya.cmds as cmds

getlist = cmds.ls(sl=True)
print getlist
>>[u'pSphere2', u'pSphere1']

Continue reading »