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
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

Update from Shanghai…

Posted on

Happy Chinese New Year to all. Yeah a lot of things happened in the recent past. Long story short, Got a job in Shanghai,China(VirtuosGames) and moved here in Sept, after which my website was not accessible(Great Firewall). So I finally got a VPN Connection(StrongVPN) and my website is back.
About Shanghai, I am Loving the place and my work rocks too, but the language is little hard to learn and understand. Hope I learn it sooner or later. Will post some pics soon, till then bye..


Posted on

I have been learning and using dot-net in 3ds max a lot recently. I think its time i show some of my learnings in Dot-net GDI . Here is an example of using a dot-net label as progress bar with GDI. I tried to replicate the look of pre-max9 polygon counter as asked in tech-artist.org forum(here).

global _dupPolyCounter
try (destroyDialog _dupPolyCounter) catch()

rollout _dupPolyCounter "Duplicate Polycounter" width:250
	local _min = 100,_max =200
	group "Progress Test"
		label _bdgt "Budget:" pos:[20,25]
		spinner spn_max "" pos:[65,25] range:[100,1000,_max] width:55 type:#integer
		label _crnt "Current:" pos:[140,25]
		spinner spn_val "" pos:[185,25] range:[1,spn_max.value,_min] width:55 type:#integer
		dotnetcontrol lbl "label" height:10 width:200 pos:[25,50]
	local acolor = dotnetclass "system.drawing.color"
	mapped fn dispose gdiobj =
	on lbl Paint args do
		local margin = 2
		graphics = args.graphics
		width = ((lbl.clientRectangle.width)/40)
		_val = ((float(_min)/_max)*40)
		X = lbl.clientRectangle.X+margin
		Y = lbl.clientRectangle.Y+margin
		for i = 1 to _val do
			rect = dotnetobject "System.Drawing.Rectangle" X Y (width-1) (lbl.clientRectangle.Height-2*margin)
			_col = acolor.green
			if i > 35  then _col = acolor.red else (if i>27 then _col = acolor.yellow else _col = acolor.green)
			foreBrush=dotnetobject "System.Drawing.SolidBrush" _col
			graphics.FillRectangle foreBrush rect
			X += width
			dispose #(foreBrush)
	on spn_val changed val do
		_min = val
	on spn_max changed val do
		_max = val
		spn_val.range = [1,spn_max.value,_min]
 	on _dupPolyCounter open do
		lbl.backColor = lbl.backColor.Black

createDialog _dupPolyCounter

I hope to post more snippets in future..

Filed under: Scripts No Comments

Post Effects Vision Shader

Posted on

Started learning some shader writing in HLSL and 3ds Max recently. Here is my first shader. Its a post effects shader for 3ds max. I tried to get the night vision and thermal vision effects using this shader. So here's what i have got.

You can view the same video at http://www.youtube.com/watch?v=wXxdq_mFAzg

The shader uses 2 gradient maps for Thermal Vision and Night Vision. I have added control for Black level adjustment, which controls the blackness in the scene(as shown in the video).

Currently working on Detail Normal Shader for 3ds max, will post it soon.

Filed under: Shaders 2 Comments

Self-Promotional Plug Alert!

Posted on

The NormalMap Widget Script that i had created has been added to polycount wiki. Thanks EricChadwick for adding it. I have also added some decent images to the post.

Read it here – http://wiki.polycount.net/Normal_Map

Filed under: Scripts No Comments

Scripts release(Select Non-Planar and Broken Wall Creator)..

Posted on

Lately i have got some request for the Broken Wall Creator script, so finally got time to make it releasable. It has got some bugs so please bare with it and comment here if found any. Use only the top view to create the broken wall because of some bugs.
Someone on Tech-Artist.org wanted a script to select non planar faces. I had a script that was written a while back so thought of releasing it as well.
Please download the scripts from
Broken Wall Creator
Select Non-Planar Faces

Installation Instructions for Select Non-Planar Faces
* Drag and Drop Select_NPR.mzp in to 3dsMax viewport.
* From the Customize User Interface menu option you can now assign Select_NPR to a Toolbar. The command is located in the "Akira Scripts" Category.

Filed under: Scripts No Comments

NormalMap Widget for 3ds Max

Posted on

Been busy learning to create forms using dotnet in maxscript. Earlier today stumble across Steev “kobra” Kelly's tutorial for easily creating normal map details in 3ds max and use photoshop to add it to a base map. So thought of writing a script for quick normal map renders based on the tutorial.

Steps for usage:
1. Run the Script :D. Find it in Customize User Interface->Toolsbar->Catogery->Akira's Scripts-> NormalWidget

2. Select the Highpoly and hit setup.

3. Scale the highpoly to fit the template plane.

4. Hit render and save the image.

5. Use it to add details in the base map. Idle to create a library of normal maps for using across objects like nuts,bolts,cracks,etc.


Hopefully will include render size options in the next update. Suggestion are welcome.

NormalMapWidget(Mirror Link)

Filed under: Scripts No 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...


Filed under: Python No Comments

Some Old Game-Art..

Posted on

Finally found time to revisit some old work.



Picture 1 of 8



Picture 1 of 8

Filed under: Personal No Comments