Isotropix Forums

Royal Render submission script

Clarisse Scripting related topics

Royal Render submission script

Unread postby Arvid » Wed Nov 06, 2013 11:37 am

Hi folks, I've modified the Royal Render Nuke submission script for use with Clarisse, simply add it to the shelf for easy access by right-clicking it and choosing "Add item". I tried modifying the shelf config files but that doesn't seem to work. It would be easier to install this sort of thing if you only need to drop a file in a directory, but this will do for now!

Usage: Select images you want to render and run the script.

Question to Isotropix: How do I find all images in a project through scripting? And how would I accomodate for layers within images that have write enabled?

Enjoy :mrgreen:

python code

# Royal Render Plugin script for Nuke 5+
# Author: Royal Render, Holger Schoenberger, Binary Alchemy
# Last change: v 6.01.70
# Copyright (c) 2009-2012 Holger Schoenberger - Binary Alchemy
# rrInstall_Copy: \plugins\
# rrInstall_Change_File: \plugins\menu.py, before "# Help menu", "m = menubar.addMenu(\"RRender\");\nm.addCommand(\"Submit Comp\", \"nuke.load('rrSubmit_Nuke_5'), rrSubmit_Nuke_5()\")\n\n"
#
# Modified for use with Isotropix Clarisse 1.5 by Arvid Bjorn
#

ix.enable_command_history()

import os
import sys
import platform
import random
import string

from xml.etree.ElementTree import ElementTree, Element, SubElement


#####################################################################################
# This function has to be changed if an app should show info and error dialog box #
#####################################################################################

def writeInfo(msg):
ix.log_info(msg)

def writeError(msg):
ix.log_warning(msg)


##############################################
# JOB CLASS #
##############################################


class rrJob(object):
"""Stores scene information """
version = ""
software = ""
renderer = ""
requiredPlugins = ""
sceneName = ""
sceneDatabaseDir = ""
seqStart = 0
seqEnd = 100
seqStep = 1
seqFileOffset = 0
seqFrameSet = ""
imageWidth = 99
imageHeight = 99
imageDir = ""
imageFileName = ""
imageFramePadding = 4
imageExtension = ""
imagePreNumberLetter = ""
imageSingleOutput = False
sceneOS = ""
camera = ""
layer = ""
channel = ""
maxChannels = 0
channelFileName = []
channelExtension = []
isActive = False
sendAppBit = ""
preID = ""
waitForPreID = ""
CustomA = ""
CustomB = ""
CustomC = ""
LocalTexturesFile = ""

def __init__(self):
pass

# from infix.se (Filip Solomonsson)
def indent(self, elem, level=0):
i = "\n" + level * ' '
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + " "
for e in elem:
self.indent(e, level + 1)
if not e.tail or not e.tail.strip():
e.tail = i + " "
if not e.tail or not e.tail.strip():
e.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
return True

def subE(self, r, e, t):
sub = SubElement(r, e)
sub.text = str(t)
return sub

def writeToXMLstart(self, submitOptions ):
rootElement = Element("RR_Job_File")
rootElement.attrib["syntax_version"] = "6.0"
self.subE(rootElement, "DeleteXML", "1")
self.subE(rootElement, "SubmitterParameter", submitOptions)
# YOU CAN ADD OTHER NOT SCENE-INFORMATION PARAMETERS USING THIS FORMAT:
# self.subE(jobElement,"SubmitterParameter","PARAMETERNAME=" + PARAMETERVALUE_AS_STRING)
return rootElement

def writeToXMLJob(self, rootElement):

