Hi Sam
Answers inline...
On Mon, 7 Dec 2015 11:37 PM <s...@weacceptyou.com> wrote:
Hi,
i think i am confused about some aspects of using c++ in maya.
so if i am writing a python script and want to use c++ occasionally, i just include openMaya and use the functionality of c++ but through a python wrapper right? which just means i will have the speed of c++ but it will be written in python so its easier and more straightforward to assemble?
Maya's lower level api is written in C++. As you know, this is not a scripting language, and must be introduced into Maya's system as a loaded plugin. Maya's scripting interfaces are MEL and Python.
How you access plugin interfaces depends on what they are. Some are commands, which extend the standard commands api with new functions. Some are custom nodes which can be created.
You can write plugins in both C++ and Python. C++ has the potential to perform better and Python has the potential to be easier to prototype and use. You can mix the two as needed.
So the c++ api, does this just mean pure c++?. Which can only be written through visual studio or something and compiled as a plugin for maya?
The C++ API is the C++ API. Exactly what it says. And api you can link against in C++ to extend Maya. You can write it in anything you want as long as you compile it according to the documented spec for the given Maya version.
There are python bindings on top of the C++ API, allowing you to call into that api from python.
I'm guessing this is even faster than using python API, but the drawbacks are that its very confusing and you will need to write alot more code to achieve the same effect as with python, but of course many times faster?
You may write more code. You may or may not find it more confusing, depending on how much C++ experience you have had. Whether it will be faster than python depends on what you are doing. If you create a sphere, you may not benefit from a lower level api. If you are looping over many things, or doing lots of number crunching, you may get large speed ups. You can also profile your code and find the hot spots, and write only portions of it in C++ to improve your critical paths.
im basically trying to figure out before i develop my script any further, the smartest way to write it. Do developers usually write everything c++ as plugin or do they use python just for ease until a point in the script that requires c++ then switch into that? - Or is it smarter in the long run just to do it all c++ and go nuts. I guess when using c++ API you cant mix with any other language like you can with python API?
A smart thing to do would be to prototype it in the language in which you are most efficient. Then you can profile it and see if there are any areas that are suffering from slowness. At that point you could either port it to a C++ plugin or rewrite parts of it.
I haven't written tons of different types of plugins, but I am pretty sure there are certain types of plugins that evaluate so often that they really should be C++. Maybe certain types of geometry, deformers, or shaders? Just depends how heavy they need to evaluate.
Even in the C++ API, the MGlobal class lets you call back into the MEL and Python interpreters.
anyway was just hoping for some clarity on the whole thing because im starting to learn c++ its tough,
It is tough learning C++. Especially if you have been spoiled for a long time with Python concepts. For me it took real production projects to actually get some confidence. Can't say it's the most enjoyable language. It's quirky and huge, but it isn't going anywhere anytime soon.
thanks,
Sam--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/6f7a4a42-70bf-44f2-b6d6-21ff31243c20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
An additional remark: The maya python API does not expose the whole C++ API functionality. Looking at the class list which is supported by python API can be useful.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2Osm9thBLNTVyAD5emXvayHC9Tr9Z2V4cGnrVz%3DB36Qw%40mail.gmail.com.