Category Archives: TUTORIALS

Pixar’s Universal Scene Description- Setup


Universal Scene Description (USD) is an efficient, scalable system for authoring, reading, and streaming time-sampled scene description for interchange between graphics applications. A preview build is available for early adopters, here.

There are two tarballs available for download, usd-20151216.tar.gz which includes the USD libraries, and deps-vfx2015.tar.gz which includes all the dependent libraries required by USD.

If you wanna get this up and running without taking the pain to read through the detailed setup instructions, you may download the following gist and run as root. Don’t forget to add the following line to your ~/.bashrc

source /opt/pixar/usd/bin/

As per the package README, the pre-built binaries expect to find library dependencies in /opt/pixar/usd-vfx2015. I went ahead with the recommended install location.

sudo mkdir /opt/usd

# Assuming you downloaded the files to ~/Downloads

sudo tar xfv ~/Downloads/usd-20151216.tar.gz -C /opt/pixar

sudo tar xfv ~/Downloads/deps-vfx2015.tar.gz -C /opt/pixar

The default shell for CentOS is bash. So if you are haven’t changed to any other shell, you can add the following line to your ~/.bashrc file so that the environment is set correctly before you proceed building the dependencies.

source /opt/pixar/usd/bin/

Next step is to install the dependencies.

yum groupinstall "Development Tools"

yum install zlib-devel

yum install glibc-devel.i686

You may use the links below to download the rest of the dependencies.

Create a temp directory in your home directory and extract each of the packages in to that.

mkdir /tmp/usd_build

cd /tmp/usd_build

# Assuming you downloaded the files to ~/Downloads

tar xfv ~/Downloads/binutils-2.24.tar.gz

tar xfv ~/Downloads/mpfr-3.1.2.tar.gz 

tar xfv ~/Downloads/mpc-1.0.1.tar.gz 

tar xfv ~/Downloads/db-4.7.25.NC.tar.gz 

tar xfv ~/Downloads/gmp-5.1.2.tar.bz2 

tar xfv ~/Downloads/gcc-4.8.2.tar.gz 

sudo /opt/pixar/usd/bin/ /tmp/usd_build/

If the build was successful, you should be able to see the following in the console.

Libraries have been installed in:

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR’
flag during linking and do at least one of the following:
– add LIBDIR to the `LD_LIBRARY_PATH’ environment variable
during execution
– add LIBDIR to the `LD_RUN_PATH’ environment variable
during linking
– use the `-Wl,–rpath -Wl,LIBDIR’ linker flag
– have your system administrator add LIBDIR to `/etc/’

See any operating system documentation about shared libraries for
more information, such as the ld(1) and manual pages.
Installing DB utilities: /opt/pixar/usd-vfx2015/bin …
cp -p .libs/db_archive /opt/pixar/usd-vfx2015/bin/db_archive
cp -p .libs/db_checkpoint /opt/pixar/usd-vfx2015/bin/db_checkpoint
cp -p .libs/db_codegen /opt/pixar/usd-vfx2015/bin/db_codegen
cp -p .libs/db_deadlock /opt/pixar/usd-vfx2015/bin/db_deadlock
cp -p .libs/db_dump /opt/pixar/usd-vfx2015/bin/db_dump
cp -p .libs/db_hotbackup /opt/pixar/usd-vfx2015/bin/db_hotbackup
cp -p .libs/db_load /opt/pixar/usd-vfx2015/bin/db_load
cp -p .libs/db_printlog /opt/pixar/usd-vfx2015/bin/db_printlog
cp -p .libs/db_recover /opt/pixar/usd-vfx2015/bin/db_recover
cp -p .libs/db_stat /opt/pixar/usd-vfx2015/bin/db_stat
cp -p .libs/db_upgrade /opt/pixar/usd-vfx2015/bin/db_upgrade
cp -p .libs/db_verify /opt/pixar/usd-vfx2015/bin/db_verify
Installing documentation: /opt/pixar/usd-vfx2015/docs …
+ echo ‘Done!’
+ exit 0

I had done a fresh install of CentOS 6.x for testing USD. Hence had forgot to install the graphics drivers for my rig. So I ran in to this error.

ImportError: cannot open shared object file: No such file or directory

You can get the graphics card drivers (NVIDIA/ATI) installed, to fix this error.

You can test if the installation was successful by loading one of the example files using the usdview application.

The tutorials can be found under /opt/pixar/usd/tutorials/



File Handling in MEL – Part2

