def set_root_colorspace(root_dict): assert isinstance(root_dict, dict), log.error( "set_root_colorspace(): argument should be dictionary") for knob, value in root_dict.items(): if nuke.root()[knob].value() not in value: nuke.root()[knob].setValue(str(value)) log.info("nuke.root()['{}'] changed to: {}".format(knob, value))
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 __init__(self, root_node=None, nodes=None, **kwargs): self._project = kwargs.get("project") or io.find_one( {"type": "project"}) self._asset = kwargs.get("asset_name") or api.Session["AVALON_ASSET"] self._asset_entity = pype.get_asset(self._asset) self._root_node = root_node or nuke.root() self._nodes = self.get_nodes(nodes=nodes) self.data = kwargs
def update_frame_range(start, end, root=None): """Set Nuke script start and end frame range Args: start (float, int): start frame end (float, int): end frame root (object, Optional): root object from nuke's script Returns: None """ knobs = {"first_frame": start, "last_frame": end} with avalon.nuke.viewer_update_and_undo_stop(): for key, value in knobs.items(): if root: root[key].setValue(value) else: nuke.root()[key].setValue(value)
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))
def script_name(): return nuke.root().knob('name').value()
def make_format(**args): log.info("Format does't exist, will create: \n{}".format(args)) nuke.addFormat("{frm_str} " "{project_name}".format(**args)) nuke.root()["format"].setValue("{project_name}".format(**args))
def reset_resolution(self): """Set resolution to project resolution.""" log.info("Reseting resolution") project = io.find_one({"type": "project"}) asset = api.Session["AVALON_ASSET"] asset = io.find_one({"name": asset, "type": "asset"}) asset_data = asset.get('data', {}) data = { "width": int( asset_data.get('resolutionWidth', asset_data.get('resolution_width'))), "height": int( asset_data.get('resolutionHeight', asset_data.get('resolution_height'))), "pixel_aspect": asset_data.get('pixelAspect', asset_data.get('pixel_aspect', 1)), "name": project["name"] } if any(x for x in data.values() if x is None): log.error("Missing set shot attributes in DB." "\nContact your supervisor!." "\n\nWidth: `{width}`" "\nHeight: `{height}`" "\nPixel Asspect: `{pixel_aspect}`".format(**data)) bbox = self._asset_entity.get('data', {}).get('crop') if bbox: try: x, y, r, t = bbox.split(".") data.update({ "x": int(x), "y": int(y), "r": int(r), "t": int(t), }) except Exception as e: bbox = None log.error( "{}: {} \nFormat:Crop need to be set with dots, example: " "0.0.1920.1080, /nSetting to default".format(__name__, e)) existing_format = None for format in nuke.formats(): if data["name"] == format.name(): existing_format = format break if existing_format: # Enforce existing format to be correct. existing_format.setWidth(data["width"]) existing_format.setHeight(data["height"]) existing_format.setPixelAspect(data["pixel_aspect"]) if bbox: existing_format.setX(data["x"]) existing_format.setY(data["y"]) existing_format.setR(data["r"]) existing_format.setT(data["t"]) else: format_string = self.make_format_string(**data) log.info("Creating new format: {}".format(format_string)) nuke.addFormat(format_string) nuke.root()["format"].setValue(data["name"]) log.info("Format is set.")
def script_name(): ''' Returns nuke script path ''' return nuke.root().knob('name').value()