def update(self, container, representation): """Update the Loader's path Fusion automatically tries to reset some variables when changing the loader's path to a new file. These automatic changes are to its inputs: """ from avalon.nuke import ( viewer_update_and_undo_stop, ls_img_sequence, update_container ) log.info("this i can see") node = container["_tool"] # TODO: prepare also for other readers img/geo/camera assert node.Class() == "Reader", "Must be Reader" root = api.get_representation_path(representation) file = ls_img_sequence(os.path.dirname(root), one=True) # Get start frame from version data version = io.find_one({"type": "version", "_id": representation["parent"]}) start = version["data"].get("startFrame") if start is None: log.warning("Missing start frame for updated version" "assuming starts at frame 0 for: " "{} ({})".format(node['name'].value(), representation)) start = 0 with viewer_update_and_undo_stop(): # Update the loader's path whilst preserving some values with preserve_trim(node): with preserve_inputs(node, knobs=["file", "first", "last", "originfirst", "originlast", "frame_mode", "frame"]): node["file"] = file["path"] # Set the global in to the start frame of the sequence global_in_changed = loader_shift(node, start, relative=False) if global_in_changed: # Log this change to the user log.debug("Changed '{}' global in:" " {:d}".format(node['name'].value(), start)) # Update the imprinted representation update_container( node, {"representation": str(representation["_id"])} )
def remove(self, container): from avalon.nuke import viewer_update_and_undo_stop node = nuke.toNode(container['objectName']) assert node.Class() == "Read", "Must be Read" with viewer_update_and_undo_stop(): nuke.delete(node)
def remove(self, container): from avalon.nuke import viewer_update_and_undo_stop node = container["_tool"] assert node.Class() == "Reader", "Must be Reader" with viewer_update_and_undo_stop(): nuke.delete(node)
def load(self, context, name, namespace, data): from avalon.nuke import ( containerise, ls_img_sequence, viewer_update_and_undo_stop ) log.info("here i am") # Fallback to asset name when namespace is None if namespace is None: namespace = context['asset']['name'] # Use the first file for now # TODO: fix path fname file = ls_img_sequence(os.path.dirname(self.fname), one=True) # Create the Loader with the filename path set with viewer_update_and_undo_stop(): # TODO: it might be universal read to img/geo/camera r = nuke.createNode( "Read", "name {}".format(self.name)) # TODO: does self.name exist? r["file"].setValue(file['path']) if len(file['frames']) is 1: first = file['frames'][0][0] last = file['frames'][0][1] r["originfirst"].setValue(first) r["first"].setValue(first) r["originlast"].setValue(last) r["last"].setValue(last) else: first = file['frames'][0][0] last = file['frames'][:-1][1] r["originfirst"].setValue(first) r["first"].setValue(first) r["originlast"].setValue(last) r["last"].setValue(last) log.warning("Missing frames in image sequence") # Set global in point to start frame (if in version.data) start = context["version"]["data"].get("startFrame", None) if start is not None: loader_shift(r, start, relative=False) containerise(r, name=name, namespace=namespace, context=context, loader=self.__class__.__name__)
def on_pyblish_instance_toggled(instance, old_value, new_value): """Toggle node passthrough states on instance toggles.""" self.log.info("instance toggle: {}, old_value: {}, new_value:{} ".format( instance, old_value, new_value)) from avalon.nuke import (viewer_update_and_undo_stop, add_publish_knob) # Whether instances should be passthrough based on new value with viewer_update_and_undo_stop(): n = instance[0] try: n["publish"].value() except ValueError: n = add_publish_knob(n) log.info(" `Publish` knob was added to write node..") n["publish"].setValue(new_value)
def remove(self, container): from avalon.nuke import viewer_update_and_undo_stop node = nuke.toNode(container['objectName']) with viewer_update_and_undo_stop(): nuke.delete(node)
def load(self, context, name, namespace, data): from avalon.nuke import (containerise, viewer_update_and_undo_stop) version = context['version'] version_data = version.get("data", {}) repr_id = context["representation"]["_id"] self.log.info("version_data: {}\n".format(version_data)) self.log.debug("Representation id `{}` ".format(repr_id)) self.first_frame = int(nuke.root()["first_frame"].getValue()) self.handle_start = version_data.get("handleStart", 0) self.handle_end = version_data.get("handleEnd", 0) first = version_data.get("frameStart", None) last = version_data.get("frameEnd", None) # Fallback to asset name when namespace is None if namespace is None: namespace = context['asset']['name'] first -= self.handle_start last += self.handle_end file = self.fname if not file: repr_id = context["representation"]["_id"] self.log.warning( "Representation id `{}` is failing to load".format(repr_id)) return file = file.replace("\\", "/") repr_cont = context["representation"]["context"] if "#" not in file: frame = repr_cont.get("frame") if frame: padding = len(frame) file = file.replace(frame, "#" * padding) name_data = { "asset": repr_cont["asset"], "subset": repr_cont["subset"], "representation": context["representation"]["name"], "ext": repr_cont["representation"], "id": context["representation"]["_id"], "class_name": self.__class__.__name__ } read_name = self.node_name_template.format(**name_data) # Create the Loader with the filename path set with viewer_update_and_undo_stop(): # TODO: it might be universal read to img/geo/camera r = nuke.createNode("Read", "name {}".format(read_name)) r["file"].setValue(file) # Set colorspace defined in version data colorspace = context["version"]["data"].get("colorspace") if colorspace: r["colorspace"].setValue(str(colorspace)) preset_clrsp = get_imageio_input_colorspace(file) if preset_clrsp is not None: r["colorspace"].setValue(preset_clrsp) loader_shift(r, first, relative=True) r["origfirst"].setValue(int(first)) r["first"].setValue(int(first)) r["origlast"].setValue(int(last)) r["last"].setValue(int(last)) # add additional metadata from the version to imprint Avalon knob add_keys = [ "frameStart", "frameEnd", "source", "colorspace", "author", "fps", "version", "handleStart", "handleEnd" ] data_imprint = {} for k in add_keys: if k == 'version': data_imprint.update({k: context["version"]['name']}) else: data_imprint.update( {k: context["version"]['data'].get(k, str(None))}) data_imprint.update({"objectName": read_name}) r["tile_color"].setValue(int("0x4ecd25ff", 16)) if version_data.get("retime", None): speed = version_data.get("speed", 1) time_warp_nodes = version_data.get("timewarps", []) self.make_retimes(r, speed, time_warp_nodes) return containerise(r, name=name, namespace=namespace, context=context, loader=self.__class__.__name__, data=data_imprint)
def load(self, context, name, namespace, data): from avalon.nuke import (containerise, viewer_update_and_undo_stop) version = context['version'] version_data = version.get("data", {}) repr_id = context["representation"]["_id"] orig_first = version_data.get("frameStart") orig_last = version_data.get("frameEnd") diff = orig_first - 1 first = orig_first - diff last = orig_last - diff handle_start = version_data.get("handleStart", 0) handle_end = version_data.get("handleEnd", 0) colorspace = version_data.get("colorspace") repr_cont = context["representation"]["context"] self.log.debug("Representation id `{}` ".format(repr_id)) context["representation"]["_id"] # create handles offset (only to last, because of mov) last += handle_start + handle_end # Fallback to asset name when namespace is None if namespace is None: namespace = context['asset']['name'] file = self.fname if not file: self.log.warning( "Representation id `{}` is failing to load".format(repr_id)) return file = file.replace("\\", "/") name_data = { "asset": repr_cont["asset"], "subset": repr_cont["subset"], "representation": context["representation"]["name"], "ext": repr_cont["representation"], "id": context["representation"]["_id"], "class_name": self.__class__.__name__ } read_name = self.node_name_template.format(**name_data) # Create the Loader with the filename path set with viewer_update_and_undo_stop(): read_node = nuke.createNode("Read", "name {}".format(read_name)) read_node["file"].setValue(file) read_node["origfirst"].setValue(first) read_node["first"].setValue(first) read_node["origlast"].setValue(last) read_node["last"].setValue(last) # start at script start read_node['frame_mode'].setValue("start at") read_node['frame'].setValue(str(self.script_start)) if colorspace: read_node["colorspace"].setValue(str(colorspace)) preset_clrsp = get_imageio_input_colorspace(file) if preset_clrsp is not None: read_node["colorspace"].setValue(preset_clrsp) # add additional metadata from the version to imprint Avalon knob add_keys = [ "frameStart", "frameEnd", "handles", "source", "author", "fps", "version", "handleStart", "handleEnd" ] data_imprint = {} for key in add_keys: if key == 'version': data_imprint.update({key: context["version"]['name']}) else: data_imprint.update( {key: context["version"]['data'].get(key, str(None))}) data_imprint.update({"objectName": read_name}) read_node["tile_color"].setValue(int("0x4ecd25ff", 16)) return containerise(read_node, name=name, namespace=namespace, context=context, loader=self.__class__.__name__, data=data_imprint)
def load(self, context, name, namespace, data): from avalon.nuke import (containerise, viewer_update_and_undo_stop) version = context['version'] version_data = version.get("data", {}) orig_first = version_data.get("frameStart", None) orig_last = version_data.get("frameEnd", None) diff = orig_first - 1 # set first to 1 first = orig_first - diff last = orig_last - diff handles = version_data.get("handles", None) handle_start = version_data.get("handleStart", None) handle_end = version_data.get("handleEnd", None) repr_cont = context["representation"]["context"] # fix handle start and end if none are available if not handle_start and not handle_end: handle_start = handles handle_end = handles # create handles offset (only to last, because of mov) last += handle_start + handle_end # offset should be with handles so it match orig frame range offset_frame = orig_first + handle_start # Fallback to asset name when namespace is None if namespace is None: namespace = context['asset']['name'] file = self.fname.replace("\\", "/") log.info("file: {}\n".format(self.fname)) read_name = "Read_{0}_{1}_{2}".format(repr_cont["asset"], repr_cont["subset"], repr_cont["representation"]) # Create the Loader with the filename path set with viewer_update_and_undo_stop(): # TODO: it might be universal read to img/geo/camera read_node = nuke.createNode("Read", "name {}".format(read_name)) read_node["file"].setValue(file) loader_shift(read_node, first, relative=True) read_node["origfirst"].setValue(first) read_node["first"].setValue(first) read_node["origlast"].setValue(last) read_node["last"].setValue(last) read_node["frame_mode"].setValue("start at") read_node["frame"].setValue(str(offset_frame)) # add additional metadata from the version to imprint to Avalon knob add_keys = [ "frameStart", "frameEnd", "handles", "source", "author", "fps", "version", "handleStart", "handleEnd" ] data_imprint = {} for key in add_keys: if key is 'version': data_imprint.update({key: context["version"]['name']}) else: data_imprint.update( {key: context["version"]['data'].get(key, str(None))}) data_imprint.update({"objectName": read_name}) read_node["tile_color"].setValue(int("0x4ecd25ff", 16)) return containerise(read_node, name=name, namespace=namespace, context=context, loader=self.__class__.__name__, data=data_imprint)
def load(self, context, name, namespace, data): from avalon.nuke import ( containerise, viewer_update_and_undo_stop ) version = context['version'] version_data = version.get("data", {}) repr_id = context["representation"]["_id"] orig_first = version_data.get("frameStart") orig_last = version_data.get("frameEnd") diff = orig_first - 1 first = orig_first - diff last = orig_last - diff handle_start = version_data.get("handleStart", 0) handle_end = version_data.get("handleEnd", 0) colorspace = version_data.get("colorspace") repr_cont = context["representation"]["context"] self.log.debug( "Representation id `{}` ".format(repr_id)) context["representation"]["_id"] # create handles offset (only to last, because of mov) last += handle_start + handle_end # offset should be with handles so it match orig frame range offset_frame = orig_first - handle_start # Fallback to asset name when namespace is None if namespace is None: namespace = context['asset']['name'] file = self.fname if not file: self.log.warning( "Representation id `{}` is failing to load".format(repr_id)) return file = file.replace("\\", "/") read_name = "Read_{0}_{1}_{2}".format( repr_cont["asset"], repr_cont["subset"], repr_cont["representation"]) # Create the Loader with the filename path set with viewer_update_and_undo_stop(): read_node = nuke.createNode( "Read", "name {}".format(read_name) ) read_node["file"].setValue(file) loader_shift(read_node, first, relative=True) read_node["origfirst"].setValue(first) read_node["first"].setValue(first) read_node["origlast"].setValue(last) read_node["last"].setValue(last) read_node["frame_mode"].setValue("start at") read_node["frame"].setValue(str(offset_frame)) if colorspace: read_node["colorspace"].setValue(str(colorspace)) # load nuke presets for Read's colorspace read_clrs_presets = presets.get_colorspace_preset().get( "nuke", {}).get("read", {}) # check if any colorspace presets for read is mathing preset_clrsp = next((read_clrs_presets[k] for k in read_clrs_presets if bool(re.search(k, file))), None) if preset_clrsp is not None: read_node["colorspace"].setValue(str(preset_clrsp)) # add additional metadata from the version to imprint Avalon knob add_keys = [ "frameStart", "frameEnd", "handles", "source", "author", "fps", "version", "handleStart", "handleEnd" ] data_imprint = {} for key in add_keys: if key == 'version': data_imprint.update({ key: context["version"]['name'] }) else: data_imprint.update({ key: context["version"]['data'].get(key, str(None)) }) data_imprint.update({"objectName": read_name}) read_node["tile_color"].setValue(int("0x4ecd25ff", 16)) return containerise( read_node, name=name, namespace=namespace, context=context, loader=self.__class__.__name__, data=data_imprint )
def load(self, context, name, namespace, options): from avalon.nuke import (containerise, viewer_update_and_undo_stop) self.log.info("__ options: `{}`".format(options)) frame_number = options.get("frame_number", 1) version = context['version'] version_data = version.get("data", {}) repr_id = context["representation"]["_id"] self.log.info("version_data: {}\n".format(version_data)) self.log.debug("Representation id `{}` ".format(repr_id)) last = first = int(frame_number) # Fallback to asset name when namespace is None if namespace is None: namespace = context['asset']['name'] file = self.fname if not file: repr_id = context["representation"]["_id"] self.log.warning( "Representation id `{}` is failing to load".format(repr_id)) return file = file.replace("\\", "/") repr_cont = context["representation"]["context"] frame = repr_cont.get("frame") if frame: padding = len(frame) file = file.replace(frame, format(frame_number, "0{}".format(padding))) name_data = { "asset": repr_cont["asset"], "subset": repr_cont["subset"], "representation": context["representation"]["name"], "ext": repr_cont["representation"], "id": context["representation"]["_id"], "class_name": self.__class__.__name__ } read_name = self.node_name_template.format(**name_data) # Create the Loader with the filename path set with viewer_update_and_undo_stop(): r = nuke.createNode("Read", "name {}".format(read_name)) r["file"].setValue(file) # Set colorspace defined in version data colorspace = context["version"]["data"].get("colorspace") if colorspace: r["colorspace"].setValue(str(colorspace)) preset_clrsp = get_imageio_input_colorspace(file) if preset_clrsp is not None: r["colorspace"].setValue(preset_clrsp) r["origfirst"].setValue(first) r["first"].setValue(first) r["origlast"].setValue(last) r["last"].setValue(last) # add additional metadata from the version to imprint Avalon knob add_keys = ["source", "colorspace", "author", "fps", "version"] data_imprint = {"frameStart": first, "frameEnd": last} for k in add_keys: if k == 'version': data_imprint.update({k: context["version"]['name']}) else: data_imprint.update( {k: context["version"]['data'].get(k, str(None))}) data_imprint.update({"objectName": read_name}) r["tile_color"].setValue(int("0x4ecd25ff", 16)) return containerise(r, name=name, namespace=namespace, context=context, loader=self.__class__.__name__, data=data_imprint)