From 01f23cc62310301031db53282d0c870b63000b44 Mon Sep 17 00:00:00 2001 From: Joseph Yu Date: Wed, 11 Aug 2021 12:41:41 +0100 Subject: [PATCH] Progress and better error message per SG node From v1.4.2+wwfx.1.3.0 --- python/tk_nuke_writenode/handler.py | 196 ++++++++++++++++------------ 1 file changed, 116 insertions(+), 80 deletions(-) diff --git a/python/tk_nuke_writenode/handler.py b/python/tk_nuke_writenode/handler.py index 1d1f21c..31e2b7d 100644 --- a/python/tk_nuke_writenode/handler.py +++ b/python/tk_nuke_writenode/handler.py @@ -407,102 +407,138 @@ def convert_sg_to_nuke_write_nodes(self): # get write nodes: sg_write_nodes = self.get_nodes() - for sg_wn in sg_write_nodes: - # set as selected: - sg_wn.setSelected(True) - node_name = sg_wn.name() - node_pos = (sg_wn.xpos(), sg_wn.ypos()) - - # create new regular Write node: - new_wn = nuke.createNode("Write") - new_wn.setSelected(False) - - # copy across file & proxy knobs (if we've defined a proxy template): - new_wn["file"].setValue(sg_wn["cached_path"].evaluate()) - if sg_wn["proxy_render_template"].value(): - new_wn["proxy"].setValue(sg_wn["tk_cached_proxy_path"].evaluate()) - else: - new_wn["proxy"].setValue("") + total = float(len(sg_write_nodes)) + task = nuke.ProgressTask("SG to Write nodes") + sg_write_node = None - # make sure file_type is set properly: - int_wn = sg_wn.node(TankWriteNodeHandler.WRITE_NODE_NAME) - new_wn["file_type"].setValue(int_wn["file_type"].value()) + try: + for count, sg_write_node in enumerate(sg_write_nodes): + if task.isCancelled(): + break + name = sg_write_node.fullName() + task.setMessage(name) + task.setProgress(int(100 * (count / total))) - # copy across any knob values from the internal write node. - for knob_name, knob in int_wn.knobs().items(): - # skip knobs we don't want to copy: - if knob_name in [ - "file_type", - "file", - "proxy", - "beforeRender", - "afterRender", - "name", - "xpos", - "ypos", - ]: - continue + try: + # Hide new node properties window when converting multiple + new_wn = self._convert_sg_to_nuke_write_node(sg_write_node) + new_wn.hideControlPanel() + except Exception: + if nuke.exists(name): + sg_write_node.selectOnly() + nuke.zoomToFitSelected() + message = ( + 'Failed to convert to write node: "{0}"\n\nCheck ' + "Terminal/Error panel for technical details.\n\nIt " + "could still be selected in the node graph, if it " + "looks broken, consider deleting it.".format(name) + ) + nuke.alert(message) + nuke.error(message) + raise + finally: + del task - if knob_name in new_wn.knobs(): - try: - new_wn[knob_name].setValue(knob.value()) - except TypeError: - # ignore type errors: - pass + def _convert_sg_to_nuke_write_node(self, sg_wn): + """Convert a Shotgun Write node to Nuke Write node. - # Set the nuke write node to have create directories ticked on by default - # As toolkit hasn't created the output folder at this point. - new_wn["create_directories"].setValue(True) + :param nuke.Node sg_wn: Shotgun Write node. + :return: New, converted Nuke write node + :rtype: nuke.Node + """ + # set as selected: + sg_wn.setSelected(True) + node_name = sg_wn.name() + node_pos = (sg_wn.xpos(), sg_wn.ypos()) - # copy across select knob values from the Shotgun Write node: - for knob_name in ["tile_color", "postage_stamp", "label"]: - new_wn[knob_name].setValue(sg_wn[knob_name].value()) + # create new regular Write node: + new_wn = nuke.createNode("Write") + new_wn.setSelected(False) - # Store Toolkit specific information on write node - # so that we can reverse this process later + # copy across file & proxy knobs (if we've defined a proxy template): + new_wn["file"].setValue(sg_wn["cached_path"].evaluate()) + if sg_wn["proxy_render_template"].value(): + new_wn["proxy"].setValue(sg_wn["tk_cached_proxy_path"].evaluate()) + else: + new_wn["proxy"].setValue("") + + # make sure file_type is set properly: + int_wn = sg_wn.node(TankWriteNodeHandler.WRITE_NODE_NAME) + new_wn["file_type"].setValue(int_wn["file_type"].value()) + + # copy across any knob values from the internal write node. + for knob_name, knob in int_wn.knobs().items(): + # skip knobs we don't want to copy: + if knob_name in [ + "file_type", + "file", + "proxy", + "beforeRender", + "afterRender", + "name", + "xpos", + "ypos", + ]: + continue - # profile - knob = nuke.String_Knob("tk_profile_name") - knob.setValue(sg_wn["profile_name"].value()) - new_wn.addKnob(knob) + if knob_name in new_wn.knobs(): + try: + new_wn[knob_name].setValue(knob.value()) + except TypeError: + # ignore type errors: + pass - # output - knob = nuke.String_Knob("tk_output") - knob.setValue(sg_wn[TankWriteNodeHandler.OUTPUT_KNOB_NAME].value()) - new_wn.addKnob(knob) + # Set the nuke write node to have create directories ticked on by default + # As toolkit hasn't created the output folder at this point. + new_wn["create_directories"].setValue(True) - # use node name for output - knob = nuke.Boolean_Knob(TankWriteNodeHandler.USE_NAME_AS_OUTPUT_KNOB_NAME) - knob.setValue( - sg_wn[TankWriteNodeHandler.USE_NAME_AS_OUTPUT_KNOB_NAME].value() - ) - new_wn.addKnob(knob) + # copy across select knob values from the Shotgun Write node: + for knob_name in ["tile_color", "postage_stamp", "label"]: + new_wn[knob_name].setValue(sg_wn[knob_name].value()) - # templates - knob = nuke.String_Knob("tk_render_template") - knob.setValue(sg_wn["render_template"].value()) - new_wn.addKnob(knob) + # Store Toolkit specific information on write node + # so that we can reverse this process later - knob = nuke.String_Knob("tk_publish_template") - knob.setValue(sg_wn["publish_template"].value()) - new_wn.addKnob(knob) + # profile + knob = nuke.String_Knob("tk_profile_name") + knob.setValue(sg_wn["profile_name"].value()) + new_wn.addKnob(knob) - knob = nuke.String_Knob("tk_proxy_render_template") - knob.setValue(sg_wn["proxy_render_template"].value()) - new_wn.addKnob(knob) + # output + knob = nuke.String_Knob("tk_output") + knob.setValue(sg_wn[TankWriteNodeHandler.OUTPUT_KNOB_NAME].value()) + new_wn.addKnob(knob) - knob = nuke.String_Knob("tk_proxy_publish_template") - knob.setValue(sg_wn["proxy_publish_template"].value()) - new_wn.addKnob(knob) + # use node name for output + knob = nuke.Boolean_Knob(TankWriteNodeHandler.USE_NAME_AS_OUTPUT_KNOB_NAME) + knob.setValue(sg_wn[TankWriteNodeHandler.USE_NAME_AS_OUTPUT_KNOB_NAME].value()) + new_wn.addKnob(knob) - # delete original node: - nuke.delete(sg_wn) + # templates + knob = nuke.String_Knob("tk_render_template") + knob.setValue(sg_wn["render_template"].value()) + new_wn.addKnob(knob) - # rename new node: - new_wn.setName(node_name) - new_wn.setXpos(node_pos[0]) - new_wn.setYpos(node_pos[1]) + knob = nuke.String_Knob("tk_publish_template") + knob.setValue(sg_wn["publish_template"].value()) + new_wn.addKnob(knob) + + knob = nuke.String_Knob("tk_proxy_render_template") + knob.setValue(sg_wn["proxy_render_template"].value()) + new_wn.addKnob(knob) + + knob = nuke.String_Knob("tk_proxy_publish_template") + knob.setValue(sg_wn["proxy_publish_template"].value()) + new_wn.addKnob(knob) + + # delete original node: + nuke.delete(sg_wn) + + # rename new node: + new_wn.setName(node_name) + new_wn.setXpos(node_pos[0]) + new_wn.setYpos(node_pos[1]) def convert_nuke_to_sg_write_nodes(self): """