QuickReferencesSwitch : A QPS alternative when using Rename Prefix method...

Hi,
In my last blog post, I talked about the QuickProxiesSwitch, a good way to work between high-poly and low-poly meshes in the same scene.
Unfortunately, this couldn't work all the time, depending of your pipeline processes...

During my last year of animation studies, we had to produce an animation short-movie. To keep more time for creativity, I decided to use a Production asset management software. So we have contacted Shotgun Software to help us in our project, and they were very enthusiast about this ! Shotgun Software is developing a toolkit which permit us to link the software with all programs used in the production pipeline, like Maya.

This toolkit uses python scripts with a good organisation of folders and files : we can't be lost with that !

Unfortunately, their script use a system of Maya referenced files which isn't suitable for me. In fact, the script use a system of references replacements, and I prefer a proxies system to store all versions files metadata.

So it's impossible to add proxy to these references files, because the replacement creates a reference without namespaces, and no chance to get proxy with shared edits (because maya stores edits of the reference in its own namespace).

Here is the interesting part of the original script (source : https://github.com/shotgunsoftware/tk-maya-breakdown/blob/master/hooks/mayabreakdownupdate.py#L38 )

import maya.cmds as cmds  
import pymel.core as pm

def UI() :  
    if cmds.window("SVAV", exists = True) :
        cmds.deleteUI("SVAV")

    window = cmds.window("SVAV", title = "Switch Version Assets Variables", mnb = False, mxb = False, sizeable = False)

    mainLayout = cmds.columnLayout(rowSpacing=10, columnAlign= "center", columnOffset = ('both', 10) )

    cmds.separator(h = 10)

    cmds.text(label = "SVAV - Switch Variables Assets Versions v.1.0")
    cmds.separator(h = 20, visible = True)

    currentRNVersion = cmds.optionMenu("currentRNVersion", label = "Choose current Asset Version :    ")
    cmds.menuItem(label = "v001", parent = "currentRNVersion")
    cmds.menuItem(label = "v002", parent = "currentRNVersion")


    nextRNVersion = cmds.optionMenu("nextRNVersion", label = "Choose next Asset Version :        ")
    cmds.menuItem(label = "v001", parent = "nextRNVersion")
    cmds.menuItem(label = "v002", parent = "nextRNVersion")

    cmds.rowLayout( numberOfColumns=2, columnAlign=(1, 'right') )
    cmds.button(label = "Switch", w = 75, h = 30, command = switch)
    cmds.button( label='Close', w = 75, h = 30, command=('cmds.deleteUI(\"' + window + '\", window=True)') )


    cmds.showWindow(window)

def switch(*args) :  
    currentVersion = cmds.optionMenu("currentRNVersion", q = True, v = True)
    nextVersion = cmds.optionMenu("nextRNVersion", q = True, v = True)

    sel = cmds.ls(sl=True)

    for ref_obj in sel :
        reference_node = cmds.referenceQuery( ref_obj, referenceNode=True )
        rn_path = cmds.referenceQuery( ref_obj, filename=True )
        if "LowPoly" in rn_path :
            n_path = rn_path.replace("LowPoly", "HighPoly")
            new_path = n_path.replace( currentVersion, nextVersion )
            rn = pm.system.FileReference(reference_node)
            rn.replaceWith(new_path)
        else:
            n_path = rn_path.replace("HighPoly", "LowPoly")
            new_path = n_path.replace( currentVersion, nextVersion )
            rn = pm.system.FileReference(reference_node)
            rn.replaceWith(new_path)


UI()  

The script create a window where we can choose between 2 optionMenus the current version of the file, and the wanted version.
I think to ameliorate it but it works like a charm. The condition at the end is useful for me because I use different folder name to separate versions of my referenced files.

Edit : Script updated

With this, no need to choose the currentVersion option, it's automatically stored using the path of the current reference file.

import maya.cmds as cmds  
import pymel.core as pm

def UI() :  
    if cmds.window("SVAV", exists = True) :
        cmds.deleteUI("SVAV")

    window = cmds.window("SVAV", title = "Switch Variables Assets Versions", mnb = False, mxb = False, sizeable = False)

    mainLayout = cmds.columnLayout(rowSpacing=10, columnAlign= "center", columnOffset = ('both', 10) )

    cmds.separator(h = 10)

    cmds.text(label = "SVAV - Switch Variables Assets Versions v.1.0")
    cmds.separator(h = 20, visible = True)

    nextRNVersion = cmds.optionMenu("nextRNVersion", label = "Choose next Asset Version :        ")
    cmds.menuItem(label = "v001", parent = "nextRNVersion")
    cmds.menuItem(label = "v002", parent = "nextRNVersion")

    cmds.rowLayout( numberOfColumns=2, columnAlign=(1, 'right') )
    cmds.button(label = "Switch", w = 75, h = 30, command = switch)
    cmds.button( label='Close', w = 75, h = 30, command=('cmds.deleteUI(\"' + window + '\", window=True)') )


    cmds.showWindow(window)

def switch(*args) :  
    nextVersion = cmds.optionMenu("nextRNVersion", q = True, v = True)

    sel = cmds.ls(sl=True)

    for ref_obj in sel :
        reference_node = cmds.referenceQuery( ref_obj, referenceNode=True )
        rn_path = cmds.referenceQuery( ref_obj, filename=True )
        x = rn_path.split(".ma")[0]
        currentVersion = x[-4:]

        if currentVersion != nextVersion :
            new_path = rn_path.replace( currentVersion, nextVersion )
            rn = pm.system.FileReference(reference_node)
            rn.replaceWith(new_path)
        else :
            cmds.warning( "The referenced object is already loaded as " + currentVersion + " version.")
UI()