Return to Snippet

Revision: 26138
at April 24, 2010 11:00 by throb


Updated Code
from pymel.core import *
import os
def infoPrint(info):
    print ('\n[INFO]: %s\n') % (info)
def errorPrint(error):
    print ('\n' + '='*20 + ' ERROR ' + '='*20 + '\n[ERROR] : ' + error + '\n' + '='*20 + ' ERROR ' + '='*20 + '\n')
    

def exportVRScene (cam, range, layer=''):
    '''Export a VRScene file based on settings:\n
    camera - the render camera\n
    range - the frame range (formatted like '5-100')\n
    layer - the render layer (optional, and uses the default if none specified)\n
    '''

    renderLayer = ''
    renderCam = ''
    
    infoPrint('Exporting VRScene with frame range %s' % range)
    startFrame = float(range.split('-')[0])
    endFrame = float(range.split('-')[1])
    if layer != '':
        if layer in ls (type='renderLayer'):
            renderLayer = layer

    for curCam in ls (type='camera'):
        if curCam == cam:
            renderCam = curCam

    if renderCam == '' :
        errorPrint ('camera %s not in scene' % (cam))
        sys.exit(1)
    else :
        if getAttr (cam + '.renderable') == 1:
            infoPrint('Using camera %s' % (cam))
        else:
            errorPrint('%s is not renderable!' % (cam))
            sys.exit(1)
    if layer != '' :
        if renderLayer == '' :    
            errorPrint('render layer %s not in scene' % (layer))
            sys.exit(1)
        else :
            infoPrint('Using layer %s' % (layer))
            editRenderLayerGlobals( currentRenderLayer=layer )
    
    # set up the vray shite here
    
    setAttr('defaultRenderGlobals.animation', 1)
    setAttr('defaultRenderGlobals.startFrame', startFrame)
    setAttr('defaultRenderGlobals.endFrame', endFrame)
    setAttr('defaultRenderGlobals.byFrameStep', 1)
    setAttr('vraySettings.animBatchOnly', 0)
    setAttr('vraySettings.fileNamePadding', 4)
    setAttr('vraySettings.runToAnimationStart', 0)
    setAttr('vraySettings.runToCurrentTime', 0)
    setAttr('vraySettings.vrscene_render_on', 0)
    setAttr('vraySettings.vrscene_on', 1)
    setAttr('vraySettings.misc_separateFiles', 0)
    setAttr('vraySettings.misc_eachFrameInFile', 0)
    setAttr('vraySettings.misc_meshAsHex', 1)
    setAttr('vraySettings.misc_compressedVrscene', 1)
    setAttr('vraySettings.sys_low_thread_priority', 1)
    setAttr('vraySettings.imgOpt_exr_compression', 3)
    setAttr('vraySettings.imgOpt_exr_bitsPerChannel', 16)
    setAttr('vraySettings.imgOpt_exr_attributes', 'testing=foo')
    
    tmpdir = os.environ['TEMP'].replace('\\','/')
    vrScene = tmpdir + '/export.vrscene'
    for curfile in os.listdir(tmpdir):
        if curfile[-7:] == 'vrscene':
            os.unlink (tmpdir + '/' + curfile)
            infoPrint('Removed existing vrscene : %s' % curfile)
    setAttr ('vraySettings.vrscene_filename', vrScene)
    # check to see if the renderlayer is blank.  if it is we don't export the layer.
    # simple eh?
    if layer != '':
        renderLayer = '-layer %s' % (renderLayer)
    else:
        renderLayer = ''
    vrendCommand = 'vrend -w 20 -h 20 -camera %s %s' % (renderCam, renderLayer)
    mel.eval (vrendCommand)
    if layer != '' :
        renderLayer = '_%s' % (layer)
    else :
        renderLayer = '_masterLayer'
        
    #if renderLayer == 'defaultRenderLayer': renderLayer = 'masterLayer'
    retVal = '%s/export%s.vrscene' % (tmpdir, renderLayer)
    infoPrint('Exported : %s' % (retVal))
    return retVal

Revision: 26137
at April 24, 2010 10:25 by throb


Updated Code
from pymel.core import *
import os
def infoPrint(info):
    print ('\n[INFO]: %s\n') % (info)
def errorPrint(error):
    print ('\n' + '='*20 + ' ERROR ' + '='*20 + '\n[ERROR] : ' + error + '\n' + '='*20 + ' ERROR ' + '='*20 + '\n')
    

