2012-04-13

prSelectionUi - dynamic Maya Python UI

(The script got updated in December 2012, so there are some inaccuracies in this post now)


prSelectionUi - Animation UI (Maya)


This post is about my prSelectionUi.py Maya script, which was written in PyMEL. It is made to manage selections and poses. This can be useful during animation. The main problem were the dynamic UI elements and how to save/load the information in Maya

This script might also be a decent example on how to write PyMEL UI code? I am not sure, since I have not seen any other PyMEL UI scripts. I just used some features from the PyMEL documentation and the posting of one of the PyMEL authors, which is mentioned at the end of this post.

I have made selection UIs before, but they had to be made for each project. This UI is flexible and should work for any project. To save the rigger time, but also allow the animator to create the selections they want on the fly. The attached video shows all the functionality and there is also the open-source download link in the Vimeo video description.

The idea came from an animator friend (Harry Fast), who was not happy with the existing freely available selection scripts. So he asked me to create a new one. It is written in PyMEL and stores all information in Maya sets. That way you can create selections in the rig-file and the script can read those sets in the animation-shot (with referenced rig file). Also the animator can always create their own selections and import/export the sets between scenes.

The code can be summarized as six classes (UI, Tab, TabElement, Pose (TabElement), Selection (TabElement), Member), which inherit from Maya UI elements (window, formlayout, menuItem). There are maya-sets for tabs, selections and poses. The member information is stored in the selection-set attributes. The set types are identified with custom attributes. That way the scene-name of the set is not important. Also it is no problem if there are name clashes. If the set is from a reference file, the attributes can be edited in the shot. (If the animator is not happy with the default order/colors). Because all elements are dynamic I did not split the UI from the functionality. But I don't have a lot of UI programming experience, so I don't know the normal way. In the past I only created UIs the Maya/MEL way. But I am happy with the current classes, because it was easy to add new features and modify the existing ones.
The basic idea to inherit from PyMEL UI elements was from this post of Ofer Koren: http://www.mail-archive.com/python_inside_maya@googlegroups.com/msg01015.html

Here is a simple UML generated from the code using PyNSource - UML tool for Python. (It does not show that UI, Tab, TabElement and Member inherit from Maya UI elements.)

No comments:

Post a Comment