Example #1
0
    def save_preset(self, file_=None, use_mel=True, verbose=0):
        """Save preset for this node.

        Args:
            file_ (str): path to save preset at
            use_mel (bool): use mel to save preset
            verbose (int): print process data

        Returns:
            (str): preset path
        """
        _file = self._get_tmp_preset_path(use_mel=use_mel)
        if os.path.exists(_file):
            os.remove(_file)
        if use_mel:
            mel.eval('saveAttrPreset "{}" "tmp" false'.format(self))
        else:
            cmds.nodePreset(save=(self, "tmp"))
        lprint("SAVED PRESET", _file, verbose=verbose)
        if not os.path.exists(_file):
            raise RuntimeError('Failed to save preset: {}'.format(_file))

        if not file_:
            lprint("RETURNING ORIGINAL FILE", verbose=verbose)
            return _file

        shutil.move(_file, file_)
        return file_
Example #2
0
def vray_default_setup():
    mel.eval("setCurrentRenderer \"vray\";")
    if not cmds.objExists("vraySettings"):
        Utils.maya_print("Node 'vraySettings' must be initialized. Open render settings.")
        mel.eval("unifiedRenderGlobalsWindow;")

    presets = cmds.nodePreset(list="vraySettings")
    if "Vray_Default" in presets:
        cmds.nodePreset(load=("vraySettings", "Vray_Default"))
        Utils.maya_print("Vray now using default setup.")
Example #3
0
def createPresets(presetName, presetOrginal=['defaultRenderQuality', 'defaultRenderGlobals', 'defaultResolution'], set=1):
    # Check to see if the presetName exists?
    state = renderPresetExists( presetName, presetOrginal )
    if( state ):
        print("Preset Name: %s already exists." %presetName)
        return 0
    else:
        for preset in presetOrginal:
            cmds.nodePreset( save=[preset, presetName] )
        return 1
Example #4
0
def loadRemovePreset( presetName, presetOrginal=['defaultRenderQuality', 'defaultRenderGlobals', 'defaultResolution'] ):
    '''
    for preset in presets:
        cmds.nodePreset( load=[presetName, preset] )    
    for preset in presets:
        cmds.nodePreset( delete=[presetName, preset] )      
    '''
    for preset in presetOrginal:
        cmds.nodePreset( load=[preset, presetName] )    
        cmds.nodePreset( delete=[preset, presetName] )         
Example #5
0
def uiFunc_process_preset_change(obj, optionMenu):
    val = optionMenu.getValue()

    if val == "Save Preset":
        result = mc.promptDialog(title='Save Preset',
                                 message='Preset Name:',
                                 button=['OK', 'Cancel'],
                                 defaultButton='OK',
                                 cancelButton='Cancel',
                                 dismissString='Cancel')

        if result == 'OK':
            text = mc.promptDialog(query=True, text=True)
            if mc.nodePreset(isValidName=text):
                mc.nodePreset(save=(obj, text))
                optionMenu.clear()

                optionMenu.append("Load Preset")
                for a in mc.nodePreset(list=obj):
                    optionMenu.append(a)
                optionMenu.append("---")
                optionMenu.append("Save Preset")

                optionMenu.setValue(text)
            else:
                print "Invalid name, try again"
                optionMenu.setValue("Load Preset")
    elif mc.nodePreset(isValidName=val):
        if mc.nodePreset(exists=(obj, val)):
            mc.nodePreset(load=(obj, optionMenu.getValue()))
Example #6
0
def loadRemovePreset(presetName,
                     presetOrginal=[
                         'defaultRenderQuality', 'defaultRenderGlobals',
                         'defaultResolution'
                     ]):
    '''
    for preset in presets:
        cmds.nodePreset( load=[presetName, preset] )    
    for preset in presets:
        cmds.nodePreset( delete=[presetName, preset] )      
    '''
    for preset in presetOrginal:
        cmds.nodePreset(load=[preset, presetName])
        cmds.nodePreset(delete=[preset, presetName])
Example #7
0
def createPresets(presetName,
                  presetOrginal=[
                      'defaultRenderQuality', 'defaultRenderGlobals',
                      'defaultResolution'
                  ],
                  set=1):
    # Check to see if the presetName exists?
    state = renderPresetExists(presetName, presetOrginal)
    if (state):
        print("Preset Name: %s already exists." % presetName)
        return 0
    else:
        for preset in presetOrginal:
            cmds.nodePreset(save=[preset, presetName])
        return 1