def exportVRScene (cam, range, layer=''):
    '''Export a VRScene file based on settings:\n
    camera - the render camera\n
    range - the frame range (formatted like '5-100')\n
    layer - the render layer (optional, and uses the default if none specified)\n
    '''

    renderLayer = ''
    renderCam = ''
    
    print 'Exporting VRScene with frame range %s' % range
    startFrame = float(range.split('-')[0])
    endFrame = float(range.split('-')[1])
    if layer != '':
        if layer in ls (type='renderLayer'):
            renderLayer = layer

    for curCam in ls (type='camera'):
        if curCam == cam:
            renderCam = curCam

    if renderCam == '' :
        errorPrint ('camera %s not in scene' % (cam))
        sys.exit(1)
    else :
        if getAttr (cam + '.renderable') == 1:
            infoPrint('Using camera %s' % (cam))
        else:
            errorPrint('%s is not renderable!' % (cam))
            sys.exit(1)
    if layer != '' :
        if renderLayer == '' :    
            errorPrint('render layer %s not in scene' % (layer))
            sys.exit(1)
        else :
            infoPrint('Using layer %s' % (layer))
            editRenderLayerGlobals( currentRenderLayer=layer )
    
    # set up the vray shite here
    
    setAttr('defaultRenderGlobals.animation', 1)
    setAttr('defaultRenderGlobals.startFrame', startFrame)
    setAttr('defaultRenderGlobals.endFrame', endFrame)
    setAttr('defaultRenderGlobals.byFrameStep', 1)
    setAttr('vraySettings.animBatchOnly', 0)
    setAttr('vraySettings.fileNamePadding', 4)
    setAttr('vraySettings.runToAnimationStart', 0)
    setAttr('vraySettings.runToCurrentTime', 0)
    setAttr('vraySettings.vrscene_render_on', 0)
    setAttr('vraySettings.vrscene_on', 1)
    setAttr('vraySettings.misc_separateFiles', 0)
    setAttr('vraySettings.misc_eachFrameInFile', 0)
    setAttr('vraySettings.misc_meshAsHex', 1)
    setAttr('vraySettings.misc_compressedVrscene', 1)
    setAttr('vraySettings.sys_low_thread_priority', 1)
    setAttr('vraySettings.imgOpt_exr_compression', 3)
    setAttr('vraySettings.imgOpt_exr_bitsPerChannel', 16)
    setAttr('vraySettings.imgOpt_exr_attributes', 'testing=foo')
    
    tmpdir = os.environ['TEMP'].replace('\\','/')
    vrScene = tmpdir + '/export.vrscene'
    for curfile in os.listdir(tmpdir):
        if curfile[-7:] == 'vrscene':
            os.unlink (tmpdir + '/' + curfile)
            infoPrint('Removed existing vrscene : %s' % curfile)
    setAttr ('vraySettings.vrscene_filename', vrScene)
    # check to see if the renderlayer is blank.  if it is we don't export the layer.
    # simple eh?
    if layer != '':
        renderLayer = '-layer %s' % (renderLayer)
    else:
        renderLayer = ''
    vrendCommand = 'vrend -w 20 -h 20 -camera %s %s' % (renderCam, renderLayer)
    mel.eval (vrendCommand)
    if layer != '' :
        renderLayer = '_%s' % (layer)
    else :
        renderLayer = '_masterLayer'
        
    #if renderLayer == 'defaultRenderLayer': renderLayer = 'masterLayer'
    retVal = '%s/export%s.vrscene' % (tmpdir, renderLayer)
    infoPrint('Exported : %s' % (retVal))
    return retVal

Revision: 26136
at April 18, 2010 21:09 by throb


Updated Code
from pymel.core import *
import os

