Commands:sysFile, dirname, basenameDiscussion:
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.

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

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.

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

Like this:

Finally got some time to get back to python after a long break, only to find that I don’t have a working copy of PyQt4. Instead of spending time on google trying to figure out whether anyone has decided to share a copy of PyQt built against Qt4.5.3, decided to build one myself. Having Windows SDK already installed on my XP proved out to be handy since the Visual Studio version I was running was still 32-bit one. Downloaded SIP4.12 source and Qt4.5.3 SDK and within few seconds the PyQt4 module was successfully added to the site-packages.

Thought of sharing the build for those of you who are planning ahead to design awesome GUIs in Maya.You may download it here

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.

Like this:

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.Problem:Getting a List of objects that are of a particular type, based on user input.Solution:

ak_listObjectsOfType(“$type”)

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

Commands: ls, listRelatives, stringArrayContains, stringArrayInsertAtIndexDiscussion:
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 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.

Like this:

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.