MAYA QUICK PROJECT MANAGER // PYTHON

A quick project manager/file launcher

Once you start getting a lot of projects on your hard drives, it
starts to be cumbersome to search for projects and files. Set project,
workspaces etc.

So i came up with an idea of building this script to load files and set
the workspace correctly with a couple of mouse clicks.

It searches the folder where you have your projects and then looks for
maya files (.mb)

Give it a try and let me know off any bugs you may find.

cheers all

Source code to put in your scripts directory. save it as projects.py.
Please refer to the comments on how to change paths to your setup.

'''
quick project manager to quickly load files
from your home projects directory

developed by Ricardo Viana June 2012
free to use and distribute

'''

import maya.cmds as cmds
import os

#home directory -> change to your projects folder
projectsDir= "/home/olheiros/maya/projects/"

# UI FUNCTION

def UI():

    #window
    if (cmds.window('projectwindow', exists=True)):
        print "window already open!!"
        cmds.deleteUI('projectwindow')

    win= cmds.window("projectwindow",title="Project Manager", w=360,h=360, mnb=False,mxb=False)

    cmds.columnLayout()

    cmds.separator(h=12)

    #projects option menu
    prjOptionMenu=cmds.optionMenu("prjOptionMenu",label="Projects:", w=350, h=35,cc=getfiles)

    #call function to populate it with projects
    populateProjects()

    cmds.separator(h=12)

    #text
    cmds.text("Scene files: DOUBLE CLICK TO OPEN")

    cmds.separator(h=12)

    #mayafiles textScrollList
    fileOptionMenu=cmds.textScrollList("fileOptionMenu", w=350, h = 250, dcc=load)

    #function to load files
    getfiles()

    #show User Interface
    cmds.showWindow(win)

#function to populate projects option menu
def populateProjects():

    #list the contents of the directory
    projects= os.listdir(projectsDir)

    #add each folder in the projects dir into option menu
    for project in projects :
        cmds.menuItem(label=project , parent="prjOptionMenu")

#function to populate files textScrollList
def getfiles(*args):

    #clean up textScrollList
    menuItems = cmds.textScrollList("fileOptionMenu", e=True, ra = True)

    #query the project selected in option Menu
    selectedProject = cmds.optionMenu("prjOptionMenu", q=True, v=True)

    #concatenate path to current project scenes folder
    project= str(projectsDir + selectedProject + "/scenes/")

    #list all files in scene directory
    scenefiles = os.listdir(project)

    #append each file to textScrollList if ends with ".mb"
    for file in scenefiles:
        if file.rpartition(".")[2]=="mb":
            cmds.textScrollList("fileOptionMenu",e=True,append=file )

#function to actually open double-clicked files on the list
def load(*args):

    #query selected project
    selectedProject = cmds.optionMenu("prjOptionMenu", q=True, v=True)

    #concatenate path to scenes dir
    project= str(projectsDir + selectedProject + "/scenes/")

    #query selected file
    selectedFile= cmds.textScrollList("fileOptionMenu", q=True, si= True)[0]

    #concatenate path to file 
    fileToLoad= str(project+selectedFile)

    #read file "at last!! hoohaa"
    cmds.file(fileToLoad, o=True, f=True)

    #change workspace to the file correspondent.
    workspacePath= projectsDir + selectedProject
    cmds.workspace(workspacePath, o=True)

    #deselect file and remove from list
    cmds.textScrollList("fileOptionMenu",e=True,ri=selectedFile, da=True)

    #print current workspace
    print "current workspace: \n" + (cmds.workspace(q=True,dir=True))

code to put in your shelf


import projects
projects.UI()


Advertisements

2 thoughts on “MAYA QUICK PROJECT MANAGER // PYTHON

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s