Akram Parvez Technical Artist

Catching and debugging errors in Maya Python

Posted on

Working as a TA for an outsourcing company means that you have to support different project at the same time. This includes writing small or big python scripts for the artist and sometimes these script could be buggy as you would not have a proper testing environment and you depend on the artist to send you error reports that help you to understand/analyze the bug. But Maya tries to act smart and mask error output in the script output window. So artist end up sending only part of the information.
Here is a super simple example:

import maya.cmds as mc
def getAllObjs():
    objs = mc.ls()
    for obj in objs:
        mc.setAttr('%s.doubleSided' % obj, False)

If you call the above function, the artist would get an error and he forwards you this.

# Error: RuntimeError: setAttr: No object matches name: time1.doubleSided #

This does not help you if the script is big and finding out where this error occurred would take some time if you were not the author. Instead you could use the traceback module from python's standard library to get some useful/proper info.

Wrap your code as follows and now you would get much more meaningful tracebacks as except from python.

import traceback
try:
    getAllObjs()
except RuntimeError:
    print traceback.format_exc()

# Outputs:
# Error: setAttr: No object matches name: time1.doubleSided
# Traceback (most recent call last):
#   File "", line 1, in
#   File "", line 7, in getAllObjs
# RuntimeError: setAttr: No object matches name: time1.doubleSided #

I know this can also be achieved by enabling Script Editor->History->Show Stack Trace, but usually this is not setup on an artist's work stations.

You can also use this in the userSetup.py if you have one used by everyone in the company:

gScriptEditor = mel.eval('$tmp = $gCommandReporter');
mc.cmdScrollFieldReporter(gScriptEditor, edit=True, stackTrace=True)
Filed under: Python, TechArt No Comments

Model Viewer in PyOpenGL

Posted on

In the last few months, I have been work with Python and PyQt a lot, so I thought why not do a personal project at home to improve my python skills and also learn some OpenGL. I started learning OpenGL and to make a Model Viewer was my realistic goal. This goal was to keep me on track and avoid getting lost in the huge world of OpenGL. I choose the following frame works:

  • Python 2.7
  • PyQt4 - for UI
  • PyOpenGl - OpenGL binding for python
  • FreeImage - for loading Images

Initially I used PIL for loading images in python, but quickly changed to FreeImage as PIL did not have support for loading DDS and HDR Images. FreeImage library was loaded using CTypes in python, which proved to be great for sending image file data to OpenGL. I had a small list of features to be implemented in the viewer and Marmoset Toolbag(link) has been a great inspiration for me during the development. The following features are partly/fully implemented:

  • Loading OBJ file format (WIP).
  • Simple Phong Shading with One Light support.
  • Diffuse, Normal, Specular and Illumination Map support.
  • Image Based Lighting with Vertical Cross Cubemap.
  • DOF, HDR and Bloom (WIP/Basic implementation).
Imrod model by Dmitriy Parkin(www.parkparkin.com)
Image Probes from Humus.name
Filed under: Python, TechArt 5 Comments

Python in 3ds Max by BLUR..

Posted on

I just found this awesome post in cgtalk(link)
by Eric Hulser,BLUR which has a complete python replacement for maxscript. This should open up many doors for scripting in 3ds max as python is more efficient language. They have also added PyQt support for making rollouts. I will try it very soon and post some updates. BLUR rocks...

Links:
Blur-Dev

Filed under: Python No Comments

Learning Maths and Python

Posted on

Recently found a website called ProjectEuler which has very good maths problems to be solved using computer programming. I am just trying to build up my python programming skills. There is one more site which i found at Tech-Artist.org which has more challenging riddles to be solved using python, PythonChallenge.com. Don't forget to check them out.

Filed under: Python No Comments

Python rocks..

Posted on

Recently started using Pyhton to simplify my life at work. Initially i started looking in python because of Blender,later on when there was a requirement of a tool which had to run in any system, python came to my rescue. Its was very quick and easy to write. My python journey begins....

Here are few sites i found useful.
Python Docs
Python Book
Tech-Artist.org(my favorite for technical artists)
Python Challenges(awesome site i found in tech-artist forums)

Filed under: Python No Comments