To perform a set of file operations including creation, deletion and listing of files and directories

Creating  folders using sysFile command

 sysFile -makeDir "/home/user/mayaFolder"; //unix
 sysFile -makeDir "C:/Documents and Settings/MayaFolder"; //windows

Get the list of mel scripts in the  maya scripts directory

 getFileList -folder "/home/user/maya/scripts" -filespec "*.mel";

Stripping a file path in to directory name and base name.

 $filePath = "/home/user/maya/2011-x64/scripts/userSetup.mel";
 $dirName = dirname($filePath);
 $baseName = basename($filePath , "/");

sysFile, dirname, basename
The sysFile command can be used to create, delete or rename files and directories from within Maya. The dirname and basename commands can be used to strip a file path in to the absolute path and filename. Using a combination of these three commands its possible to perform a variety of OS level operations from within the Maya workspace itself.

File Handling in MEL – Part1

In this tutorial, we will be covering the file handling functionality provided by MEL.
Writing out to and reading from file formats other than maya ascii and binary.
Write the file location of texture maps used in a scene

 $fileId = `fopen "/home/user/textureList.txt" "w"`;
 $fileNodes = `ls -type "file"`;
 if( size($fileNodes)==0 ) {
 fprint $fileHandle "No File Nodes found in scene";
 else {
 for ($each in `ls -type "file"`) {
 fprint $fileHandle (getAttr ($each + ".fileTextureName") + "n");
 fclose $fileHandle;

Read the contents of the written file and print the contents of each line.

 $fileHandle = `fopen "/home/user/textureList.txt" "r"`;
 while (! `feof $fileHandle`) {
 $eachLine = `fgetline $fileHandle`;
 print $eachLine;
 fclose $fileHandle;




The first code block writes the file paths of all the texture maps in the scene to a text file names textureList.txt. The fopen command returns a file identifier which can be used to write in to or read from the file specified in the command.An additional string can also be mentioned to denote whether to open the file for read,write or append operation(r ,w or a). Data can be written to the file using fprint command. Its advised to close the file handle once the read, write or append operation is finished. This can be done using the command fclose.

Data can be read by opening the file handle in “r” mode. The fgetline command reads the contents of the file line by line, which is then printed on to the screen.

Adding Maya Panels to MEL GUIs

Adding default scripted panels(Visor, Reference Editor etc) in Maya to custom UIs created using MEL

 if(!`scriptedPanelType -exists visorPanel1`)
 -createCallback "createVisorPanel"
 -initCallback "initVisorPanel"
 -addCallback "addVisorPanel"
 -removeCallback "removeVisorPanel"
 -saveStateCallback "saveStateVisorPanel"
 -deleteCallback "deleteVisorPanel"
 -unique true

if (`window -exists myWindow`)deleteUI myWindow;
 window -t "My Window" myWindow;
 frameLayout -lv false -bv false myLayout;
 scriptedPanel -e -p myLayout -type visorPanel1 visorPanel1;
 showWindow myWindow;

scriptedPanelType, scriptedPanel, getMayaPanelTypes


Default Scripted panels can be added to your custom GUIs using the scriptedPanel command. Before specifying the command the scripted panel should be defined using the command scriptedPanelType. By specifying the type of scripted panel using the -type flag in scriptedPanel command creates an instance of the specific scripted panel. You can also get a list of the default scripted panels in Maya using the command getMayaPanelTypes(1). In the above example an instance of Visor panel is created and then added to the custom UI myWindow.

The query regarding this functionality in MEL was raised by one of the visitors to this blog. Hence I thought it would be great to include this as a tutorial just in case some of you might find it useful. You may feel free to mail me in case you have any topics which you feel could be included in the Tutorials section. I am not guaranteeing a quick reply, but whenever I get free time from my work schedule I would try to include those topics too (provided I know the answer to your question).

Array manipulation in MEL – Part 2

As we saw in PART 1, stringArrayContains() and stringArrayInsertAtIndex() are two handy commands that can be used to manipulate arrays. In this Tutorial we will explore few more commands that can be used in the context of strings.

stringArrayRemoveDuplicates(), stringArrayCatenate(), stringArrayToString()

stringArrayRemoveDuplicates() can be used to remove duplicate entries from an array. The code block in PART1 can be simplified to something like this.

 for ($each in $transformList)
 if (stringArrayContains($each,$cleanList)!=1)

can be simplified to something like this

$cleanList = stringArrayRemoveDuplicates($transformList);

stringArrayCatenate() can be used to catenate two arrays together. Suppose we want to add a suffix “_geo” to all geometries in the scene, the following script can be made use of

 global proc ak_addSuffixAllGeo()
 string $polyList[],$nurbsList[];
 $polyList = `ls -type "mesh"`;
 $nurbsList = `ls -type "nurbsSurface"`;
 $allList = stringArrayCatenate($polyList,$nurbsList);
 $transformList = `listRelatives -p $allList`;
 $cleanList = stringArrayRemoveDuplicates($transformList);
 for ($each in $cleanList)
 $newName = $each + "_geo";
 rename $each $newName;

stringArrayToString() can be used to generate a string containing elements of the array separated using a separator string mentioned in the command.

 $myFolderTree = {"My Documents","maya","scripts"};
 $backSlash = "\";
 print (stringArrayToString($myFolderTree,$backSlash));

This would print My Documentsmayascripts” when executed in the Script Editor. This can be handy in cases where you create an UI from which the user selects a list of options which can include a scene name, a scene type (model, tex, rig), scene location etc and saving the file to particular location. You can build an array which includes all these individual user choices and encode it in to a OS recognizable string, which can be used for reading from or writing to the particular file location.

Array manipulation in MEL – Part 1

Here, in this tutorial we will see some of the array manipulation commands in MEL that can be put to use while creating your own scripts.
Getting a List of objects that are of a particular type, based on user input.


where $type can be mesh, nurbsCurve, ikHandle, joint, multiplyDivide….

 global proc ak_listObjectsOfType(string $type)
 string $transformList[],$cleanList[],$conflictList[];
 string $newName,$each;
 $choiceList = `ls -type $type`;
 if ($type == "nurbsCurve" || $type == "mesh")
 $transformList = `listRelatives -parent $choiceList`;
 $transformList = $choiceList;
 int $i = 0;
 for ($each in $transformList)
 if (stringArrayContains($each,$cleanList)!=1)
 print $cleanList;

ls, listRelatives, stringArrayContains, stringArrayInsertAtIndex
The result can be easily achieved using the command ls. Using the -type flag followed by the object type will give a list of objects of that specific type.
For eg: ls -type “ikHandle” will return a list of all ik handles in the scene
But specifying mesh or nurbsCurve will give the shape names instead of the transform names. By running a listRelatives -parent on the returning list will give the transform nodes, but this will include duplicate entries if the mesh is having a deformer attached to it since ls -type “mesh” return a list of all the intermediate objects too. So we will be using the script listed above to print out objects that matches the user entry type.

The pseudocode for the script is as follows.

global procedure ak_listObjectsOfType($type of type string )
 declare String Arrays $transformLis,$cleanList and $conflictList
 declare String $newName and $each;
 store the value of ls command of node type $type in $choiceList
 if ($type  is "nurbsCurve" or   "mesh")
 store the parents of $choiceList in $transformList;
 Assign  the value of $choiceList itself to $transformList
 initialize index number $i  to zero;
 for (each element  in $transformList)
 if (string Array $cleanList doesn't contain $each)
 insert $each at position $i of $cleanList
 increment the index value $i by 1
 print the $cleanList

The command stringArrayContains() checks a string exists in a string Array or not and returns true of false. stringArrayInsertAtIndex() will insert a string in to the index position position in the string Array. Both the command names are self-explanatory.

CODE – CG – MEL Scripting – Preface

After coming across so many queries about MEL Scripting in several computer graphics forums, I felt it would be a great idea to start a MEL Scripting Tutorial Series under CODE-CG where Artists and Programmers can learn how to get their job done by making use of MEL. You might be skeptical why we need a Tutorial series when we already have numerous books available in the market that cover MEL. I would say, all those books will tell you how to write a MEL Script but fail to tell where to use them. Having spend a couple of years in the Computer Graphics industry this is the pattern that I observed.

1. Artists are too lazy to learn Scripting even if they know that scripting knowledge can streamline their workflow a lot.

2. Programmers who know Scripting, never always come up with the Scripts that completely makes use of the techniques an experienced Artist is equipped with.

There will always be a communication gap between the Artists and the Programmers which results in a few thousand lines of code, which would have made use of better logic, if they both knew what the other person was looking for.

Hence I decided that the structure of the Tutorials should be in such a way that each MEL command that we examine here should point to the exact production scenario where it can be made use of, so that whether you are an Artist or a Programmer, you know exactly Where and How you gotta use it.