mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 22:02:15 +01:00
Merged in feature/PYPE-342-handles-from-tags (pull request #152)
Feature/PYPE-342 handles from tags Approved-by: Milan Kolar <milan@orbi.tools>
This commit is contained in:
commit
f9c622acef
13 changed files with 181 additions and 43 deletions
|
|
@ -39,6 +39,7 @@ from .templates import (
|
|||
)
|
||||
|
||||
from .lib import (
|
||||
get_handle_irregular,
|
||||
get_project_data,
|
||||
get_asset_data,
|
||||
modified_environ,
|
||||
|
|
@ -67,6 +68,7 @@ __all__ = [
|
|||
"reset_data_from_templates",
|
||||
|
||||
# get contextual data
|
||||
"get_handle_irregular",
|
||||
"get_project_data",
|
||||
"get_asset_data",
|
||||
"get_project_name",
|
||||
|
|
|
|||
|
|
@ -15,6 +15,13 @@ import avalon
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_handle_irregular(asset):
|
||||
data = asset["data"]
|
||||
handle_start = data.get("handle_start", 0)
|
||||
handle_end = asset.get("handle_end", 0)
|
||||
return (handle_start, handle_end)
|
||||
|
||||
|
||||
def add_tool_to_environment(tools):
|
||||
"""
|
||||
It is adding dynamic environment to os environment.
|
||||
|
|
|
|||
102
pype/nuke/lib.py
102
pype/nuke/lib.py
|
|
@ -335,6 +335,54 @@ def set_colorspace():
|
|||
"contact your supervisor!")
|
||||
|
||||
|
||||
def reset_frame_range_handles():
|
||||
"""Set frame range to current asset"""
|
||||
|
||||
fps = float(api.Session.get("AVALON_FPS", 25))
|
||||
nuke.root()["fps"].setValue(fps)
|
||||
name = api.Session["AVALON_ASSET"]
|
||||
asset = io.find_one({"name": name, "type": "asset"})
|
||||
|
||||
if "data" not in asset:
|
||||
msg = "Asset {} don't have set any 'data'".format(name)
|
||||
log.warning(msg)
|
||||
nuke.message(msg)
|
||||
return
|
||||
data = asset["data"]
|
||||
|
||||
missing_cols = []
|
||||
check_cols = ["fstart", "fend"]
|
||||
|
||||
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, name)
|
||||
log.warning(msg)
|
||||
nuke.message(msg)
|
||||
return
|
||||
|
||||
# get handles values
|
||||
handles = avalon.nuke.get_handles(asset)
|
||||
handle_start, handle_end = pype.get_handle_irregular(asset)
|
||||
|
||||
edit_in = int(asset["data"]["fstart"]) - handles - handle_start
|
||||
edit_out = int(asset["data"]["fend"]) + handles + handle_end
|
||||
|
||||
nuke.root()["first_frame"].setValue(edit_in)
|
||||
nuke.root()["last_frame"].setValue(edit_out)
|
||||
|
||||
# setting active viewers
|
||||
vv = nuke.activeViewer().node()
|
||||
vv['frame_range_lock'].setValue(True)
|
||||
vv['frame_range'].setValue('{0}-{1}'.format(
|
||||
int(asset["data"]["fstart"]),
|
||||
int(asset["data"]["fend"]))
|
||||
)
|
||||
|
||||
|
||||
def get_avalon_knob_data(node):
|
||||
import toml
|
||||
try:
|
||||
|
|
@ -451,33 +499,33 @@ def make_format(**args):
|
|||
# TODO: bellow functions are wip and needs to be check where they are used
|
||||
# ------------------------------------
|
||||
|
||||
|
||||
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 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
|
||||
#
|
||||
|
|
|
|||
|
|
@ -17,5 +17,17 @@ def install():
|
|||
menu.removeItem(rm_item[1].name())
|
||||
menu.addCommand(rm_item[1].name(), lib.reset_resolution, index=rm_item[0])
|
||||
|
||||
# replace reset resolution from avalon core to pype's
|
||||
name = "Reset Frame Range"
|
||||
rm_item = [(i, item)
|
||||
for i, item in enumerate(menu.items())
|
||||
if name in item.name()][0]
|
||||
menu.removeItem(rm_item[1].name())
|
||||
menu.addCommand(
|
||||
rm_item[1].name(),
|
||||
lib.reset_frame_range_handles,
|
||||
index=rm_item[0])
|
||||
|
||||
# add colorspace menu item
|
||||
menu.addCommand("Set colorspace...", lib.set_colorspace, index=rm_item[0]+1)
|
||||
menu.addCommand("Set colorspace...", lib.set_colorspace,
|
||||
index=rm_item[0] + 1)
|
||||
|
|
|
|||
|
|
@ -5,17 +5,16 @@ import sys
|
|||
# Pyblish libraries
|
||||
import pyblish.api
|
||||
|
||||
# Host libraries
|
||||
import hiero
|
||||
|
||||
from pypeapp import Logger
|
||||
log = Logger().get_logger(__name__, "nukestudio")
|
||||
|
||||
import avalon.api as avalon
|
||||
import pype.api as pype
|
||||
|
||||
from avalon.vendor.Qt import (QtWidgets, QtGui)
|
||||
|
||||
# Host libraries
|
||||
import hiero
|
||||
|
||||
from pypeapp import Logger
|
||||
log = Logger().get_logger(__name__, "nukestudio")
|
||||
|
||||
cached_process = None
|
||||
|
||||
|
|
|
|||
16
pype/plugins/global/publish/collect_project_data.py
Normal file
16
pype/plugins/global/publish/collect_project_data.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import pyblish.api
|
||||
import pype.api as pype
|
||||
|
||||
|
||||
|
||||
class CollectProjectData(pyblish.api.ContextPlugin):
|
||||
"""Collecting project data from avalon db"""
|
||||
|
||||
label = "Collect Project Data"
|
||||
order = pyblish.api.CollectorOrder
|
||||
|
||||
def process(self, context):
|
||||
# get project data from avalon db
|
||||
context.data["projectData"] = pype.get_project_data()
|
||||
|
||||
return
|
||||
|
|
@ -9,9 +9,10 @@ class CollectClips(api.ContextPlugin):
|
|||
hosts = ["nukestudio"]
|
||||
|
||||
def process(self, context):
|
||||
projectdata = context.data["projectData"]
|
||||
data = {}
|
||||
for item in context.data.get("selection", []):
|
||||
self.log.info("__ item: {}".format(item))
|
||||
self.log.debug("__ item: {}".format(item))
|
||||
# Skip audio track items
|
||||
# Try/Except is to handle items types, like EffectTrackItem
|
||||
try:
|
||||
|
|
@ -37,5 +38,5 @@ class CollectClips(api.ContextPlugin):
|
|||
family=family,
|
||||
startFrame=value["startFrame"],
|
||||
endFrame=value["endFrame"],
|
||||
handles=0
|
||||
handles=projectdata['handles']
|
||||
)
|
||||
|
|
|
|||
52
pype/plugins/nukestudio/publish/collect_handles.py
Normal file
52
pype/plugins/nukestudio/publish/collect_handles.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import json
|
||||
from pyblish import api
|
||||
|
||||
class CollectClipHandles(api.InstancePlugin):
|
||||
"""Collect Handles from selected track items."""
|
||||
|
||||
order = api.CollectorOrder + 0.006
|
||||
label = "Collect Handles"
|
||||
hosts = ["nukestudio"]
|
||||
families = ['clip']
|
||||
|
||||
def process(self, instance):
|
||||
# gets tags
|
||||
tags = instance.data["tags"]
|
||||
|
||||
for t in tags:
|
||||
t_metadata = dict(t["metadata"])
|
||||
t_family = t_metadata.get("tag.family", "")
|
||||
|
||||
# gets only task family tags and collect labels
|
||||
if "handles" in t_family:
|
||||
# gets value of handles
|
||||
t_value = int(t_metadata.get("tag.value", ""))
|
||||
|
||||
# gets arguments if there are any
|
||||
t_args = t_metadata.get("tag.args", "")
|
||||
|
||||
# distribute handles
|
||||
if not t_args:
|
||||
# add handles to both sides
|
||||
instance.data['handles'] = t_value
|
||||
self.log.info("Collected Handles: `{}`".format(
|
||||
instance.data['handles']))
|
||||
else:
|
||||
t_args = json.loads(t_args.replace("'", "\""))
|
||||
# add in start
|
||||
if 'start' in t_args['where']:
|
||||
hs = instance.data.get('handle_start')
|
||||
if not hs:
|
||||
instance.data['handle_start'] = 0
|
||||
instance.data['handle_start'] += t_value
|
||||
self.log.info("Collected Handle Start: `{}`".format(
|
||||
instance.data['handle_start']))
|
||||
|
||||
# add in end
|
||||
if 'end' in t_args['where']:
|
||||
hs = instance.data.get('handle_end')
|
||||
if not hs:
|
||||
instance.data['handle_end'] = 0
|
||||
instance.data['handle_end'] += t_value
|
||||
self.log.info("Collected Handle End: `{}`".format(
|
||||
instance.data['handle_end']))
|
||||
|
|
@ -41,7 +41,7 @@ class CollectHierarchyInstance(pyblish.api.InstancePlugin):
|
|||
data = {
|
||||
"sequence": context.data['activeSequence'].name().replace(' ', '_'),
|
||||
"track": clip.parent().name().replace(' ', '_'),
|
||||
"shot": asset
|
||||
"clip": asset
|
||||
}
|
||||
self.log.debug("__ data: {}".format(data))
|
||||
|
||||
|
|
@ -65,16 +65,18 @@ class CollectHierarchyInstance(pyblish.api.InstancePlugin):
|
|||
|
||||
# if shot in template then remove it
|
||||
if "shot" in template.lower():
|
||||
instance.data["asset"] = [t for t in template.split('/')][-1]
|
||||
template = "/".join([t for t in template.split('/')][0:-1])
|
||||
|
||||
# take template from Tag.note and break it into parts
|
||||
patern = re.compile(r"^\{([a-z]*?)\}")
|
||||
patern = re.compile(r"\{([a-z]*?)\}")
|
||||
par_split = [patern.findall(t)[0]
|
||||
for t in template.split("/")]
|
||||
|
||||
# format all {} in two layers
|
||||
for k, v in t_metadata.items():
|
||||
new_k = k.split(".")[1]
|
||||
# self.log.info("__ new_k: `{}`".format(new_k))
|
||||
try:
|
||||
# first try all data and context data to
|
||||
# add to individual properties
|
||||
|
|
@ -82,9 +84,6 @@ class CollectHierarchyInstance(pyblish.api.InstancePlugin):
|
|||
**dict(context.data, **data))
|
||||
d_metadata[new_k] = new_v
|
||||
|
||||
if 'shot' in new_k:
|
||||
instance.data["asset"] = new_v
|
||||
|
||||
# create parents
|
||||
# find matching index of order
|
||||
p_match_i = [i for i, p in enumerate(par_split)
|
||||
|
|
@ -97,6 +96,10 @@ class CollectHierarchyInstance(pyblish.api.InstancePlugin):
|
|||
except Exception:
|
||||
d_metadata[new_k] = v
|
||||
|
||||
# create new shot asset name
|
||||
instance.data["asset"] = instance.data["asset"].format(
|
||||
**d_metadata)
|
||||
|
||||
# lastly fill those individual properties itno
|
||||
# format the string with collected data
|
||||
hierarchy = template.format(
|
||||
|
|
@ -105,7 +108,6 @@ class CollectHierarchyInstance(pyblish.api.InstancePlugin):
|
|||
# check if hierarchy attribute is already created
|
||||
# it should not be so return warning if it is
|
||||
hd = instance.data.get("hierarchy")
|
||||
self.log.info("__ hd: {}".format(hd))
|
||||
assert not hd, "Only one Hierarchy Tag is \
|
||||
allowed. Clip: `{}`".format(asset)
|
||||
|
||||
|
|
@ -143,7 +145,6 @@ class CollectHierarchyContext(pyblish.api.ContextPlugin):
|
|||
if 'projectfile' in instance.data.get('family', ''):
|
||||
continue
|
||||
|
||||
|
||||
in_info = {}
|
||||
name = instance.data["asset"]
|
||||
# suppose that all instances are Shots
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue