mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
Merged in bugfix/PYPE-29-nuke-fix-set-format (pull request #14)
Bugfix/PYPE-29 nuke fix set format Approved-by: Milan Kolar <milan@orbi.tools>
This commit is contained in:
commit
911335a097
3 changed files with 130 additions and 67 deletions
157
pype/nuke/lib.py
157
pype/nuke/lib.py
|
|
@ -2,6 +2,7 @@ import sys
|
|||
from collections import OrderedDict
|
||||
from pprint import pprint
|
||||
from avalon.vendor.Qt import QtGui
|
||||
from avalon import api, io
|
||||
import avalon.nuke
|
||||
import pype.api as pype
|
||||
import nuke
|
||||
|
|
@ -99,57 +100,6 @@ def add_rendering_knobs(node):
|
|||
return node
|
||||
|
||||
|
||||
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 get_additional_data(container):
|
||||
"""Get Nuke's related data for the container
|
||||
|
||||
Args:
|
||||
container(dict): the container found by the ls() function
|
||||
|
||||
Returns:
|
||||
dict
|
||||
"""
|
||||
|
||||
node = container["_tool"]
|
||||
tile_color = node['tile_color'].value()
|
||||
if tile_color is None:
|
||||
return {}
|
||||
|
||||
hex = '%08x' % tile_color
|
||||
rgba = [
|
||||
float(int(hex[0:2], 16)) / 255.0,
|
||||
float(int(hex[2:4], 16)) / 255.0,
|
||||
float(int(hex[4:6], 16)) / 255.0
|
||||
]
|
||||
|
||||
return {"color": QtGui.QColor().fromRgbF(rgba[0], rgba[1], rgba[2])}
|
||||
|
||||
|
||||
def set_viewers_colorspace(viewer):
|
||||
assert isinstance(viewer, dict), log.error(
|
||||
"set_viewers_colorspace(): argument should be dictionary")
|
||||
|
|
@ -245,6 +195,111 @@ def get_avalon_knob_data(node):
|
|||
return None
|
||||
return data
|
||||
|
||||
|
||||
def reset_resolution():
|
||||
"""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"})
|
||||
|
||||
try:
|
||||
width = asset["data"].get("resolution_width", 1920)
|
||||
height = asset["data"].get("resolution_height", 1080)
|
||||
pixel_aspect = asset["data"].get("pixel_aspect", 1)
|
||||
bbox = asset["data"].get("crop", "0.0.1920.1080")
|
||||
|
||||
try:
|
||||
x, y, r, t = bbox.split(".")
|
||||
except Exception as e:
|
||||
x = 0
|
||||
y = 0
|
||||
r = width
|
||||
t = height
|
||||
log.error("{}: {} \nFormat:Crop need to be set with dots, example: "
|
||||
"0.0.1920.1080, /nSetting to default".format(__name__, e))
|
||||
|
||||
except KeyError:
|
||||
log.warning(
|
||||
"No resolution information found for \"{0}\".".format(
|
||||
project["name"]
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
used_formats = list()
|
||||
for f in nuke.formats():
|
||||
if project["name"] in str(f.name()):
|
||||
used_formats.append(f)
|
||||
else:
|
||||
format_name = project["name"] + "_1"
|
||||
|
||||
crnt_fmt_str = ""
|
||||
if used_formats:
|
||||
check_format = used_formats[-1]
|
||||
format_name = "{}_{}".format(
|
||||
project["name"],
|
||||
int(used_formats[-1].name()[-1])+1
|
||||
)
|
||||
log.info(
|
||||
"Format exists: {}. "
|
||||
"Will create new: {}...".format(
|
||||
used_formats[-1].name(),
|
||||
format_name)
|
||||
)
|
||||
crnt_fmt_kargs = {
|
||||
"width": (check_format.width()),
|
||||
"height": (check_format.height()),
|
||||
"x": int(check_format.x()),
|
||||
"y": int(check_format.y()),
|
||||
"r": int(check_format.r()),
|
||||
"t": int(check_format.t()),
|
||||
"pixel_aspect": float(check_format.pixelAspect())
|
||||
}
|
||||
crnt_fmt_str = make_format_string(**crnt_fmt_kargs)
|
||||
log.info("crnt_fmt_str: {}".format(crnt_fmt_str))
|
||||
|
||||
new_fmt_kargs = {
|
||||
"width": int(width),
|
||||
"height": int(height),
|
||||
"x": int(x),
|
||||
"y": int(y),
|
||||
"r": int(r),
|
||||
"t": int(t),
|
||||
"pixel_aspect": float(pixel_aspect),
|
||||
"project_name": format_name
|
||||
}
|
||||
|
||||
new_fmt_str = make_format_string(**new_fmt_kargs)
|
||||
log.info("new_fmt_str: {}".format(new_fmt_str))
|
||||
|
||||
if new_fmt_str not in crnt_fmt_str:
|
||||
make_format(frm_str=new_fmt_str,
|
||||
project_name=new_fmt_kargs["project_name"])
|
||||
|
||||
log.info("Format is set")
|
||||
|
||||
|
||||
def make_format_string(**args):
|
||||
format_str = (
|
||||
"{width} "
|
||||
"{height} "
|
||||
"{x} "
|
||||
"{y} "
|
||||
"{r} "
|
||||
"{t} "
|
||||
"{pixel_aspect:.2f}".format(**args)
|
||||
)
|
||||
return format_str
|
||||
|
||||
|
||||
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))
|
||||
|
||||
|
||||
# TODO: bellow functions are wip and needs to be check where they are used
|
||||
# ------------------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue