def reset_frame_range_handles(self): """Set frame range to current asset""" if "data" not in self._asset_entity: msg = "Asset {} don't have set any 'data'".format(self._asset) log.warning(msg) nuke.message(msg) return data = self._asset_entity["data"] missing_cols = [] check_cols = [ "fps", "frameStart", "frameEnd", "handleStart", "handleEnd" ] for col in check_cols: if col not in data: missing_cols.append(col) if len(missing_cols) > 0: missing = ", ".join(missing_cols) msg = "'{}' are not set for asset '{}'!".format( missing, self._asset) log.warning(msg) nuke.message(msg) return # get handles values handle_start = data["handleStart"] handle_end = data["handleEnd"] fps = data["fps"] frame_start = int(data["frameStart"]) - handle_start frame_end = int(data["frameEnd"]) + handle_end self._root_node["fps"].setValue(fps) self._root_node["first_frame"].setValue(frame_start) self._root_node["last_frame"].setValue(frame_end) # setting active viewers try: nuke.frame(int(data["frameStart"])) except Exception as e: log.warning("no viewer in scene: `{}`".format(e)) range = '{0}-{1}'.format(int(data["frameStart"]), int(data["frameEnd"])) for node in nuke.allNodes(filter="Viewer"): node['frame_range'].setValue(range) node['frame_range_lock'].setValue(True) node['frame_range'].setValue(range) node['frame_range_lock'].setValue(True) # adding handle_start/end to root avalon knob if not avalon.nuke.imprint(self._root_node, { "handleStart": int(handle_start), "handleEnd": int(handle_end) }): log.warning("Cannot set Avalon knob to Root node!")
def writes_version_sync(): try: rootVersion = pype.get_version_from_path(nuke.root().name()) padding = len(rootVersion) new_version = str("{" + ":0>{}".format(padding) + "}").format( int(rootVersion)) log.info("new_version: {}".format(new_version)) except Exception: return for each in nuke.allNodes(): if each.Class() == 'Write': avalon_knob_data = get_avalon_knob_data(each) if avalon_knob_data['families'] not in ["render"]: log.info(avalon_knob_data['families']) continue try: node_file = each['file'].value() log.info("node_file: {}".format(node_file)) node_version = pype.get_version_from_path(node_file) log.info("node_version: {}".format(node_version)) node_new_file = node_file.replace(node_version, new_version) each['file'].setValue(node_new_file) except Exception as e: log.debug("Write node: `{}` has no version in path: {}".format( each.name(), e))
def get_nodes(self, nodes=None, nodes_filter=None): # filter out only dictionaries for node creation # # print("\n\n") # pprint(self._nodes) # if not isinstance(nodes, list) and not isinstance(nodes_filter, list): return [n for n in nuke.allNodes()] elif not isinstance(nodes, list) and isinstance(nodes_filter, list): nodes = list() for filter in nodes_filter: [nodes.append(n) for n in nuke.allNodes(filter=filter)] return nodes elif isinstance(nodes, list) and not isinstance(nodes_filter, list): return [n for n in self._nodes] elif isinstance(nodes, list) and isinstance(nodes_filter, list): for filter in nodes_filter: return [n for n in self._nodes if filter in n.Class()]
def __init__(self, *args, **kwargs): super(PypeCreator, self).__init__(*args, **kwargs) self.presets = get_current_project_settings()["nuke"]["create"].get( self.__class__.__name__, {}) if check_subsetname_exists(nuke.allNodes(), self.data["subset"]): msg = ("The subset name `{0}` is already used on a node in" "this workfile.".format(self.data["subset"])) self.log.error(msg + '\n\nPlease use other subset name!') raise NameError("`{0}: {1}".format(__name__, msg)) return
def checkInventoryVersions(): """ Actiual version idetifier of Loaded containers Any time this function is run it will check all nodes and filter only Loader nodes for its version. It will get all versions from database and check if the node is having actual version. If not then it will color it to red. """ # TODO: make it for all nodes not just Read (Loader # get all Loader nodes by avalon attribute metadata for each in nuke.allNodes(): if each.Class() == 'Read': container = avalon.nuke.parse_container(each) if container: node = container["_node"] avalon_knob_data = avalon.nuke.get_avalon_knob_data( node, ['avalon:', 'ak:']) # get representation from io representation = io.find_one({ "type": "representation", "_id": io.ObjectId(avalon_knob_data["representation"]) }) # Get start frame from version data version = io.find_one({ "type": "version", "_id": representation["parent"] }) # get all versions in list versions = io.find({ "type": "version", "parent": version["parent"] }).distinct('name') max_version = max(versions) # check the available version and do match # change color of node if not max verion if version.get("name") not in [max_version]: node["tile_color"].setValue(int("0xd84f20ff", 16)) else: node["tile_color"].setValue(int("0x4ecd25ff", 16))
def set_viewers_colorspace(viewer): assert isinstance(viewer, dict), log.error( "set_viewers_colorspace(): argument should be dictionary") filter_knobs = ["viewerProcess", "wipe_position"] viewers = [n for n in nuke.allNodes() if n.Class() == 'Viewer'] erased_viewers = [] for v in viewers: v['viewerProcess'].setValue(str(viewer.viewerProcess)) if str(viewer.viewerProcess) not in v['viewerProcess'].value(): copy_inputs = v.dependencies() copy_knobs = { k: v[k].value() for k in v.knobs() if k not in filter_knobs } pprint(copy_knobs) # delete viewer with wrong settings erased_viewers.append(v['name'].value()) nuke.delete(v) # create new viewer nv = nuke.createNode("Viewer") # connect to original inputs for i, n in enumerate(copy_inputs): nv.setInput(i, n) # set coppied knobs for k, v in copy_knobs.items(): print(k, v) nv[k].setValue(v) # set viewerProcess nv['viewerProcess'].setValue(str(viewer.viewerProcess)) if erased_viewers: log.warning("Attention! Viewer nodes {} were erased." "It had wrong color profile".format(erased_viewers))
def writes_version_sync(): ''' Callback synchronizing version of publishable write nodes ''' # TODO: make it work with new write node group try: rootVersion = pype.get_version_from_path(nuke.root().name()) padding = len(rootVersion) new_version = "v" + str("{" + ":0>{}".format(padding) + "}").format( int(rootVersion)) log.debug("new_version: {}".format(new_version)) except Exception: return for each in nuke.allNodes(): if each.Class() == 'Write': avalon_knob_data = avalon.nuke.get_avalon_knob_data( each, ['avalon:', 'ak:']) try: if avalon_knob_data['families'] not in ["render"]: log.debug(avalon_knob_data['families']) continue node_file = each['file'].value() node_version = "v" + pype.get_version_from_path(node_file) log.debug("node_version: {}".format(node_version)) node_new_file = node_file.replace(node_version, new_version) each['file'].setValue(node_new_file) if not os.path.isdir(os.path.dirname(node_new_file)): log.warning("Path does not exist! I am creating it.") os.makedirs(os.path.dirname(node_new_file), 0o766) except Exception as e: log.warning( "Write node: `{}` has no version in path: {}".format( each.name(), e))