maya.cmds VS pyMel.core

maya.cmds VS pyMel.core

bayareadeck
Enthusiast Enthusiast
3,655 Views
4 Replies
Message 1 of 5

maya.cmds VS pyMel.core

bayareadeck
Enthusiast
Enthusiast

Can someone describe to me when I should use maya.cmds and when
to use pyMel.core ??

Accepted solutions (1)
3,656 Views
4 Replies
Replies (4)
Message 2 of 5

abogoev
Explorer
Explorer

Tl;DR

 

Just use PyMel(modern python in maya). When something won't work, use CMDS, and if you can't find it or get it working in CMDS(classic maya python), use MEL(old school maya scripting). This is pretty much the norm, lately. More experienced/older users tend to use CMDS and OpenMaya for some good reasons that you'll learn about later on(not important for starting off). There are reasons not to use PyMel sometimes, but you'll figure that out faster through trial and error(and reading docs) than trying to understand it before you've started programming.

 

Longer Explanation


It's an architecture preference, mostly. Would you rather write in an object oriented or functional way? That example is typescript, but the ideas are the same. OOP is considered more organized because it enforces an organizational structure, it's usually easier to read, and a lot of people find it easier to learn. People lean toward OOP for front-end (user interface) stuff, so web people lean heavily toward OOP.

CMDS is closer to the MEL commands that are core and original to Maya. Most menu commands run MEL, just because of legacy. Maybe that's changed in the latest Maya. This is an overview of maya's language architecture:

abogoev_0-1642380702751.png

(from Maya Python for Games and Film, one of the classic references, now)

 

Python has some features that are well geared for object oriented programming(OOP), so people that like writing in a "pythonic" style prefer PyMel because it has a PyNode object that has a bunch of methods. Some people worry PyMel is too slow. Imho the speed thing is more a question of functional vs OOP, it's easier to write fast procedures in a functional way than OOP. But a lot of people find OOP much easier to read, and a lot of the time "slow" is still 100x faster than some artist doing the same by hand.

0 Likes
Message 3 of 5

bayareadeck
Enthusiast
Enthusiast

Ok, thats very good info, thanks so much ! 

Should I concentrate on maya.cmds to start off ?

0 Likes
Message 4 of 5

Kahylan
Advisor
Advisor
Accepted solution

Pymel.core is a third party library created by LumaPictures in order to make the maya python workflow more intuitive and pythonic compared to using maya.cmds, which is the Maya inbuilt library that "just" translates MEL commands into Python. Which means it is better for programmers that know Pyhton to come in and start programming than maya.cmds because it has a lot more built in functions for basic tasks, such as searching the name of an object or iterating upwards int the hierarchy. But as far as I know, those functions still use MEL commands, they just do it as optimised as possible.
But it is worth mentioning that pymel is no longer included into the standart setup since Maya 2022, so people need to check the installation of pymel manually when installing Maya or install it via pip in order for scripts that include pymel to run properly.

Also as @abogoev mentioned there is OpenMaya, which is basically a python wrapper into the C++ API and therefore a lot faster than both maya.cmds and pymel.core, but also harder to use and more abstract because it is deeper in the language architecture.

 

Between those three OpenMaya is by far the most powerful and fastest, pymel.core and maya.cmds are about the same when it comes to performance. But Pymel is more aligned with the logic of other programs that support python.

I hope this helps!

Message 5 of 5

bayareadeck
Enthusiast
Enthusiast

 Awesome response as usual ! Really clarified many questions I had.

0 Likes