Example #8
0
def uiFunc_make_display_line(parent, label="", text="", button=False, buttonLabel = ">>", buttonCommand=None, buttonInfo="", presetOptions=False, presetObj=None):
    _row = mUI.MelHSingleStretchLayout(parent,ut='cgmUISubTemplate',padding = _padding)        

    mUI.MelSpacer(_row,w=_padding)
    mUI.MelLabel(_row, 
                 l=label)

    uiTF = mUI.MelLabel(_row,ut='cgmUIInstructionsTemplate',l=text,
                                en=True)

    if button:
        cgmUI.add_Button(_row,buttonLabel,
                         buttonCommand,
                         buttonInfo)
    
    _row.setStretchWidget(uiTF)

    if presetOptions:
        presetMenu = mUI.MelOptionMenu(_row,useTemplate = 'cgmUITemplate')
        presetMenu.append("Load Preset")
        for a in mc.nodePreset( list=presetObj ):
            presetMenu.append(a)
        presetMenu.append("---")
        presetMenu.append("Save Preset")
        presetMenu(edit=True,
            value = "Load Preset",
            cc = cgmGEN.Callback(uiFunc_process_preset_change, presetObj, presetMenu) )
        
    mUI.MelSpacer(_row,w=_padding)

    _row.layout()

    return uiTF
Example #9
0
def renderPresetExists( presetName, presetOrginal=['defaultRenderQuality', 'defaultRenderGlobals', 'defaultResolution'] ):
    '''
    This function by default looks for presetNodes in the render global.
    '''
    state = 0
    for preset in presetOrginal:
        if( cmds.nodePreset( exists=[preset, presetName]) ):
            state = 1
    return state
Example #10
0
    def load_preset(self, file_, use_mel=True):
        """Load the given preset.

        Args:
            file_ (str): preset file to load
            use_mel (bool): preset was written using mel
        """
        _tmp_path = self._get_tmp_preset_path(use_mel=use_mel)
        test_path(os.path.dirname(_tmp_path))
        if file_ != _tmp_path:
            shutil.copy(file_, _tmp_path)
        if use_mel:
            _cmd = '{} "{}" "" "" "tmp" 1'.format(
                _get_load_preset_mel(), self)
            mel.eval(_cmd)
        else:
            cmds.nodePreset(load=(self, "tmp"))
        if file_ != _tmp_path:
            os.remove(_tmp_path)
Example #11
0
def hw(*args, **kwargs):
    t0 = float(time.time())
    try:
        verbose = kwargs["verbose"]
    except KeyError:
        verbose = False
        if cmds.optionVar(exists="checkmateVerbosity"):
            verbose = cmds.optionVar(query="checkmateVerbosity")
    else:
        pass

    scenefilename = cmds.file(query=True, sn=True, shn=True)
    root, ext = os.path.splitext(scenefilename)
    fullscenepath = cmds.file(query=True, sn=True, shn=False)
    fullscenedirname = os.path.dirname(fullscenepath)
    reportname = "".join([root, ext.replace(".", "_")])
    img_dir = os.path.join(fullscenedirname, reportname)

    print "save HW rendered images to : %s" % img_dir

    # before we render, save render globals presets
    cmds.nodePreset(save=("defaultRenderQuality", "ttRestorePreviousDefaultRenderViewPreset"))
    cmds.nodePreset(save=("defaultRenderGlobals", "ttRestorePreviousDefaultRenderViewPreset"))
    cmds.nodePreset(save=("defaultResolution", "ttRestorePreviousDefaultRenderViewPreset"))

    # override the user settings
    cmds.setAttr("defaultRenderGlobals.imageFormat", 32)
    ext = ".png"
    # set resolution ot 320x240
    cmds.setAttr("defaultResolution.width", 640)
    cmds.setAttr("defaultResolution.height", 480)
    cmds.setAttr("defaultResolution.deviceAspectRatio", (float(320) / float(240)))

    # set file format to png
    cmds.setAttr("defaultRenderGlobals.imageFormat", 32)
    ext = ".png"
    cmds.setAttr("defaultRenderGlobals.outFormatControl", 0)  # default name.ext
    cmds.setAttr("defaultRenderGlobals.animation", False)

    # cmds.setAttr('defaultRenderGlobals.imageFilePrefix', "../<Camera>", type="string")
    cmds.setAttr("defaultRenderGlobals.imageFilePrefix", "<Camera>", type="string")

    cmds.workspace(fileRule=["images", img_dir])
    print "save rendered images to : %s" % img_dir
    cmds.hwRender(currentFrame=True, cam="top", edgeAntiAliasing=[2, 4], fullRenderSupport=True)
    cmds.hwRender(currentFrame=True, cam="persp", edgeAntiAliasing=[2, 16], fullRenderSupport=True)
    cmds.hwRender(currentFrame=True, cam="front", edgeAntiAliasing=[2, 16], fullRenderSupport=True)
    cmds.hwRender(currentFrame=True, cam="side", edgeAntiAliasing=[2, 16], fullRenderSupport=True)

    # move rendererd images from the default project images dir to the report dir
    sourcedir = os.path.join(cmds.workspace(q=True, rd=True), cmds.workspace(fileRuleEntry="images"))
    targetdir = img_dir
    print "from : ", sourcedir
    print "to   : ", targetdir

    # for img in ['side.png', 'front.png', 'persp.png', 'top.png'] :
    #    os.rename(os.path.join(sourcedir, img),  os.path.join(targetdir, img))

    print "%-24s : %.6f seconds" % ("render.hw()", (float(time.time()) - t0))
    return img_dir
