def addProfileOutput(filename): print "TIMING ENABLED: profile will be saved to " + filename import nukescripts nukeProfiler = nukescripts.NukeProfiler() nukeProfiler.setPathToFile(filename) nuke.addBeforeRender(nukeProfiler.resetTimersAndStartProfile) nuke.addAfterFrameRender(nukeProfiler.addFrameProfileAndResetTimers) nuke.addOnScriptClose(nukeProfiler.endProfile)
def register_callbacks(): # nuke.addOnCreate(crop_overscan.cropOverscan, nodeClass='Crop') nuke.addOnCreate(CamProjTab.CamProjTab01, nodeClass='Camera') nuke.addOnCreate(CamProjTab.CamProjTab01, nodeClass='Camera2') nuke.addOnCreate(DIWrite.CreateWriteTab, nodeClass='Write') nuke.addBeforeRender(writeMeta.writeMeta) nuke.addAfterRender(writeMeta.delMetaNode)
def setup(): nuke.addBeforeRender(CALLBACKS_BEFORE_RENDER.execute) nuke.addOnScriptLoad(CALLBACKS_ON_SCRIPT_LOAD.execute) nuke.addOnScriptSave(CALLBACKS_ON_SCRIPT_SAVE.execute) nuke.addOnScriptClose(CALLBACKS_ON_SCRIPT_CLOSE.execute) nuke.addOnCreate(CALLBACKS_ON_CREATE.execute) nuke.addUpdateUI(CALLBACKS_UPDATE_UI.execute) if nuke.GUI: import nukescripts nukescripts.addDropDataCallback(CALLBACKS_ON_DROP_DATA.execute)
import nuke import fxpipe import fxpipenukescripts import filenameFilters import os ''' The template for the nuke setup Make sure to configure this file so that you get the show specific things loaded in ''' ### CUSTOMIZE HERE nuke.pluginAddPath(os.path.join(fxpipe.jobPath, fxpipe.job, fxpipe.jobPathNuke)) ### END CUSTOMIZE ### NO Fiddling past here generally nuke.pluginAddPath('./gizmos') ### Add general formats here nuke.load('formats.py') ### Make sure we create write directories automatically nuke.addBeforeRender(fxpipenukescripts.createWriteDir)
# CREATE PANEL p = assetManager.NkPanel( nkScripts ) # ADJUST SIZE p.setMinimumSize( 200, 200 ) # IF PANEL WAS CONFIRMED AND A NUKE SCRIPT WAS SELECTED, OPEN IT if p.showModalDialog(): if p.selectedScript: nuke.scriptOpen( p.selectedScript ) # ADD CALLBACKS nuke.addOnScriptSave( assetManager.checkScriptName ) nuke.addOnUserCreate( nkPanelHelper, nodeClass='Root') nuke.addOnUserCreate( assetManager.createVersionKnobs, nodeClass='Read' ) nuke.addKnobChanged( assetManager.updateVersionKnob, nodeClass='Read' ) nuke.addBeforeRender( assetManager.createOutDirs, nodeClass='Write' ) nuke.knobDefault( 'Write.beforeRender', 'assetManager.createOutDirs()') ### END ASSET MANAGEMENT SETUP ### ### BEGIN RENDER SETUP ### m = menubar.addMenu("Render") m.addCommand("Create Paths", "createPaths()") #m.addCommand("Fix Paths", "fixPath.fixPath()") ## Uncomment this if RUSH is used #m.addCommand("Send2Rush", "s2r.Nuke2Rush()") ### END RUSH SETUP ### ### BEGIN GIZMO SETUP ###
metadataNode.setName(__modifyMetadataName) metadataNode.setXYpos(xposWriteNode, yposWriteNode - 40) for name, value in values.iteritems(): metadataNode.knob('metadata').fromScript('{' + "set {name}".format(name=name) + " \"{}\"".format(value[0].replace('"', '\\"')) + '}') connectedNode = writeNode.input(0) metadataNode.setInput(0, connectedNode) writeNode.setInput(0, metadataNode) def hasMetadata(writeNode): """ Check if the metadata exist in the write node. :parm writeNode: The curernt write node :type writeNode: nuke.Node :return foundMetadata: A flag that return if it found the metadata or not :rtype: boolean """ foundMetadata = False for metadataKey in writeNode.metadata().keys(): if fnmatch(metadataKey, __metadataConvention): foundMetadata = True return foundMetadata # registering callbacks nuke.addBeforeRender(beforeRender, nodeClass='Write') nuke.addAfterRender(afterRender, nodeClass='Write')
#coding=utf-8 import nuke # import renderFinished import beforerender nuke.addBeforeRender(beforerender.mkds) # nuke.addAfterRender(renderFinished.notify_user)
nuke.thisKnob().name()) nuke.addOnUserCreate(_cb, ("onUserCreate")) nuke.addOnCreate(_cb, ("onCreate")) nuke.addOnScriptLoad(_cb, ("onScriptLoad")) nuke.addOnScriptSave(_cb, ("onScriptSave")) nuke.addOnScriptClose(_cb, ("onScriptClose")) nuke.addOnDestroy(_cb, ("onDestroy")) nuke.addKnobChanged(_cbk, ("knobChanged")) nuke.addUpdateUI(_cb, ("updateUI")) nuke.addAutolabel(_cb, ("autolabel")) nuke.addBeforeRender(_cb, ("beforeRender")) nuke.addBeforeFrameRender(_cb, ("beforeFrameRender")) nuke.addAfterFrameRender(_cb, ("afterFrameRender")) nuke.addAfterRender(_cb, ("afterRender")) nuke.addFilenameFilter(lambda s: nuke.tprint("filenameFilter('" + s + "')"))
shot_folder + custom_folder + version + "/" + show_filename + scene_filename + shot_filename + custom_filename + version + number + "." + extension) node['proxy'].setValue(path + show_folder + scene_folder + shot_folder + custom_folder + version + "/" + show_filename + scene_filename + shot_filename + custom_filename + version + "_proxy" + number + "." + extension) if extension == "sgi": node['datatype'].setValue("16 Bit") except: print("No AutoFillWrites found.") def createOutputDir(): file = nuke.filename(nuke.thisNode()) dir = os.path.dirname(file) osdir = nuke.callbacks.filenameFilter(dir) if not os.path.isdir(osdir): os.makedirs(osdir) # register functions nuke.addOnScriptSave(updateAutoFillWrite) nuke.addUpdateUI(updateAutoFillWrite, nodeClass='Write') nuke.addBeforeRender(createOutputDir)
def Set_project(): if os.path.exists( os.path.join(os.path.expanduser("~"), ".nuke", "Set_project.ini")): pass else: f = ConfigParser.ConfigParser() f.add_section("Set_project") f.set("Set_project", "width", "1920") f.set("Set_project", "height", "1080") f.set("Set_project", "pixel aspect", "1") f.set("Set_project", "fps", "24") f.set("Set_project", "Write channels", "rgb") f.set("Set_project", "Write node codec", "ap4h") f.set("Set_project", "Write mov write time code", "False") f.set("Set_project", "Viewer full_frame_processing", "False") f.set("Set_project", "Read raw data", "False") f.set("Set_project", "Write raw data", "False") f.set("Set_project", "Retime automatically output to the project start frame", "False") f.set("Set_project", "Rendering automatically create a rendering path", "False") f.write( open( os.path.join(os.path.expanduser("~"), ".nuke", "Set_project.ini"), "w")) f = ConfigParser.ConfigParser() f.read(os.path.join(os.path.expanduser("~"), ".nuke", "Set_project.ini")) size = [ f.get("Set_project", "width"), f.get("Set_project", "height"), "0", "0", f.get("Set_project", "width"), f.get("Set_project", "height"), f.get("Set_project", "pixel aspect"), f.get("Set_project", "width") + "*" + f.get("Set_project", "height") ] nuke.knobDefault("Root.format", " ".join(size)) nuke.knobDefault("Root.fps", f.get("Set_project", "fps")) nuke.knobDefault("Write.channels", f.get("Set_project", "Write channels")) nuke.knobDefault("Write.mov.meta_codec", f.get("Set_project", "Write node codec")) nuke.knobDefault("Write.mov.mov64_write_timecode", f.get("Set_project", "Write mov write time code")) nuke.knobDefault("Viewer.full_frame_processing", f.get("Set_project", "Viewer full_frame_processing")) nuke.knobDefault("Read.raw", f.get("Set_project", "Read raw data")) nuke.knobDefault("Write.raw", f.get("Set_project", "Write raw data")) nuke.knobDefault( "Write.raw", f.get("Set_project", "Retime automatically output to the project start frame")) if panduan( f.get("Set_project", "Retime automatically output to the project start frame")): nuke.addOnUserCreate(auto_retime) if panduan( f.get("Set_project", "Rendering automatically create a rendering path")): nuke.addBeforeRender(chuangjian) menubar = nuke.menu("Nuke") m = menubar.addMenu("Set the project default") m.addCommand("Set the project default", Set_project_ui)
for each in glob('%s/*' % os.path.dirname(__file__)): if os.path.isdir(each): nuke.pluginAddPath(each) def createWriteDir(): import nuke, os, errno file = nuke.filename(nuke.thisNode()) dir = os.path.dirname( file ) osdir = nuke.callbacks.filenameFilter( dir ) # cope with the directory existing already by ignoring that exception try: os.makedirs( osdir ) except OSError, e: if e.errno != errno.EEXIST: raise nuke.addBeforeRender(createWriteDir) def sam_publish(): import IECore import Gaffer import PySide import os, pipe os.environ['PIPE_PUBLISH_FILTER'] = 'render/nuke' appLoader = IECore.ClassLoader.defaultLoader( "GAFFER_APP_PATHS" ) appLoader.classNames() app=appLoader.load( 'opa' )() app.parameters()['arguments'] = IECore.StringVectorData(['-Asset.type','render/nuke','1','IECORE_ASSET_OP_PATHS'])
def start(): nuke.addBeforeRender(create_write_dir)
# -*- coding:utf-8 -*- __date__ = '2017/5/18 15:14' __author__ = 'liaokong' import nuke from CreateNoExistentFolder import CreateNoExistentFolder nuke.addBeforeRender(CreateNoExistentFolder)
# nuke.load("formats.tcl") # attempt to populate environment variables if nuke.env['gui']: init_shot_env() nuke.addOnScriptLoad(init_shot_env) else: try: tmp = os.environ['TANK_CONTEXT'] print "INFO: Nuke launched from Shotgun." nuke.addOnScriptLoad(init_shot_env) except KeyError: pass # print the environment to STDOUT # print "DEBUG: Inside init.py, printing current environment." # for env_key in sorted(os.environ.keys()): # print "%s : %s"%(env_key, os.environ[env_key]) # add support for RV if nuke.env['gui']: import rvflipbook if nuke.NUKE_VERSION_MAJOR > 8: nuke.knobDefault("Read.mov.mov64_decode_video_levels", "Video Range") # add callback to auto-create directory path for write nodes nuke.addBeforeRender(make_dir_path, nodeClass='Write') # nuke.addAfterFrameRender(print_render_frame, nodeClass = 'Write')
nuke.pluginAddPath(facility_plugins) print("Loading nodes from " + facility_plugins) # Load show-specific init.py/menu.py try: show_path = os.environ['SHOW_PATH'] show_path = os.path.join(show_path, 'pipeline', 'nuke') if os.path.isdir(show_path): print("Loading custom configs from " + show_path.replace('\\', '/')) nuke.pluginAddPath(show_path) except: print("Could not load a show-based plugin repository.") print(sep) # Implement callbacks def writeNodeDirs(): import os, nuke file = nuke.filename(nuke.thisNode()) dir = os.path.dirname(file) # osdir = nuke.callbacks.filenameFilter(dir) try: # os.makedirs(osdir) os.makedirs(dir) except OSError: pass nuke.addBeforeRender(writeNodeDirs)
def createArtifact(): nuke.scriptSave() script = nuke.value("root.name") filename, file_extension = os.path.splitext(script) artef = '{}_artifact.{}'.format(filename, file_extension) shutil.copyfile(script, artef) def beforeWrite_cb(): if script_has_version(): createArtifact() def afterWrite_cb(): if script_has_version() and nuke.ask( 'Do you want to version up your script?'): incrementalSave() # for some off reason these callbacks are added tiwce nuke.addBeforeRender(beforeWrite_cb) nuke.addAfterRender(afterWrite_cb) # setting callback to remove the second one on script load - odd stuff nuke.addOnScriptLoad(lambda: nuke.removeAfterRender(afterWrite_cb)) ####################################
# major events of a script's lifecycle, namely when scripts # are loaded, saved and rendered # -------------------------------------------------------- import nuke import os def createWriteDirs(): """ Automatically create directories in Write path if path doesn't exists. """ f = nuke.filename(nuke.thisNode()) dirr = os.path.dirname(f) if not os.path.exists(dirr): osdir = nuke.callbacks.filenameFilter(dirr) os.makedirs(osdir) nuke.addBeforeRender(createWriteDirs) def writeNoOverwrite(): """ Automatically create directories in Write path if path doesn't exists. """ if nuke.thisNode()['no_overwrite'].value(): file_to_be_rendered = nuke.filename(nuke.thisNode(), nuke.REPLACE) if os.path.exists(file_to_be_rendered): msg = "File already exists: %s" % file_to_be_rendered try: raise RuntimeError(msg) except RuntimeError as e: print e nuke.addBeforeFrameRender(writeNoOverwrite) def writeNoOverwriteKnob(): n = nuke.thisNode() if 'no_overwrite' not in n.knobs().keys():
import nuke import fxpipe import fxpipenukescripts import os ''' The template for the nuke setup Make sure to configure this file so that you get the show specific things loaded in ''' ### CUSTOMIZE HERE nuke.pluginAddPath(os.path.join(fxpipe.jobPath, fxpipe.job, fxpipe.jobPathNuke)) ### END CUSTOMIZE ### NO Fiddling past here generally nuke.pluginAddPath('./gizmos') ### Add general formats here nuke.load('formats.py') ### Make sure we create write directories automatically nuke.addBeforeRender(fxpipenukescripts.createWriteDir)
# TRIinit nuke script v1.1 # -*- coding: utf-8 -*- # import os import nuke import re import getpass from datetime import datetime def _check_framerange(): if int(nuke.numvalue("root.first_frame")) < 1: raise ValueError("Start frame number can not be less than 1") return nuke.addBeforeRender(_check_framerange) def fr2tc(f, fps): """ Convert frame nuber to timecode string """ fr = f % fps f = int(f / fps) s = f % 60 f = int(f / 60) m = f % 60 h = int(f / 60) return '%02d:%02d:%02d:%02d' % (h, m, s, fr) def sceneName(): """
sys.path.append('/Volumes/resources/vfx/pipeline/jeeves') ############################################################################################################ # Set the plugin paths and sys paths and callbacks ############################################################################################################ #Get all folders in NUKE_PATH and add them to sys and plugin path import core import jnuke import jnuke.pipeline for root, dirs, files in os.walk(os.path.join(core.jeevesRoot, 'jnuke')): for folder in dirs: gizmodir = os.path.join(root, folder).replace('\\', '/') sys.path.append(gizmodir) nuke.pluginAddPath(gizmodir) nuke.addBeforeRender(jnuke.pipeline.callbacks.createWriteDir) ############################################################################################################ # Project defaults ############################################################################################################ s = nuke.root() name = s.name() nuke.knobDefault('Root.fps', '25') nuke.knobDefault('Root.format', 'HD_1080') nuke.knobDefault('Viewer.viewerProcess', 'sRGB') nuke.knobDefault('Root.name', name)
nuke.pluginAddPath(os.path.join(fullpath, subdir)) # Callbacks #--------------------------------------------------------------------------------------------- # If a write directory does not exist, create it automatically. def create_write_directory(): directory = nuke.callbacks.filenameFilter( os.path.dirname(nuke.filename(nuke.thisNode()))) if directory and not os.path.isdir(directory): try: os.makedirs(directory) except (OSError, e): if e.errno == 17: pass nuke.addBeforeRender(create_write_directory) # Works around bug in node.dependent calls which sometimes return an empty list in error # Only add callback if not in commandline render mode def eval_deps(): nodes = nuke.allNodes() if nodes: _ = nodes[-1].dependent() if '-X' not in nuke.rawArgs: nuke.addOnScriptLoad(eval_deps)
print('SETTINGS') # FPS *********************************** try: nuke.knobDefault("nuke.Root()['fps'].setValue({})".format( project_data['fps'])) print(' {} ON - FPS: {}'.format(chr(254), project_data['fps'])) except: pass LOG.debug(' OFF - FPS: {}'.format(project_data['fps'])) print(' {} OFF - FPS: {}'.format(chr(254), project_data['fps'])) # RESOLUTION **************************** try: nuke.addFormat(RESOLUTION) nuke.knobDefault('Root.format', project_data['name'].replace(' ', '')) print(' {} ON - RES: {}'.format(chr(254), RESOLUTION)) except: LOG.debug(' OFF - RES: {}'.format(RESOLUTION)) print(' {} OFF - RES: {}'.format(chr(254), RESOLUTION)) # createFolder **************************** try: nuke.addBeforeRender(createWriteDir) print(' {} ON - BeR: createWriteDir'.format(chr(254))) except: LOG.error(' OFF - BeR: createWriteDir'.format(chr(254)), exc_info=True) print(' {} OFF - BeR: createWriteDir'.format(chr(254))) print('') # ********************
Output Path: [value file] Project Root: [value proj_root] Sequence: [value seq] Episode Name: [value episode] Shot Name: [value shot] Script Name: [value script] Stripe Name: [value stripe] userName Name: [value user] """ w.knob('label').setValue(feedback) # Re-assemble the path fragments into a proper output path output_path = "[value proj_root]/[value seq]/[value episode]/[value shot]/nuke/[value user]/render/[value stripe]/[value stripe].%04d.jpeg" w.knob('file').fromScript(output_path) #w['beforeRender'].setValue('''if not os.path.isdir(os.path.dirname(nuke.thisNode().knob("file").value())): os.makedirs(os.path.dirname(nuke.thisNode().knob("file").value()))''') def createOutDirs(): trgDir = os.path.dirname( nuke.filename( nuke.thisNode() ) ) if not os.path.isdir( trgDir ): os.makedirs( trgDir ) nuke.addBeforeRender( createOutDirs, nodeClass='AutoWrite' ) # Add an AutoWrite option to the Image menu nuke.tprint('Adding AutoWrite to Image menu.') menubar=nuke.menu('Nodes') m = menubar.findItem('Image') m.addSeparator() m.addCommand('AutoWrite', 'autowrite.dropAutoWrite()')