Time before PyMel!

I’ve just spent all day updating some legacy code and thinking… damn, I wish this were in Pymel. It’s our main animation binder and part of it is responsible for restructuring the hierarchy, re-grouping stuff so we can insert offset nodes and remap things better when we have vast differences in skeletons. All the way through updating it I’d forgotten what a pain it is to do this sort of thing in Mel. Reparent that, update the string, move that … doooh, not found! eeeeeek

Been in Pymel for the lasy 6months and just take it for granted I can shift nodes round and still get them!

:slight_smile:

Yep,

PyMel’s underlying API DagNode hierarchy data is super valuable when rigging and doing lots of parenting.

I actually had the same thought about referencing. Pymel’s FileReference objects make writing referencing code…well let’s not say fun, but at least not Painful:D:

So, I’m revisiting some of our core tools and functions and bringing them into Python, firstly for ease and secondly because my brain’s been in Python to the point where mel now looks a mess :wink:

One thing that’s become obvious is the speed difference between Mel, Cmds and Pymel. Pymel is by far the best to code in and makes development far easier, but in certain cases when you need speed, Mel/Cmds are way faster.

Take something like this, a simple function to find a given attr on any transforms in the scene…



cmds:
markerAttrs=[n for n in cmds.ls(l=True,type='transform') if cmds.attributeQuery('markerAttr', exists=True, node=n)]

pymel:
markerAttrs=[n for n in pm.ls(l=True,type='transform') if n.hasAttr('markerAttr')]

mel:
string $markerAttrs[];
for($n in `ls -l -type "transform"`)
{
      if(`attributeQuery -exists -node $n "markerAttr"`)
     {
          $markerAttrs[`size $markerAttrs]=$n;
     }
}

On large scenes the pymel is much, much slower because internally it’s casting every transform in the scene to a pyNode and evaluating it. Its also wrapping the cmds, which is wrapping mel in the first place before sending to the mel command engine.

Just thought I’d share it. If you want speed in large loops, use cmds then cast the returns to pynodes once you’ve got what you need from them.

Mark

[QUOTE=Mark-J;6353]
[…]cmds, which is wrapping mel in the first place before sending to the mel command engine.
[/QUOTE]

Is it? I was under the impression that Python communicated with the command engine directly, but I don’t know that I’ve ever seen specific documentation to either effect.

Interesting.

I’m in the middle of optimizing my first big PyMEL tool right now and was starting to wonder how I would ever be able to make some part of it faster as it looks really simple and is structure that is usually quite fast in other languages.

I’ll try to use some cmds in there to see if it improves things.

It’s not that pymel is slow, not at all, it speeds things up in general. The thing that’s slow is large iterations where you’re effectively casting all nodes to PyNodes just for simple checking as in the example above.

I’ve noticed that. Been running the python profiler all day and any time I iterate over components and such in PyMEL it slows down extremely.

Example: By moving some lines over to python commands in a function that iterates over vertices, it cut the CPU time for it in my test scene from 86s to 4s…