Example #12
0
def renderPresetExists(presetName,
                       presetOrginal=[
                           'defaultRenderQuality', 'defaultRenderGlobals',
                           'defaultResolution'
                       ]):
    '''
    This function by default looks for presetNodes in the render global.
    '''
    state = 0
    for preset in presetOrginal:
        if (cmds.nodePreset(exists=[preset, presetName])):
            state = 1
    return state
Example #13
0
import maya.cmds as cmds

# To determine if "My Special Settings" is a valid name for a preset (it
# is not because it contains spaces):
#
cmds.nodePreset(isValidName="My Special Settings")
# Result: 0 #
# To save the settings of nurbsSphereShape1 as a preset called "smithers":
#
cmds.nodePreset(save=("nurbsSphereShape1", "smithers"))
# To get a list of all presets available that could be applied to
# nurbsSphereShape1:
#
cmds.nodePreset(list="nurbsSphereShape1")
# Result: [u'smithers', u'smoothSphere', u'roughSphere', u'atmoSphere'] #
# To load the preset named "smoothSphere" onto nurbsSphereShape1:
#
cmds.nodePreset(load=("nurbsSphereShape1", "smoothSphere"))
# To delete the preset named "smithers" which was formerly available for the
# node nurbsSphereShape1 (and other nodes of the same type):
#
cmds.nodePreset(delete=("nurbsSphereShape1", "smithers"))
# To determine if a preset named "smithers" exists for the node
# nurbsSphereShape1 (it does not because it has been deleted):
#
cmds.nodePreset(exists=("nurbsSphereShape1", "smithers"))
# Result: 0 #
# Create a preset containing only the color and diffuse attributes:
#
cmds.nodePreset(save=("lambert1", "colorAndDiffuse"), attributes="color diffuse")
# Create a preset to map a checker texture to the applied node.
Example #14
0
def snapshots(*args, **kwargs):
    """ in GUI mode, renders snapshots of the model views
    returns reportsDir
    render_snapshots() -> string
    """
    t0 = float(time.time())
    try:
        verbose = kwargs["verbose"]
    except KeyError:
        verbose = False
        if cmds.optionVar(exists="checkmateVerbosity"):
            verbose = cmds.optionVar(query="checkmateVerbosity")
    else:
        pass

    # check that we;re running in GUI mode
    if cmds.about(batch=True):
        print "You can't create a render view in batch mode"
        return 1
    # turn off the heads-up diplay
    cmds.headsUpDisplay(layoutVisibility=False)

    # clear selection
    cmds.select(clear=True)

    _userWorkspaceDir = cmds.internalVar(userWorkspaceDir=True)
    scene = cmds.file(query=True, sn=True, shn=True) or "unknown.mb"
    (root, ext) = os.path.splitext(scene)
    fullscenepath = cmds.file(query=True, sn=True, shn=False) or "unknown.mb"
    fullscenedirname = os.path.dirname(fullscenepath)
    if fullscenedirname == "":
        fullscenedirname = os.path.join(_userWorkspaceDir, "reports")

    reportname = "".join([root, ext.replace(".", "_")])
    img_dir = os.path.join(fullscenedirname, reportname)

    # before we render, save render globals presets
    cmds.nodePreset(save=("defaultRenderQuality", "ttRestorePreviousDefaultRenderViewPreset"))
    cmds.nodePreset(save=("defaultRenderGlobals", "ttRestorePreviousDefaultRenderViewPreset"))
    cmds.nodePreset(save=("defaultResolution", "ttRestorePreviousDefaultRenderViewPreset"))

    # override the user settings
    cmds.setAttr("defaultRenderGlobals.imageFormat", 32)
    ext = ".png"
    # set resolution ot 320x240
    cmds.setAttr("defaultResolution.width", 320)
    cmds.setAttr("defaultResolution.height", 240)
    cmds.setAttr("defaultResolution.deviceAspectRatio", (float(320) / float(240)))

    # set file format to png
    cmds.setAttr("defaultRenderGlobals.imageFormat", 32)
    ext = ".png"

    # bring up the render view
    if not cmds.window("renderViewWindow", exists=True):
        cmds.RenderViewWindow()

    # cameras to render
    cameras = ["top", "front", "side", "persp"]

    for camera in cameras:
        mel.eval("".join(["renderWindowRenderCamera snapshot renderView ", camera]))
        image = "".join([camera, ext])
        # we can get the path from the report class instance
        imagepath = os.path.join(img_dir, image)
        if verbose:
            print "imagepath : %s " % imagepath
        # delete the images before saving
        cmds.sysFile(imagepath, delete=True)
        cmds.renderWindowEditor("renderView", edit=True, writeImage=imagepath)

    # restore the node presets
    # globalsNodes = cmds.renderer( 'mayaSoftware', query=True, globalsNodes=True)
    try:
        cmds.nodePreset(load=("defaultRenderQuality", "ttRestorePreviousDefaultRenderViewPreset"))
    except LockedAttrError:
        print "Cannot restore defaultRenderQuality to defaults"
    try:
        cmds.nodePreset(load=("defaultRenderGlobals", "ttRestorePreviousDefaultRenderViewPreset"))
    except LockedAttrError:
        print "Cannot restore defaultRenderGlobals to defaults"
    try:
        cmds.nodePreset(load=("defaultResolution", "ttRestorePreviousDefaultRenderViewPreset"))
    except LockedAttrError:
        print "Cannot restore defaultRenderGlobals to defaults"
    # turn the heads-up diplay back on
    cmds.headsUpDisplay(layoutVisibility=True)

    print "%-24s : %.6f seconds" % ("render.snapshots()", (float(time.time()) - t0))
    return img_dir
