Home Coding, Scripting, Shaders

PYTHON Highlevel intro to Python in Maya (cmds, Pymel, Openmaya 1.0 & 2.0)

polycounter lvl 12
Offline / Send Message
hannes d polycounter lvl 12
Hello,

Here is a video I made discussing the various types of Python available in Maya. And when to use which API.
A lot of people still use cmds, and haven't discovered the advantages of Pymel yet. Hopefully this will help spreading the word.
The official Autodesk intro is also great at comparing both of them.
And I go over some examples in my video.

https://www.youtube.com/watch?v=xniqGsWb3uo

Let me know what you think, if you agree/disagree. Would be great to get more people talking about Python in Maya instead of MEL. incase above embed doesn't work here is the direct link: https://www.youtube.com/embed/xniqGsWb3uo

Replies

  • neilberard
    Online / Send Message
    neilberard polycounter lvl 17
    I like the idea of Pymel, but I have found that it is way too slow for any real production use. I used to work with it all the time, but as my code grew, the sluggish performance became quite noticeable. If you are having to switch to OpenMaya for most procedures to speed up performance, I don't see what the real benefit of using Pymel is.
  • Deadly Nightshade
    Offline / Send Message
    Deadly Nightshade polycounter lvl 10
    I like the idea of Pymel, but I have found that it is way too slow for any real production use. I used to work with it all the time, but as my code grew, the sluggish performance became quite noticeable. If you are having to switch to OpenMaya for most procedures to speed up performance, I don't see what the real benefit of using Pymel is.
    That's a very broad generalization - borderline trash talk. Too slow for what? Material managers? UV tools? Exporters? Auto-riggers? I have worked on everything of that except the latter (rigging is not my thing) and I've never had any performance problems what so ever.

    The real benefit is that developing tools with PyMEL is just faster than it is with Maya API (iteration time is faster). Your code is more readable and it's easier to maintain by more people +easier for companies to hire Technical Artists who can continue maintaining and developing pre-existing tools. (Bottom line here is that most TA's can't even read C++, and/or they struggle with wrapping their heads around how the Maya API work - even if written in Python using the OpenMaya library).

    Also: PyMEL has an object-oriented approach and it's big amount of utility functions means you write less code. Getters and setters for pretty much everything and the fact that everything is an object and not a string is just superior to the alternative of writing verbose code with the -edit flag on every single command, or doing string parsing and other silly workarounds (which you will do when working with Maya.cmds)

    OpenMaya and the Maya API is real useful - especially for things like mesh processing or any other case where you wanna loop over a big amount of mesh components (like retrieving UV shells or copying vertex colors between channels, or making a deformer). In such cases then it doesn't matter if you chose PyMEL or Maya.cmds - both alternatives are slow in comparison and should be avoided at all costs.

    No the best approach is to write your tools in Maya.cmds or PyMEL, release an MVP of your tool to the Art team and then get feedback from them while you work on optimizing the slower parts - like getting rid of unecessary selection-behavior or string processing. Then you replace those parts in your Python code with some OpenMaya-based functions for v2 of your tool - something that can use the MItMesh -iterators and loop over component indices instead of dealing with dumb strings. That is a good, iterative approach that is favorable in production environments. Heck even if you know from day 1 that what you need is a C++ plugin I still believe that developing with Python and OpenMaya is quicker for the first few versions of the tool: it's easier to test things live in the script editor than it is to compile a build in Visual Studio every time you do a tiny change.
  • neilberard
    Online / Send Message
    neilberard polycounter lvl 17
    That's a very broad generalization - borderline trash talk. Too slow for what? Material managers? UV tools? Exporters? Auto-riggers? I have worked on everything of that except the latter (rigging is not my thing) and I've never had any performance problems what so ever.

    No trash talk, I was just stating that the performance does not suit my needs for production and I no longer use pymel for that reason.

    I don't see readability as an issue, if the implementation is difficult to read, you can always wrap up stuff yourself by writing your own functions or classes and comment on what you are doing.

    Any procedure that instantiates and manipulates a lot of PyNodes is going to take a hit, that can be significant depending on what the task is. I know a lot of folks who love pymel, but personally think the cost outweighs the benefits.

     As you mentioned about setting up an MVP or proof of concept to show the team prior to writing it the "real" way: if using cmds is 10-20x faster, doesn't it make sense to go with that for testing out code? Processing vertices or joints can be seconds as opposed to minutes without having to write C++ or Open Maya. If you are experimenting with ideas, that can be a big deal. There are a number of sites that discuss the difference with performance in length. I think it's totally worth discussing the pros and cons of pymel. At the end of the day, do whatever works for you.
    http://patrickvfx.blogspot.com/2017/04/pymelcore-versus-mayacmds.html#.X0rBRchKiUl
  • neilberard
    Online / Send Message
    neilberard polycounter lvl 17
    @Deadly Nightshade
    I don't want to beat a dead horse, but I figured I would add some of my own speed comparisons... for science. I'm using Maya 2018 btw, maybe Pymel is way faster in newer versions.

    Pymel import time: 1.0759999752 seconds
    Cmds import time: 0.00200009346008 seconds
    Importing Cmds is 537.974848015x faster than Pymel
    Pymel List 1000 scene objects time: 0.0829999446869 seconds
    Cmds List 1000 scene objects time: 0.00300002098083 seconds
    Cmds is 27.6664547405x faster than Pymel

    Maybe that's not a big deal for most folks.

  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter
    Tbh, I've found that for situations where performance is an issue cmds isn't faster enough to make me want to use it over pymel. 

    There's no doubt that pymel is slower - noticeably so in many situations - but if you're really interested in speed you don't want to be using python or even doing the work in Maya if you can avoid it. 


Sign In or Register to comment.