Fast(est?) get attr for each frame.

*update. Found another method. still open maya with mdg time is faster. But this is not half bad.


the “om_plug_as_double_mdg_set_time” function is the fastest I could find.
be careful with currentTime eval=False and cmds.keyframe. Scroll down for the script.


Soooo I had to export a bunch of data (10k+ maya files) for some dataset.
Which forced me to find a fast way to export attrbutes per frame.
(And it also had to work in mayapy)

And I dint want to have to dive into a c++ plugin or anything.

So I compared a bunch of different ways that i know to getAttr and updating the maya time.

1. Dont use cmds.currentTime(frameNr, eval=False) !!
This results in the attribute dg not being evaluated. sooooo its useless.

2. cmds.keyframe(attr, query=True, eval=True)
This only evaluates the active anim layer’s keyframe data.
And changing the active anim layer in mayapy is a nightmare soooo… yeah don’t use it. Also it only works if there are keyframes set. So a channel with a constraint will not return any value.

So for testing i made a simple sphere and 2 additive anim layers with some animation in them.


Timings with a sphere:

Shortest duration for each function tested 100 times:


Timing with a heavier scene with skinning and constraints.

Timing becomes more clear this way.

Code should mostly speak for itself.
If you have any questions just ask.



Leave a Reply

Your email address will not be published. Required fields are marked *