View Full Version : Maya API Python wrapper
10-13-2006, 09:01 AM
In another thread there is a bit about using python as a wrapper for writing plugins in mayas api located here:
Python isn't a compiled language so my question is how do wrappers work, e.g. does it still churn out a C++ plugin in the end, that operates at the same speed as if I'd written it in c++ in studio .net? Any useful info I should know about using a "wrapper".
Sorry if this is a stupid question :)
10-13-2006, 09:17 AM
Languages like python allow you to "bind" c/++ code to them, so when you run a command in python it will call the c++ equivalent. Often (as is the case with python) you can bind entire classes to the language, and even derive new classes in the scripting language from your c++ base class. The python docs contain a section on extending python that shows you how to do this. Or you can use boost::python to get the compiler to do the heavy lifting for you.
How fast it is depends on what you're trying to do. The usual approach to this kind of thing is to do the "grunt work" in c++, and use the scripting language to do the logic, essentially using python as the glue that assembles the c++ processing units together to form a program. This is essenitally what MEL is (just a little more complicated becuase of its tight relationship to the maya internals).
10-13-2006, 09:50 AM
thanks for the quick response :)
10-13-2006, 03:01 PM
here is another example for the curious http://www.swig.org/
10-20-2006, 07:17 AM
Python isn't a compiled language so my question is how do wrappers work, e.g. does it still churn out a C++ plugin in the end, that operates at the same speed as if I'd written it in c++ in studio .net?
No, if you write a Python plugin the Python code is executed while Maya is running just as it is the case with a C++ plugin. It's just the programming language that is different. As was already explained above in more detail, a Python wrapper for a C/C++ library (such as the Maya SDK) just makes the functionality of that library available to a Python program.
As Python is an interpreted language the code runs slower than equivalent C++ code. Whether or not this is really noticable depends on the actual plugin. If the bulk of the work is done in a Python extension module which is again implemented in C/C++ then you probably won't notice a big difference. Usually you should not use Python code for time-critical code segments but implement those in C++, either directly as a plugin or as a Python extension module. If execution time is not of primary concern and you rather want to reduce the time it takes to develop some functionality then it might be worth to have a look at Python.
- Matthias -
10-20-2006, 07:17 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2014, Jelsoft Enterprises Ltd.