mrv, pymel, and "monkey-patching"

49 views
Skip to first unread message

Tagore Smith

unread,
Apr 11, 2011, 10:09:09 AM4/11/11
to MRV Development Framework
Hi. I want to say first off that I'm really impressed with MRV. It's a
really tremendous piece of work.

A colleague and I have been working on some tools in Maya for a while,
and we've used some parts of MRV to avoid having to deal with the
messier aspects of the API. I really sped up some of our early
exploration. I think we are likely going to have to remove the
dependency on MRV from our code at some point soon, but even so it was
really useful in helping us make quick progress at the beginning of or
work. So thank you very much for all the hard work you've put into it.

One of the reasons that we are going to have to remove the dependency
is that MRV makes too many changes to the Maya Python environment for
our use cases. I guess there is no way around this if MRV is to do
what you intend it to do. I've been aware that this was the case since
pretty early on. I was hoping we could put off removing the dependency
for a while longer, at least until we had finished doing our internal
testing, but we ran into a bit of a snag recently. You might already
be aware of this, but I thought I would point it out just in case.

It's unfortunate, IMHO, that the normal Maya Python stuff is so un-
pythonic. One of the very nice things about MRV is that it adds things
like iteration to a lot of things that are best viewed as collections
in Python. And of course, in order to do that you have to implement
__len__ for these objects. Unfortunately doing this interacts badly
with Pymel. We need to use our tools in a running Maya without
stepping on Pymel.

The main problem we've found (so far) here is that when printing
objects Pymel checks the truth value of Attribute objects. A non-array
attribute would normally evaluate as True, but because the added
__len__ method returns zero it winds up evaluating as False, and Pymel
throws an exception. For the moment we have been able to work around
this by also implementing __nonzero__ on the Attribute class. I'm not
sure if this might have other undesirable effects, but if not you
might consider adding it to MRV.

Anyway, like I said, we're really impressed with MRV. It's too bad
that in order to get the behavior that makes MRV so nice in the first
place you have to change a fair bit about the Python for Maya
environment. It's not immediately clear to me how you could get that
behavior without doing so though, so there may not be any way around
it.

Thanks
Tagore Smith

Tagore Smith

unread,
Apr 14, 2011, 11:07:58 AM4/14/11
to MRV Development Framework
I was a bit inaccurate in what I wrote above, so let me correct it a
bit. The problem is the __len__ method on MPlug- it manifests itself
when Pymel tries to print an instance of the Pymel Attribute class.
Sorry about that.

Thanks
Tagore Smith

Sebastian Thiel

unread,
Apr 18, 2011, 1:47:33 PM4/18/11
to mrv...@googlegroups.com, Tagore Smith
Hi Tagore,

First of all, sorry for the late reply, but I was disconnected from the
internet during the past week - some may call it holiday ;).

The information about the cause of the pymel breakage caused by mrv is
extremely useful - I noticed the issue myself, but couldn't figure out
the cause easily, and quickly gave up on it.

I will update mrv to work with maya 2012 in the next days, and in that
moment provide a fix for the issue. Either I find a way to apply my
changes without breaking pymel, or I won't apply them at all unless a
new configuration variable is set for backward compatibility.

Thanks again,
Sebastian

Sebastian Thiel

unread,
Apr 19, 2011, 12:44:54 PM4/19/11
to MRV Development Framework
In order to fix this issue, I had to replace the __len__ method on the
MPlug type with the length method. This changes the API, but causes
pymel to work as expected. Considering that length() is used on maya
vector like types as well, I believe this change fits nicely into the
maya API, even though it is less pythonic.

You can get the latest version on github (https://github.com/
organizations/mrv-developers) or on the python package index (http://
pypi.python.org/pypi/MRV).

Please let me know if you have any other issues, I am always willing
to help,
Sebastian

Tagore Smith

unread,
May 11, 2011, 10:26:12 AM5/11/11
to MRV Development Framework
On Apr 19, 12:44 pm, Sebastian Thiel <byron...@googlemail.com> wrote:
> In order to fix this issue, I had to replace the __len__ method on the
> MPlug type with the length method. This changes the API, but causes
> pymel to work as expected. Considering that length() is used on maya
> vector like types as well, I believe this change fits nicely into the
> maya API, even though it  is less pythonic.

Sorry to have taken so long to respond. Thanks a lot for taking as
look at this so quickly. I'll grab the new repository.

Thanks
Tagore Smith
Reply all
Reply to author
Forward
0 new messages