Example #15
0
import shutil, os.path
import maya.mel as mel
import maya.cmds as cmds

'''
# There are three preset nodes for render globals
cmds.nodePreset( ls='defaultRenderQuality' )
cmds.nodePreset( load=['defaultRenderQuality', 'aa'] )
cmds.nodePreset( load=['defaultRenderGlobals', 'aa'] )
cmds.nodePreset( load=['defaultResolution', 'aa'] )


# Revert render globals to default
# unifiedRenderGlobalsRevertToDefault;
import maya.mel as mel
mel.eval( 'unifiedRenderGlobalsRevertToDefault' )
string $plress[] = `listConnections defaultRenderGlobals.resolution`;
setAttr defaultRenderGlobals.imageFormat 20;
// 8 for jpg
setAttr defaultRenderGlobals.imageFormat 8;

setAttr ($plress[0]+".width") 50;
setAttr ($plress[0]+".height") 50;
setAttr -type "string" defaultRenderGlobals.imageFilePrefix "";
render camera1;
'''
imageTypes = { "gif": 0, "tiff": 3, "iff":7, "jpg":8, "tga":19, "bmp":20, 
    "png":32, "xpm": 63, "xpm2":50}
  
# 7 == "iff"
# 32 == "png" checked
Example #16
0
import shutil, os.path
import maya.mel as mel
import maya.cmds as cmds
'''
# There are three preset nodes for render globals
cmds.nodePreset( ls='defaultRenderQuality' )
cmds.nodePreset( load=['defaultRenderQuality', 'aa'] )
cmds.nodePreset( load=['defaultRenderGlobals', 'aa'] )
cmds.nodePreset( load=['defaultResolution', 'aa'] )


# Revert render globals to default
# unifiedRenderGlobalsRevertToDefault;
import maya.mel as mel
mel.eval( 'unifiedRenderGlobalsRevertToDefault' )
string $plress[] = `listConnections defaultRenderGlobals.resolution`;
setAttr defaultRenderGlobals.imageFormat 20;
// 8 for jpg
setAttr defaultRenderGlobals.imageFormat 8;

setAttr ($plress[0]+".width") 50;
setAttr ($plress[0]+".height") 50;
setAttr -type "string" defaultRenderGlobals.imageFilePrefix "";
render camera1;
'''
imageTypes = {
    "gif": 0,
    "tiff": 3,
    "iff": 7,
    "jpg": 8,
    "tga": 19,