Skip to content

Commit

Permalink
Merge pull request #13 from ynput/enhancement/use_task_attributes
Browse files Browse the repository at this point in the history
Use task attributes for WorkfileSettings
  • Loading branch information
moonyuet authored Aug 26, 2024
2 parents 698a7c0 + c5541d1 commit 7a08f57
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
41 changes: 24 additions & 17 deletions client/ayon_nuke/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,10 +1393,17 @@ def __init__(self, root_node=None, nodes=None, **kwargs):
Context._project_entity = project_entity
self._project_name = project_name
self._folder_path = get_current_folder_path()
self._task_name = get_current_task_name()
self._folder_entity = ayon_api.get_folder_by_path(
project_name, self._folder_path
)
self._task_name = get_current_task_name()
self._context_label = "{} > {}".format(self._folder_path,
self._task_name)
self._task_entity = ayon_api.get_task_by_name(
project_name,
self._folder_entity["id"],
self._task_name
)
self._root_node = root_node or nuke.root()
self._nodes = self.get_nodes(nodes=nodes)

Expand Down Expand Up @@ -1907,39 +1914,39 @@ def set_colorspace(self):
def reset_frame_range_handles(self):
"""Set frame range to current folder."""

if "attrib" not in self._folder_entity:
msg = "Folder {} don't have set any 'attrib'".format(
self._folder_path
if "attrib" not in self._task_entity:
msg = "Task {} doesn't have set any 'attrib'".format(
self._context_label
)
log.warning(msg)
nuke.message(msg)
return

folder_attributes = self._folder_entity["attrib"]
task_attributes = self._task_entity["attrib"]

missing_cols = []
check_cols = ["fps", "frameStart", "frameEnd",
"handleStart", "handleEnd"]

for col in check_cols:
if col not in folder_attributes:
if col not in task_attributes:
missing_cols.append(col)

if len(missing_cols) > 0:
missing = ", ".join(missing_cols)
msg = "'{}' are not set for folder '{}'!".format(
missing, self._folder_path)
msg = "'{}' are not set for task '{}'!".format(
missing, self._context_label)
log.warning(msg)
nuke.message(msg)
return

# get handles values
handle_start = folder_attributes["handleStart"]
handle_end = folder_attributes["handleEnd"]
frame_start = folder_attributes["frameStart"]
frame_end = folder_attributes["frameEnd"]
handle_start = task_attributes["handleStart"]
handle_end = task_attributes["handleEnd"]
frame_start = task_attributes["frameStart"]
frame_end = task_attributes["frameEnd"]

fps = float(folder_attributes["fps"])
fps = float(task_attributes["fps"])
frame_start_handle = frame_start - handle_start
frame_end_handle = frame_end + handle_end

Expand Down Expand Up @@ -1979,12 +1986,12 @@ def reset_resolution(self):
"""Set resolution to project resolution."""
log.info("Resetting resolution")
project_name = get_current_project_name()
folder_attributes = self._folder_entity["attrib"]
task_attributes = self._task_entity["attrib"]

format_data = {
"width": folder_attributes["resolutionWidth"],
"height": folder_attributes["resolutionHeight"],
"pixel_aspect": folder_attributes["pixelAspect"],
"width": task_attributes["resolutionWidth"],
"height": task_attributes["resolutionHeight"],
"pixel_aspect": task_attributes["pixelAspect"],
"name": project_name
}

Expand Down
27 changes: 16 additions & 11 deletions client/ayon_nuke/plugins/publish/validate_script_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ def process(self, instance):

script_data = deepcopy(instance.context.data["scriptData"])

src_folder_attributes = instance.data["folderEntity"]["attrib"]
# Task may be optional for an instance
task_entity = instance.data.get("taskEntity")
if task_entity:
src_attributes = task_entity["attrib"]
else:
src_attributes = instance.data["folderEntity"]["attrib"]

# These attributes will be checked
attributes = [
Expand All @@ -44,32 +49,32 @@ def process(self, instance):
"handleEnd"
]

# get only defined attributes from folder data
folder_attributes = {
attr: src_folder_attributes[attr]
# get only defined attributes from folder or task data
check_attributes = {
attr: src_attributes[attr]
for attr in attributes
if attr in src_folder_attributes
if attr in src_attributes
}
# fix frame values to include handles
folder_attributes["fps"] = float("{0:.4f}".format(
folder_attributes["fps"]))
check_attributes["fps"] = float("{0:.4f}".format(
check_attributes["fps"]))
script_data["fps"] = float("{0:.4f}".format(
script_data["fps"]))

# Compare folder's values Nukescript X Database
not_matching = []
for attr in attributes:
self.log.debug(
"Folder vs Script attribute \"{}\": {}, {}".format(
"Task vs Script attribute \"{}\": {}, {}".format(
attr,
folder_attributes[attr],
check_attributes[attr],
script_data[attr]
)
)
if folder_attributes[attr] != script_data[attr]:
if check_attributes[attr] != script_data[attr]:
not_matching.append({
"name": attr,
"expected": folder_attributes[attr],
"expected": check_attributes[attr],
"actual": script_data[attr]
})

Expand Down

0 comments on commit 7a08f57

Please sign in to comment.