Maya API
API Questions
Learning the Maya API is usually a 3 step process:
[1] - Know what you want to build.
[2] - Then power up the computer on turn on Maya.
[3] - If you are unsure on how to achieve what you want, keep in mind the
most important button in the whole Maya functionality set, is of course *F1*
Good luck! Can verify it gets more and more interesting the further into
those documentations you go :)
(A. Guðmundsson)
What is a class?
example of basic class implementation by 3DevArtist
and class defining in Maya (in python, for card playing..) (also 3DevArtist)
but it didn't make sense to me until looking at Python's own docs
class MyClass:
"""A simple example class"""
i = 12345
def f(self):
return 'hello world'
#i guess this is what is meant by instantiation?
x = MyClass()
x.f()
>>> class Complex:... def __init__(self, realpart, imagpart):... self.r = realpart... self.i = imagpart...>>> x = Complex(3.0, -4.5)>>> x.r, x.i(3.0, -4.5)
Actually, you may have guessed the answer: the special thing about methods is that the object is passed as the first argument of the function. In our example, the call x.f() is exactly equivalent toMyClass.f(x). In general, calling a method with a list of n arguments is equivalent to calling the corresponding function with an argument list that is created by inserting the method’s object before the first argument. (python.org)
Why use classes? Where is it a good idea, and where is it unnecessary?
Object-Oriented Rigging in Skeleton Builder (H. Mackenzie)
Resources
Web
Maya API Whitepaper (Autodesk!)
Maya API Python Attribute and Type Reference (Jason Osipa)
Maya API Help Page (Michael Comet)
http://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/
http://ewertb.soundlinker.com/maya.php
http://ewertb.soundlinker.com/api/api.php
(from Maya Station)
Riggerman's notes (going from C++ to Python)
Books
Thinking in C++ Volume One: Introduction to Standard C++ by Bruce Eckel
Learning Python by Mark Lutz and David Ascher
Complete Maya Programming: An Extensive Guide to MEL and the C++ API by David Gould
FAQ
Do I develop plugins in Python or C++?
My problem with Python in
Maya right now is writing a deformer in Python. Maya allows you to
write plug-ins in Python, but it is very difficult to make them
efficient, even if you push all the heavy lifting onto C, using
ctypes, or something like cython/pyrex/etc. The basic problem here is
that you have to convert to CPython types in order to pass the data
along (unless you really do want to write an entirely new binding to
the Maya API,) and object creation/destruction with CPython is
insanely expensive- maybe 100 times too expensive for our purposes. I
would love to have our top-level deformer logic be in Python, and the
expensive bits be in C, or Pyrex, or cython, but just creating (and
destroying) the Swigged objects that the Maya Python API requires is
much more expensive than the very heavy math our deformer does in C.
We've decided to ship our plugin in two pieces- a deformer in C/C++
and the rest of what we do in Python that calls out to a C dll. You
seem very knowledgeable about this, so I wonder if you might know of
some way of passing data from ctypes, or cython, to Maya without
having to create all that expensive intermediate garbage.
(T. D. Smith)
This is a critical issue that has impacts the design and implementation of
any complex system attempted in Maya, using python. The limitations are
significant and the penalties severe should one mis-step while developing in
this area. If anyone has any other information regarding solutions or
work-arounds I'd love to hear more. As it stands right now, we limit our use
of python to non-computational purposes, or when computation is required, we
limit the back and forth communication of python with the Maya API. When we
need something done fast, we do it in a c++ plugin and expose what we need
as arguments to a command, or inputs on a node. Again, very limiting and
also not very portable, but in the end it yields a much more efficient
result.
(J. Baron)