Skip to content

Instantly share code, notes, and snippets.

@paulwinex
Created January 13, 2016 13:40
Show Gist options
  • Save paulwinex/0650ee24f7e89273b32d to your computer and use it in GitHub Desktop.
Save paulwinex/0650ee24f7e89273b32d to your computer and use it in GitHub Desktop.
Render current frame with arnold to jpeg and return path
def render_current_frame_ai(self):
import tempfile, random
from arnold import *
d = tempfile.gettempdir()
fi = join(d,'preview_image_%s' % random.randrange(10000, 99999))
fa = join(d,'preview_image_%s' % random.randrange(10000, 99999)) + '.ass'
rg = PyNode('defaultRenderGlobals')
dr = PyNode('defaultResolution')
ar = PyNode('defaultArnoldDriver')
# backup
old_format = ar.aiTranslator.get()
oldW, oldH =dr.width.get(), dr.height.get()
old_path = rg.imageFilePrefix.get()
res = self.persp_res_cbb.currentIndex()
dr.width.set(v.res_repsp[res][0])
dr.height.set(v.res_repsp[res][1])
# set values
ar.aiTranslator.set('jpeg')
rg.imageFilePrefix.set(fi)
# render ass
cam = ui.PyUI(playblast(activeEditor=True)).getCamera()
file = cmds.arnoldExportAss(f=fa, startFrame=currentTime(), endFrame=currentTime(),
mask=255, lightLinks=1, frameStep=1.0, shadowLinks=1,
cam=cam)
# restore
ar.aiTranslator.set(old_format)
rg.imageFilePrefix.set(old_path)
dr.width.set(oldW)
dr.height.set(oldH)
# render jpg
AiBegin()
AiLoadPlugins(os.environ['ARNOLD_PLUGIN_PATH'])
AiASSLoad (file[0], AI_NODE_ALL)
AiRender()
AiEnd()
os.remove(file[0])
# os.startfile(fi+'.jpeg')
return fi+'.jpeg'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment