Your dedicated rigging-shelf - Sourcing multiple script at once to a shelf

by nikhatos posted 33 days ago | 7 comments

Hello there :-)

I have been looking all over the web for this, but with no luck;

I have a big pile of scripts for rigging. They are scattered around in different shelfs of mine, some for specific projects, some for characters etc.

Now, my main struggle/problem: Is there ANY WAY at all, to just go to my scripts folder, select all my (favourite) rigging scripts, drag and drop them (or something similarly easy) to a dedicated scriptinterface, to then make a shelf for me, instead of sourcing them again, one by one to a new shelf?

Hope it is clear, Have a nice one! nikhatos

by morganloomis posted 30 days ago

I have a tool for organising scripts into menus if that's helpful: Basically you just organise yours scripts in folders under an ml_toolbox_menu folder in your script directory, then the script will turn that folder hierarchy into a menu hierarchy on the maya menu bar. Script requirements are that MEL scripts need to have a global proc of the same name as the filename, and python files should have a main() or ui() function to be run.

by vshotarov posted 25 days ago

Nice! That's a real nice way to build UI elements.

It's very similar to what I have been doing, but your method requires so much less input, which would be great. The way I had set it up is that for every script I want to add to a shelf/markingMenu/menu I have to manually say something along the lines of shelf.addButton(script).

Having that managed by directories sounds so much better! Thanks for that!

by vshotarov posted 32 days ago

I just whipped up something quickly to do that. It's a bad bad code, but seems to do the job.

Just change the SHELF_NAME variable to whatever you want to call your shelf and run the code. It will open up a new maya window which is blank and you need to drag your files on to that window. It should create the shelf and exit.

Bear in mind if a shelf with the same name already exists, it will error out.

Tested on Windows 7 - Maya 16.5 and Maya 17

from maya import cmds as mc

    from PySide2.QtCore import *
    from PySide2.QtGui import *
    from PySide2.QtWidgets import *
    from PySide2.QtWebKitWidgets import QWebView, QWebPage, QWebInspector, QWebSettings
    from PySide2 import __version__
    from shiboken2 import wrapInstance
except ImportError:
    from PySide.QtCore import *
    from PySide.QtGui import *
    from PySide.QtWebKit import QWebView, QWebPage, QWebInspector, QWebSettings
    from PySide import __version__
    from shiboken import wrapInstance


def _buildShelf(scriptFiles):
    if mc.shelfLayout(SHELF_NAME, q=1, ex=1):
        mc.error("Shelf %s already exists. Aborting." % SHELF_NAME)

    if not scriptFiles:

    mc.shelfLayout(SHELF_NAME, p="ShelfLayout")

    for scriptFile in scriptFiles:
        fileName = scriptFile.split("/")[-1]
        extension = fileName.split(".")[-1]

        with open(scriptFile, "r") as f:
            data =

        source = "python"
        if extension == "mel":
            source = "mel"

        mc.shelfButton(iol=fileName.split(".")[0], l=fileName.split(".")[0], i="mayaIcon.png", c=data, stp=source)


    print "Shelf %s was created" % SHELF_NAME

class DropWidget(QWidget):
    def __init__(self, parent=None):
        super(DropWidget, self).__init__(parent)


    def dragEnterEvent(self, e):
        if e.mimeData().hasUrls():

    def dropEvent(self, e):
        _buildShelf([url.toLocalFile() for url in e.mimeData().urls()])

    def closeEvent(self, e):

dropper = DropWidget()
by nikhatos posted 30 days ago

Wow - impressive! ;) Thanks for the quick reply, so eager to try it out! Thank you!

by Voxel posted 32 days ago

Great share! That is really cool. I need to learn me some Pyside. This will let you pull your scripts (as well as native maya commands) from a search bar if that's more up your alley. Haven't personally tried it.

by nikhatos posted 30 days ago

Oh yeah the Cosmos tool - very handy indeed! Thanks for the input! ;)

by vshotarov posted 32 days ago

Yeah, it's such a great tool! I am not using it as I haven't had the time to sit down and migrate my stuff to it, but I always give it as a great tool example, as I feel we need more cool stuff like this in Maya.

And yeah, PySide is really handy! I have only recently started tinkering with it and it seems like it's not too difficult to grasp, but is very powerful.