def exportVRScene (cam, range, layer='defaultRenderLayer'):
    print 'Exporting VRScene with frame range %s' % range
    startFrame = float(range.split('-')[0])
    endFrame = float(range.split('-')[1])
    renderLayers = ls (type='renderLayer')
    renderLayer = ''    
    for curLayer in renderLayers:
        if curLayer == layer:
            renderLayer = curLayer


    renderCam = ''
    for curCam in ls (type='camera'):
        if curCam == cam:
            renderCam = curCam

    if renderCam == '' :
        print 'Error : camera %s not in scene' % (cam)
    else :
        if getAttr (cam + '.renderable') == 1:
            print 'Using camera %s' % (cam)
        else:
            print '%s is not renderable!' % (cam)
    if renderLayer == '' :    
        print 'Error : render layer %s not in scene' % (layer)
    else :
        print 'Using layer %s' % (layer)
        editRenderLayerGlobals( currentRenderLayer=layer )
    
    # set up the vray shite here
    
    setAttr('defaultRenderGlobals.animation', 1)
    setAttr('defaultRenderGlobals.startFrame', startFrame)
    setAttr('defaultRenderGlobals.endFrame', endFrame)
    setAttr('defaultRenderGlobals.byFrameStep', 1)
    setAttr('vraySettings.animBatchOnly', 0)
    setAttr('vraySettings.fileNamePadding', 4)
    setAttr('vraySettings.runToAnimationStart', 0)
    setAttr('vraySettings.runToCurrentTime', 0)
    setAttr('vraySettings.vrscene_render_on', 0)
    setAttr('vraySettings.vrscene_on', 1)
    setAttr('vraySettings.misc_separateFiles', 0)
    setAttr('vraySettings.misc_eachFrameInFile', 0)
    setAttr('vraySettings.misc_meshAsHex', 1)
    setAttr('vraySettings.misc_compressedVrscene', 1)
    setAttr('vraySettings.sys_low_thread_priority', 1)
    
    tmpdir = os.environ['TEMP'].replace('\\','/')
    vrScene = tmpdir + '/export.vrscene'
    for curfile in os.listdir(tmpdir):
        if curfile[-7:] == 'vrscene':
            os.unlink (tmpdir + '/' + curfile)
            print 'Removed existing vrscene : %s' % curfile
    setAttr ('vraySettings.vrscene_filename', vrScene)
    vrendCommand = 'vrend -w 20 -h 20 -camera %s -layer %s' % (renderCam, renderLayer)
    mel.eval (vrendCommand)
    if renderLayer == 'defaultRenderLayer': renderLayer = 'masterLayer'
    retVal = '%s/export_%s_%s.vrscene' % (tmpdir, renderCam, renderLayer)
    return retVal
            


#vrScenePath = exportVRScene ('PoopFaceShape','1-100')

Revision: 26135
at April 18, 2010 19:31 by throb


Initial Code
import pymel.core as pm
import os

def exportVRScene (cam, range, layer='defaultRenderLayer'):
    print 'Exporting VRScene with frame range %s' % range
    startFrame = float(range.split('-')[0])
    endFrame = float(range.split('-')[1])
    renderLayers = ls (type='renderLayer')
    renderLayer = ''    
    for curLayer in renderLayers:
        if curLayer == layer:
            renderLayer = curLayer


    renderCam = ''
    for curCam in ls (type='camera'):
        if curCam == cam:
            renderCam = curCam

    if renderCam == '' :
        print 'Error : camera %s not in scene' % (cam)
    else :
        if getAttr (cam + '.renderable') == 1:
            print 'Using camera %s' % (cam)
        else:
            print '%s is not renderable!' % (cam)
    if renderLayer == '' :    
        print 'Error : render layer %s not in scene' % (layer)
    else :
        print 'Using layer %s' % (layer)
        pm.editRenderLayerGlobals( currentRenderLayer=layer )
    
    # set up the vray shite here
    
    setAttr('defaultRenderGlobals.animation', 1)
    setAttr('defaultRenderGlobals.startFrame', startFrame)
    setAttr('defaultRenderGlobals.endFrame', endFrame)
    setAttr('defaultRenderGlobals.byFrameStep', 1)
    setAttr('vraySettings.animBatchOnly', 0)
    setAttr('vraySettings.fileNamePadding', 4)
    setAttr('vraySettings.runToAnimationStart', 0)
    setAttr('vraySettings.runToCurrentTime', 0)
    setAttr('vraySettings.vrscene_render_on', 0)
    setAttr('vraySettings.vrscene_on', 1)
    setAttr('vraySettings.misc_separateFiles', 0)
    setAttr('vraySettings.misc_eachFrameInFile', 0)
    setAttr('vraySettings.misc_meshAsHex', 1)
    setAttr('vraySettings.misc_compressedVrscene', 1)
    setAttr('vraySettings.sys_low_thread_priority', 1)
    
    tmpdir = os.environ['TEMP'].replace('\\','/')
    vrScene = tmpdir + '/export.vrscene'
    for curfile in os.listdir(tmpdir):
        if curfile[-7:] == 'vrscene':
            os.unlink (tmpdir + '/' + curfile)
            print 'Removed existing vrscene : %s' % curfile
    setAttr ('vraySettings.vrscene_filename', vrScene)
    vrendCommand = 'vrend -w 20 -h 20 -camera %s -layer %s' % (renderCam, renderLayer)
    mel.eval (vrendCommand)
    if renderLayer == 'defaultRenderLayer': renderLayer = 'masterLayer'
    retVal = '%s/export_%s_%s.vrscene' % (tmpdir, renderCam, renderLayer)
    return retVal
            


# you can use a 3rd option to pick the layer you want to export
vrScenePath = exportVRScene ('PoopFaceShape','1-100')

Initial URL

                                

Initial Description
Currently supports exporting to VRScene only.  This will change over time.

Initial Title
VRay Utils for Maya 2011

Initial Tags

                                

Initial Language
Python