def plugin_startup(): """ Initializes the Toolkit plugin for Nuke. """ # construct the path to the plugin root's folder. # plugins/basic/menu.py # -------------| # this part ^ plugin_root_path = os.path.dirname(__file__) # the plugin python path will be just below the root level. add it to # sys.path plugin_python_path = os.path.join(plugin_root_path, "Python") sys.path.insert(0, plugin_python_path) # now that the path is there, we can import the plugin bootstrap logic try: from tk_nuke_basic import plugin_bootstrap plugin_bootstrap.bootstrap(plugin_root_path) except Exception, e: import traceback stack_trace = traceback.format_exc() message = "Shotgun Toolkit Error: %s" % (e,) details = "Error stack trace:\n\n%s" % (stack_trace) import nuke nuke.error(message) nuke.error(details)
def plugin_startup(): """ Initializes the Toolkit plugin for Nuke. """ # construct the path to the plugin root's folder. # plugins/basic/menu.py # -------------| # this part ^ plugin_root_path = os.path.dirname(__file__) # the plugin python path will be just below the root level. add it to # sys.path plugin_python_path = os.path.join(plugin_root_path, "Python") sys.path.insert(0, plugin_python_path) # now that the path is there, we can import the plugin bootstrap logic try: from tk_nuke_basic import plugin_bootstrap plugin_bootstrap.bootstrap(plugin_root_path) except Exception as e: import traceback stack_trace = traceback.format_exc() message = "Shotgun Toolkit Error: %s" % (e,) details = "Error stack trace:\n\n%s" % (stack_trace) import nuke nuke.error(message) nuke.error(details)
def _emit_log_message(self, handler, record): """ Emits a log to Nuke's Script Editor and Error Console. :param handler: Log handler that this message was dispatched from :type handler: :class:`~python.logging.LogHandler` :param record: Std python logging record :type record: :class:`~python.logging.LogRecord` """ msg = handler.format(record) # Sends the message to error console of the DCC if self.hiero_enabled: import hiero if record.levelno >= logging.ERROR: hiero.core.log.error(msg) elif record.levelno >= logging.WARNING: hiero.core.log.info(msg) elif record.levelno >= logging.INFO: hiero.core.log.info(msg) else: hiero.core.log.setLogLevel(hiero.core.log.kDebug) hiero.core.log.debug(msg) else: if record.levelno >= logging.CRITICAL: nuke.critical("Shotgun Critical: %s" % msg) elif record.levelno >= logging.ERROR: nuke.error("Shotgun Error: %s" % msg) elif record.levelno >= logging.WARNING: nuke.warning("Shotgun Warning: %s" % msg) # Sends the message to the script editor. print msg
def __create_tank_error_menu(): """ Creates a std "error" tank menu and grabs the current context. Make sure that this is called from inside an except clause. """ (exc_type, exc_value, exc_traceback) = sys.exc_info() message = "" message += "SG encountered a problem starting the Engine. " message += "Please contact us via %s\n\n" % sgtk.support_url message += "Exception: %s - %s\n" % (exc_type, exc_value) message += "Traceback (most recent call last):\n" message += "\n".join(traceback.format_tb(exc_traceback)) if nuke.env.get("gui"): nuke_menu = nuke.menu("Nuke") sg_menu = nuke_menu.addMenu("Shotgun") sg_menu.clearMenu() def cmd(m=message): nuke.message(m) sg_menu.addCommand("[SG Error - Click for details]", cmd) else: msg = "The SG Pipeline Toolkit caught an error: %s" % message logger.error(msg) nuke.error(msg)
def log_error(self, msg): msg = "Shotgun Error: %s" % msg # We will log it via the API, as well as print normally, # which should make its way to the scripting console. if self.hiero_enabled: import hiero hiero.core.log.error(msg) else: nuke.error(msg) print msg
def log_error(self, msg): msg = "Shotgun Error: %s" % msg # print it in the nuke error console nuke.error(msg) # also print it in the nuke script console print msg # and pop up UI nuke.message(msg)
def _on_failure(self, phase, exception): """ Called when something went wrong during bootstrap. :param phase: Phase which went wrong. :param exception: Exception that was raised. """ try: nuke.error("Initialization failed: %s" % str(exception)) finally: self._on_finish(failed=True)
def __create_tank_disabled_menu(details): """ Creates a std "disabled" shotgun menu """ if nuke.env.get("gui"): nuke_menu = nuke.menu("Nuke") sg_menu = nuke_menu.addMenu("Shotgun") sg_menu.clearMenu() cmd = lambda d=details: __show_tank_disabled_message(d) sg_menu.addCommand("Toolkit is disabled.", cmd) else: nuke.error("The Shotgun Pipeline Toolkit is disabled: %s" % details)
def emit(self, record): # Formated message: msg = self.format(record) if record.funcName == "warning": nuke.warning(msg) elif record.funcName in ["critical", "fatal"]: nuke.error(msg) nuke.message(record.message) else: sys.stdout.write(msg)
def checkFile4ef( nknd ): # add 4 effect stuffs====================add by zhangben============== # rdnd = nuke.selectedNodes("Read") stuffPath = nknd.knob('file').getValue() pthspl = os.path.split(stuffPath) stuff_name = os.path.splitext(os.path.splitext( pthspl[1])[0])[0].split('_') cam_info = re.search("[ABC]", stuff_name[-1]) if cam_info: cam_info = cam_info.group() else: nuke.error("Cant find Camera information") layerInfo = '' try: layerInfo = "_".join(stuff_name[4:-2]) except: layerInfo = "_".join(stuff_name[:-2]) return [cam_info, layerInfo]
def __create_tank_error_menu(): """ Creates a std "error" tank menu and grabs the current context. Make sure that this is called from inside an except clause. """ (exc_type, exc_value, exc_traceback) = sys.exc_info() message = "" message += "Message: Shotgun encountered a problem starting the Engine.\n" message += "Please contact [email protected]\n\n" message += "Exception: %s - %s\n" % (exc_type, exc_value) message += "Traceback (most recent call last):\n" message += "\n".join( traceback.format_tb(exc_traceback)) if nuke.env.get("gui"): nuke_menu = nuke.menu("Nuke") sg_menu = nuke_menu.addMenu("Shotgun") sg_menu.clearMenu() cmd = lambda m=message: nuke.message(m) sg_menu.addCommand("[Shotgun Error - Click for details]", cmd) else: nuke.error("The Shotgun Pipeline Toolkit caught an error: %s" % message)
def __create_tank_error_menu(): """ Creates a std "error" tank menu and grabs the current context. Make sure that this is called from inside an except clause. """ (exc_type, exc_value, exc_traceback) = sys.exc_info() message = "" message += "Message: Shotgun encountered a problem starting the Engine.\n" message += "Please contact [email protected]\n\n" message += "Exception: %s - %s\n" % (exc_type, exc_value) message += "Traceback (most recent call last):\n" message += "\n".join(traceback.format_tb(exc_traceback)) if nuke.env.get("gui"): nuke_menu = nuke.menu("Nuke") sg_menu = nuke_menu.addMenu("Shotgun") sg_menu.clearMenu() cmd = lambda m=message: nuke.message(m) sg_menu.addCommand("[Shotgun Error - Click for details]", cmd) else: nuke.error("The Shotgun Pipeline Toolkit caught an error: %s" % message)
def log_error(self, msg): msg = "Shotgun Error: %s" % msg # print it in the nuke error console nuke.error(msg) # also print it in the nuke script console print msg
def mergeCams_dntg(self, sourceSels, flag, FileName): if sourceSels == None: sourceSels = nuke.selectedNodes('Read') numSelect = len(sourceSels) _dot = nuke.nodes.Dot() sourceSels = sorted(sourceSels, key=lambda eaNd: self.checkFile(eaNd, FileName)[0]) if not self.checkFile(sourceSels[0], FileName)[0]: sourceSels = sorted( sourceSels, key=lambda eaNd: self.__class__.checkFile4ef(eaNd)[0]) _dot.setXYpos(sourceSels[0].xpos(), sourceSels[0].ypos()) left_edge = _dot.xpos() # min(eand.xpos() for eand in sourceSels) top_edge = _dot.ypos() # min(eand.ypos() for eand in sourceSels) _sortedCam = {} # cleare select for i in sourceSels: i['selected'].setValue(False) transData = self.calculate_data(sourceSels) centerData = [1143, 4343.5] merge_inputPlugs = {0: 1, 1: 3, 2: 4} x_pos_v = left_edge transLst = [] rndlyer = [] rndCam = [] totalwidth = 0 for each in sourceSels: # each['selected'].setValue(True) camStr = self.checkFile(each, FileName) if camStr[0] == None: camStr = self.__class__.checkFile4ef(each) rndlyer.append( self.__class__.stuff_info(each, True)["rndLayer"]) rndCam.append(self.__class__.stuff_info(each, True)["rndCam"]) else: rndlyer.append(self.__class__.stuff_info(each)["rndLayer"]) rndCam.append(self.__class__.stuff_info(each)["rndCam"]) if not camStr: nuke.error("sutff name promeblem") each.setXYpos(x_pos_v, top_edge) ea_w = each.screenWidth() ea_h = each.screenHeight() ea_left = each.xpos() ea_top = each.ypos() ea_bottom = ea_top - ea_h totalwidth += ea_w trnsnd = nuke.nodes.Transform() trnsnd['translate'].setValue( [transData[camStr[0]][0], transData[camStr[0]][1]]) trnsnd['center'].setValue([centerData[0], centerData[1]]) trnsnd.setXYpos(ea_left, ea_bottom + 180) trnsnd.setInput(0, each) transLst.append(trnsnd) x_pos_v += (ea_w + 33) MergeNode = nuke.nodes.Merge2() MergeNode.setXYpos(transLst[1].xpos(), transLst[1].ypos() + 80) for n in range(len(transLst)): MergeNode.setInput(merge_inputPlugs[n], transLst[n]) _setFormat = [ eafmt for eafmt in nuke.formats() if eafmt.width() == transData['Cons'][0] ] if not len(_setFormat): dntgfmt = "{:d} {:d} DNTGEF MergCams".format( transData['Cons'][0], transData['Cons'][1]) addfmg = nuke.addFormat(dntgfmt) _constant = nuke.nodes.Constant(format=addfmg.name()) else: _constant = nuke.nodes.Constant(format=_setFormat[0].name()) _constant.setXYpos((MergeNode.xpos() + 160), MergeNode.ypos() - 50) _constant.knob("channels").setValue("rgb") MergeNode.setInput(0, _constant) rndlyer = [ rndlyer[n] for n in range(len(rndlyer)) if rndlyer[n] not in rndlyer[:n] ] if len(rndlyer) != 1: self.__class__.warn_box( "Please selecte the stuffs those in the same render layer") rndCam = [ rndCam[n] for n in range(len(rndCam)) if rndCam[n] not in rndCam[:n] ] if len(rndlyer) != 1: self.__class__.warn_box( "Please selecte the stuffs those in the same side camera") bdrp = nuke.nodes.BackdropNode( xpos=(_dot.xpos() - 15), bdwidth=totalwidth + 160, ypos=(_dot.ypos() - 75), bdheight=(MergeNode.ypos() - top_edge) + 130, tile_color=int((random.random() * (16 - 10))) + 10, note_font_size=45) camsDict = {'l': 'left', 'r': 'right', 'L': 'Left', 'R': 'Right'} cam_nm = re.search('[lr]', rndCam[0], re.I).group() drpName = "camera {} {}".format(camsDict[cam_nm], rndlyer[0]) bdrp.setName(drpName) drp_lab = "{} : {}".format(camsDict[cam_nm], rndlyer[0]) bdrp.knob("label").setValue(drp_lab) nuke.delete(_dot) nknd = each
def mergeCams_dntg(self, sourceSels, flag, FileName): _dot = nuke.nodes.Dot() sourceSels = sorted(sourceSels, key=lambda eaNd: self.checkFile(eaNd, FileName)[0]) left_edge = min(eand.xpos() for eand in sourceSels) right_edge = max(eand.xpos() for eand in sourceSels) top_edge = min(eand.ypos() for eand in sourceSels) bottom_edge = max(eand.ypos() for eand in sourceSels) _sortedCam = {} # cleare select for i in sourceSels: i['selected'].setValue(False) transData = { "A": { "translate": [0, 0] }, "B": { "translate": [2286, 1028.5] }, "C": { "translate": [4572, 0] } } centerData = [1143, 4343.5] merge_inputPlugs = {0: 1, 1: 3, 2: 4} x_pos_v = left_edge transLst = [] for each in sourceSels: # each['selected'].setValue(True) camStr = self.checkFile(each, FileName) if not camStr: nuke.error("sutff name promeblem") _bkdrpStr = "cam{}".format(camStr[0]) each.setXYpos(x_pos_v, top_edge) ea_w = each.screenWidth() ea_h = each.screenHeight() ea_left = each.xpos() ea_right = ea_left + ea_w ea_top = each.ypos() ea_bottom = ea_top - ea_h # each.setSelected(1) bdrp = nuke.nodes.BackdropNode(xpos=ea_left - 15, bdwidth=ea_w + 30, ypos=ea_top - 35, bdheight=ea_h + 70, tile_color=int((random.random() * (16 - 10))) + 10, note_font_size=42) bdrp.setName(camStr[0]) bdrp.knob("label").setValue(_bkdrpStr) trnsnd = nuke.nodes.Transform() trnsnd['translate'].setValue([ transData[camStr[0]].values()[0][0], transData[camStr[0]].values()[0][1] ]) trnsnd['center'].setValue([centerData[0], centerData[1]]) trnsnd.setXYpos(ea_left, ea_bottom + 250) trnsnd.setInput(0, each) transLst.append(trnsnd) each.setYpos(each.ypos() + 30) x_pos_v += (ea_w + 33) MergeNode = nuke.nodes.Merge2() MergeNode.setXYpos(transLst[1].xpos(), transLst[1].ypos() + 80) for n in range(len(transLst)): MergeNode.setInput(merge_inputPlugs[n], transLst[n]) _setFormat = [ eafmt for eafmt in nuke.formats() if eafmt.width() == 6858 ] _constant = nuke.nodes.Constant(format=_setFormat[0].name()) _constant.setXYpos((MergeNode.xpos() + 200), MergeNode.ypos() - 50) _constant.knob("channels").setValue("rgb") MergeNode.setInput(0, _constant)
def copyToProjector(node=None, frame=None, gui=nuke.GUI): if not node: node = nuke.thisNode() if not frame: frame = nuke.root()['frame'].value() if node.Class() not in ['StereoCam', 'StereoCam2', 'Camera', 'Camera2']: m = 'this node is not a supported camera type, unable to convert to projector' if gui: nuke.message(m) nuke.error(m) return saved_frame = nuke.root()['frame'].value() nuke.root()['frame'].setValue(frame) # Turn off all selected nodes, otherwise they mess up the node paste: for n in nuke.selectedNodes(): n.knob('selected').setValue(False) # Now select this node then copy and paste it: node['selected'].setValue(True) nukescripts.node_copypaste() proj = nuke.selectedNode() # Name/label new node: new_name = 'projector_cam' if node.knob('shot') is not None: if node['shot'].getText() != '': new_name += '_%s_' % proj['shot'].getText().replace('.', '_') new_name += 'fr%d_' % nuke.frame() # De-duplicate the new name: counter = 1 while 1: new_name2 = new_name + '%d' % counter if nuke.toNode(new_name2) is None: new_name = new_name2 break counter += 1 proj['name'].setValue(new_name) l = proj['label'].getText() if l != '' and not l.endswith('\\n'): l += '\\n' l += 'frame %d' % nuke.frame() proj['label'].setValue(l) # Offset its position in the DAG: xpos = node['xpos'].value() proj['xpos'].setValue(xpos + 100) ypos = node['ypos'].value() proj['ypos'].setValue(ypos + 100) # Unsplit all knobs (remove views): vs = nuke.views() if len(vs) > 1: for name, knob in proj.knobs().items(): if issubclass(knob.__class__, nuke.Array_Knob): #print 'knob %s: unsplitting view %s' % (knob.name(), vs[1]) knob.unsplitView(view=vs[1]) # Clear animations from all knobs: for name, knob in proj.knobs().items(): if knob.isAnimated(): knob.clearAnimated() # Disable updating: if proj.knob('read_from_file') is not None: proj['read_from_file'].setValue(False) nuke.root()['frame'].setValue(saved_frame)
Note however that this does not automatically run *the first* time nuke starts up, despite being an auto-start script. This is to overcome the fact that file->new in nuke typically results in a completely new process being launched. """ import nuke import os import sys def handle_new_tank_session(): import tk_nuke tk_nuke.tank_ensure_callbacks_registered() tk_nuke.tank_startup_node_callback() if not nuke.env.get("hiero"): # now we need to add our callback module to the pythonpath manually. # note! __file__ does not work for this file, so the engine passes # down the engine's python folder location to us via an env var. path = os.environ.get("TANK_NUKE_ENGINE_MOD_PATH") if path: sys.path.append(path) handle_new_tank_session() else: nuke.error( "Shotgun could not find the environment variable TANK_NUKE_ENGINE_MOD_PATH!" )
Note however that this does not automatically run *the first* time nuke starts up, despite being an auto-start script. This is to overcome the fact that file->new in nuke typically results in a completely new process being launched. """ import nuke import os import sys def handle_new_tank_session(): import tk_nuke tk_nuke.tank_ensure_callbacks_registered() if not nuke.env.get("hiero"): # now we need to add our callback module to the pythonpath manually. # note! __file__ does not work for this file, so the engine passes # down the engine's python folder location to us via an env var. path = os.environ.get("TANK_NUKE_ENGINE_MOD_PATH") if path: sys.path.append(path) handle_new_tank_session() else: nuke.error("Shotgun could not find the environment variable TANK_NUKE_ENGINE_MOD_PATH!")