Every once in a while I’ll see someone asking whether they should use Python or C++ for a plugin they’re writing. It’s one of those questions that seems highly subjective until you realize there’s plenty of situations where there’s only one right answer.
My original plan was to write a detailed post where I went over the pros and cons of each but I think it’s better to just bottom-line it for you. The following is my (informed) opinion and is intended to be applicable to Maya plugins only.
When to use C++
If you’re doing anything that’s computationally intensive, you should use C++. Writing a deformer? Use C++. Shader? C++. Iterating over thousands of items (verts, meshes, etc)? You get the idea.
Why? Well, in my experience, if you implement the exact same algorithm in C++ as Python, you’ll usually get at least a 10x speed boost from C++!
Also, Maya’s MIt* iterator classes are waaay faster in C++.
When to use Python
If you’re implementing a node that deals with asset management or some other part of your pipeline, you can’t beat Python! Python is great for string manipulation, interacting w/ the OS, and you can natively call anything in maya.cmds (or maya.mel, maya.utils, etc). No need to wrap it in MGlobal::executeCommand.
Let’s say you’re tasked with writing some fancy node whose job is to keep the referenced asset grouped under it up-to-date (i.e., always referencing from the latest version). A simple approach might be to identify the file the asset came from, extract the version number from the filename, and check whether there are any higher versions in that same directory. Python makes all that very easy and the speed lost by not using C++ is so negligible that it can be measured in milliseconds!
Use C++ if you need the speed, if every millisecond counts, or if you need to do a lot of iteration over scene elements. Use Python if your primary functionality revolves around something other than math.