talk.bindpose.com has been shut down on the 6th of March 2021. You can read a bit more about it here.

You are currently reading an archived copy of the latest content, with all the usernames deleted.

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

by user45 posted 09-11-2017 | 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 user46 posted 12-11-2017

I have a tool for organising scripts into menus if that's helpful: https://github.com/morganloomis/ml_tools/blob/master/ml_toolbox.py 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 user3 posted 17-11-2017

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 user3 posted 10-11-2017

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

try:
    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


SHELF_NAME = "Test" ## GLOBAL DEFINING THE NAME OF THE SHELF TO BUILD

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

    if not scriptFiles:
        return

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

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

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

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

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

    mc.setParent("..")

    print "Shelf %s was created" % SHELF_NAME

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

        self.setAcceptDrops(True)

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

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

    def closeEvent(self, e):
        self.deleteLater()


dropper = DropWidget()
dropper.show()

 

by user45 posted 12-11-2017

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

 

by user36 posted 10-11-2017

Great share! That is really cool. I need to learn me some Pyside. http://cosmos.toolsfrom.space/ 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 user45 posted 12-11-2017

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

 

by user3 posted 10-11-2017

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.