Blog of


APyTA_02: Let’s Draw, not print !

APyTA_02:  Let's Draw, not print !

Just forget this damn script editor, and let's create a text in Maya: Create>Text
Let's look at our MEL feedback in the Script Editor:

textCurves -ch 0 -f "Times New Roman|h-13|w400|c0" -t "Hello world";

Well, first good news: you can use these MEL-formatted lines with your python code !
Let's Type this:

import maya.mel
maya.mel.eval('textCurves -ch 0 -f "Times New Roman|h-13|w400|c0" -t "Hello world";')

(Please notice how I avoid breaking the string chain with a global simple quote.)
Well, so you have no reason to be afraid: all your MEL-knowledge, favorite procs are not obsolete !

To be honest, when you'll become more at ease with python, (and this would be quicker than you actually think)
in practice this method will be the very last of your choices. But now you know it.

Well, this MEL-line can be very easily converted into a python function:

import maya.cmds
pythonReturn = maya.cmds.textCurves(text="Hello world")

First, notice in the first line the call to maya commands libraries.
This is where all MEL commands are stored in python.
They are stored in a form like any other function, with parenthesis and arguments.
So, to respect the MEL-Style, you have to write the parameter (shortName or longName).
Non-specified parameters will be set at their default values.

So, we have to way of doing thing, MEL-Style and Python-Style.
I'm sorry but it is a bit more complicated. As Python is object-oriented (a whole post on that aspect will come later),
some people (Hi Olivier!) decided to respect a meaningful structure of commands, and created PyMEL.
Let's have a look at it:

import pymel.core
pymelReturn= pymel.core.modeling.textCurves(t="Hello world" )

Quite similar right ? But you can observe the command is "namespaced", like grouped by categories.
So when calling which one ? Are there others surprises ?

Yes of course, please wellcoooooome OpenMaya !
I'll explain it later, but let say it is the python equivalent to C++ API of Maya !
You will be able to do, with only python, (almost) reach all the possibilities of Maya Plug-Ins (but slower).

import maya.OpenMaya
maya.OpenMaya.MGlobal.displayInfo("Hello World")
maya.OpenMaya.MGlobal.displayWarning("Hello World?")
maya.OpenMaya.MGlobal.displayError("Hello World!")

And we're done with that presentation ! Ouch !

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.