jobElement = self.subE(rootElement, "Job", "")
self.subE(jobElement, "Software", self.software)
self.subE(jobElement, "Renderer", self.renderer)
self.subE(jobElement, "RequiredPlugins", self.requiredPlugins)
self.subE(jobElement, "Version", self.version)
self.subE(jobElement, "SceneName", self.sceneName)
self.subE(jobElement, "SceneDatabaseDir", self.sceneDatabaseDir)
self.subE(jobElement, "IsActive", self.isActive)
self.subE(jobElement, "SeqStart", self.seqStart)
self.subE(jobElement, "SeqEnd", self.seqEnd)
self.subE(jobElement, "SeqStep", self.seqStep)
self.subE(jobElement, "SeqFileOffset", self.seqFileOffset)
self.subE(jobElement, "SeqFrameSet", self.seqFrameSet)
self.subE(jobElement, "ImageWidth", int(self.imageWidth))
self.subE(jobElement, "ImageHeight", int(self.imageHeight))
self.subE(jobElement, "ImageDir", self.imageDir)
self.subE(jobElement, "ImageFilename", self.imageFileName)
self.subE(jobElement, "ImageFramePadding", self.imageFramePadding)
self.subE(jobElement, "ImageExtension", self.imageExtension)
self.subE(jobElement, "ImageSingleOutput", self.imageSingleOutput)
self.subE(jobElement, "ImagePreNumberLetter", self.imagePreNumberLetter)
self.subE(jobElement, "SceneOS", self.sceneOS)
self.subE(jobElement, "Camera", self.camera)
self.subE(jobElement, "Layer", self.layer)
self.subE(jobElement, "Channel", self.channel)
self.subE(jobElement, "SendAppBit", self.sendAppBit)
self.subE(jobElement, "PreID", self.preID)
self.subE(jobElement, "WaitForPreID", self.waitForPreID)
self.subE(jobElement, "CustomA", self.CustomA)
self.subE(jobElement, "CustomB", self.CustomB)
self.subE(jobElement, "CustomC", self.CustomC)
self.subE(jobElement, "LocalTexturesFile", self.LocalTexturesFile)
for c in range(0,self.maxChannels):
self.subE(jobElement,"ChannelFilename",self.channelFileName[c])
self.subE(jobElement,"ChannelExtension",self.channelExtension[c])
return True



def writeToXMLEnd(self, f,rootElement):
xml = ElementTree(rootElement)
self.indent(xml.getroot())

if not f == None:
xml.write(f)
f.close()
else:
print("No valid file has been passed to the function")
try:
f.close()
except:
pass
return False
return True



##############################################
# Global Functions #
##############################################

def getRR_Root():
if os.environ.has_key('RR_ROOT'):
return os.environ['RR_ROOT']
HCPath="%"
if ((sys.platform.lower() == "win32") or (sys.platform.lower() == "win64")):
HCPath="\\\\dvs\\dvs02\\Assets\\RoyalRender"
elif (sys.platform.lower() == "darwin"):
HCPath="%RRLocationMac%"
else:
HCPath="%RRLocationLx%"
if HCPath[0]!="%":
return HCPath
writeError("This plugin was not installed via rrWorkstationInstaller!")


def getNewTempFileName():
random.seed()
if ((sys.platform.lower() == "win32") or (sys.platform.lower() == "win64")):
if os.environ.has_key('TEMP'):
nam=os.environ['TEMP']
else:
nam=os.environ['TMP']
nam+="\\"
else:
nam="/tmp/"
nam+="rrSubmitClarisse_"
nam+=str(random.randrange(1000,10000,1))
nam+=".xml"
return nam

def getRRSubmitterPath():
''' returns the rrSubmitter filename '''
rrRoot = getRR_Root()
if ((sys.platform.lower() == "win32") or (sys.platform.lower() == "win64")):
rrSubmitter = rrRoot+"\\win__rrSubmitter.bat"
elif (sys.platform.lower() == "darwin"):
rrSubmitter = rrRoot+"/bin/mac/rrSubmitter.app/Contents/MacOS/rrSubmitter"
else:
rrSubmitter = rrRoot+"/lx__rrSubmitter.sh"
return rrSubmitter


def getOSString():
if ((sys.platform.lower() == "win32") or (sys.platform.lower() == "win64")):
return "win"
elif (sys.platform.lower() == "darwin"):
return "osx"
else:
return "lx"


def submitJobsToRR(jobList,submitOptions):
tmpFileName = getNewTempFileName()
tmpFile = open(tmpFileName, "w")
xmlObj= jobList[0].writeToXMLstart(submitOptions)
for submitjob in jobList:
submitjob.writeToXMLJob(xmlObj)
ret = jobList[0].writeToXMLEnd(tmpFile,xmlObj)
if ret:
writeInfo("Job written to " + tmpFile.name)
else:
writeError("Error - There was a problem writing the job file to " + tmpFile.name)
os.system(getRRSubmitterPath()+" \""+tmpFileName+"\"")



###########################################
# Read Nuke file #
###########################################

def rrSubmit_fillGlobalSceneInfo(newJob):
newJob.version = "1.5" # How do I find the Clarisse version?
newJob.software = "Clarisse"
newJob.sceneOS = getOSString()


def rrSubmit_CreateAllJob(jobList,noLocalSceneCopy):
newJob= rrJob()


def getFileFormat(id):
if id==0: return ".exr"
if id==1: return ".exr"
if id==2: return ".jpg"
if id==3: return ".bmp"
if id==4: return ".tga"
if id==5: return ".png"
if id==6: return ".png"
if id==7: return ".tif"
if id==8: return ".tif"
if id==9: return ".tif"
return ""

def getProjectPath():
path = ix.application.get_factory().get_vars().get("PDIR").get_string() + "/"
project_file = ix.application.get_factory().get_vars().get("PNAME").get_string()

if project_file.find(".project") == -1: project_file += ".project"

project = path + project_file

return path, project, project_file



def rrSubmit_CreateSingleJobs(jobList):

path, project, project_file = getProjectPath()

if ix.selection.get_count() == 0:
writeError("Please select one or more Images!")
return False
else:

for i in range(ix.selection.get_count()):
item = ix.selection[i]
if os.environ.has_key('PNAME'): writeInfo("Name: "+os.environ['PNAME'])


if item.is_kindof("Image"):
enabled = item.attrs.render_to_disk[0]
if enabled:
newJob= rrJob()
rrSubmit_fillGlobalSceneInfo(newJob)
newJob.sceneName = project_file
newJob.isActive = True
newJob.sceneName = project
newJob.sceneDatabaseDir = path
newJob.layer = item.get_full_name()
first_frame = item.attrs.first_frame[0]
last_frame = item.attrs.last_frame[0]

save_as = item.attrs.save_as[0]
pad = save_as.count("#")
if pad > 0: newJob.imageFramePadding = pad

newJob.imageFileName = save_as

newJob.imageExtension = getFileFormat(item.attrs.format[0])
newJob.seqStart = first_frame
newJob.seqEnd = last_frame

jobList.append(newJob)

return True



def rrSubmit_Clarisse_1():
writeInfo ("rrSubmit v 6.01.70")
path, project, project_file = getProjectPath()

jobList= []
noLocalSceneCopy= [False]
#rrSubmit_CreateAllJob(jobList,noLocalSceneCopy)
success = rrSubmit_CreateSingleJobs(jobList)
submitOptions=""
if (noLocalSceneCopy[0]):
submitOptions="AllowLocalSceneCopy=0~0"
if success:
ix.save_project(project)
submitJobsToRR(jobList,submitOptions)


rrSubmit_Clarisse_1()



ix.disable_command_history()
Last edited by Arvid on Wed Nov 06, 2013 11:52 am, edited 2 times in total.
Arvid
 
Posts: 191
Joined: Thu Jan 31, 2013 4:44 pm

Re: Royal Render submission script

Unread postby sam » Wed Nov 06, 2013 11:45 am

Cool! Thanks for sharing! I put this topic as sticky.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 995
Joined: Sat Jan 26, 2013 12:33 am

Re: Royal Render submission script

Unread postby support_team » Wed Nov 06, 2013 12:17 pm

Arvid wrote:Question to Isotropix: How do I find all images in a project through scripting? And how would I accomodate for layers within images that have write enabled?

To get all images in the project just:

python code

objects = ix.api.OfObjectArray()
ix.application.get_factory().get_all_objects("Image", objects)


To get layers from an image (ModuleImage)

python code

# return the array of layers in an image
img.get_module().get_layers()
Isotropix
Support Team
User avatar
support_team
 
Posts: 1007
Joined: Thu Jan 31, 2013 12:10 pm

Re: Royal Render submission script

Unread postby Arvid » Wed Nov 06, 2013 12:22 pm

Thanks! I'll take a crack at adding support for layers.

Another question, I tried modifying the shelf files, but nothing appears in the gui, the only way I can add it is through "Add item" in the gui. Is this locked like that by design?
Arvid
 
Posts: 191
Joined: Thu Jan 31, 2013 4:44 pm

Re: Royal Render submission script

Unread postby justin » Fri Nov 06, 2015 2:20 am

This post is super old, but I thought I'd comment that finding the version of clarisse can be done with:

ix.application.get_version()
justin
 
Posts: 8
Joined: Tue Oct 06, 2015 1:24 am


Return to Scripting