mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
feat(nukestudio): working on plugins
This commit is contained in:
parent
360586a7cf
commit
d80631851e
6 changed files with 242 additions and 46 deletions
148
pype/nukestudio/precomp_clip.py
Normal file
148
pype/nukestudio/precomp_clip.py
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
from hiero.core import *
|
||||
from hiero.ui import *
|
||||
import ft_utils
|
||||
import re
|
||||
import os
|
||||
|
||||
|
||||
def create_nk_script_clips(script_lst, seq=None):
|
||||
'''
|
||||
nk_scripts is list of dictionaries like:
|
||||
[{
|
||||
'path': 'P:/Jakub_testy_pipeline/test_v01.nk',
|
||||
'name': 'test',
|
||||
'timeline_frame_in': 10,
|
||||
'handles': 10,
|
||||
'source_start': 0,
|
||||
'source_end': 54,
|
||||
'task': 'Comp-tracking',
|
||||
'work_dir': 'VFX_PR',
|
||||
'shot': '00010'
|
||||
}]
|
||||
'''
|
||||
env = ft_utils.Env()
|
||||
proj = projects()[-1]
|
||||
root = proj.clipsBin()
|
||||
|
||||
if not seq:
|
||||
seq = Sequence('NewSequences')
|
||||
root.addItem(BinItem(seq))
|
||||
# todo will ned to define this better
|
||||
# track = seq[1] # lazy example to get a destination# track
|
||||
clips_lst = []
|
||||
for nk in script_lst:
|
||||
task_short = env.task_codes[nk['task']]
|
||||
script_file = task_short
|
||||
task_path = '/'.join([nk['work_dir'], nk['shot'], nk['task']])
|
||||
bin = create_bin_in_project(task_path, proj)
|
||||
task_path += script_file
|
||||
|
||||
if nk['task'] not in seq.videoTracks():
|
||||
track = hiero.core.VideoTrack(nk['task'])
|
||||
seq.addTrack(track)
|
||||
else:
|
||||
track = seq.tracks(nk['task'])
|
||||
|
||||
# create slip media
|
||||
print nk['path']
|
||||
media = MediaSource(nk['path'])
|
||||
print media
|
||||
source = Clip(media)
|
||||
print source
|
||||
name = os.path.basename(os.path.splitext(nk['path'])[0])
|
||||
split_name = split_by_client_version(name, env)[0] or name
|
||||
print split_name
|
||||
# print source
|
||||
# add to bin as clip item
|
||||
items_in_bin = [b.name() for b in bin.items()]
|
||||
if split_name not in items_in_bin:
|
||||
binItem = BinItem(source)
|
||||
bin.addItem(binItem)
|
||||
print bin.items()
|
||||
new_source = [
|
||||
item for item in bin.items() if split_name in item.name()
|
||||
][0].items()[0].item()
|
||||
print new_source
|
||||
# add to track as clip item
|
||||
trackItem = TrackItem(split_name, TrackItem.kVideo)
|
||||
trackItem.setSource(new_source)
|
||||
trackItem.setSourceIn(nk['source_start'] + nk['handles'])
|
||||
trackItem.setSourceOut(nk['source_end'] - nk['handles'])
|
||||
trackItem.setTimelineIn(nk['source_start'] + nk['timeline_frame_in'])
|
||||
trackItem.setTimelineOut(
|
||||
(nk['source_end'] - (nk['handles'] * 2)) + nk['timeline_frame_in'])
|
||||
track.addTrackItem(trackItem)
|
||||
track.addTrackItem(trackItem)
|
||||
clips_lst.append(trackItem)
|
||||
|
||||
return clips_lst
|
||||
|
||||
|
||||
def create_bin_in_project(bin_name='', project=''):
|
||||
'''
|
||||
create bin in project and
|
||||
if the bin_name is "bin1/bin2/bin3" it will create whole depth
|
||||
'''
|
||||
|
||||
if not project:
|
||||
# get the first loaded project
|
||||
project = projects()[0]
|
||||
if not bin_name:
|
||||
return None
|
||||
if '/' in bin_name:
|
||||
bin_name = bin_name.split('/')
|
||||
else:
|
||||
bin_name = [bin_name]
|
||||
|
||||
clipsBin = project.clipsBin()
|
||||
|
||||
done_bin_lst = []
|
||||
for i, b in enumerate(bin_name):
|
||||
if i == 0 and len(bin_name) > 1:
|
||||
if b in [bin.name() for bin in clipsBin.bins()]:
|
||||
bin = [bin for bin in clipsBin.bins() if b in bin.name()][0]
|
||||
done_bin_lst.append(bin)
|
||||
else:
|
||||
create_bin = Bin(b)
|
||||
clipsBin.addItem(create_bin)
|
||||
done_bin_lst.append(create_bin)
|
||||
|
||||
elif i >= 1 and i < len(bin_name) - 1:
|
||||
if b in [bin.name() for bin in done_bin_lst[i - 1].bins()]:
|
||||
bin = [
|
||||
bin for bin in done_bin_lst[i - 1].bins()
|
||||
if b in bin.name()
|
||||
][0]
|
||||
done_bin_lst.append(bin)
|
||||
else:
|
||||
create_bin = Bin(b)
|
||||
done_bin_lst[i - 1].addItem(create_bin)
|
||||
done_bin_lst.append(create_bin)
|
||||
|
||||
elif i == len(bin_name) - 1:
|
||||
if b in [bin.name() for bin in done_bin_lst[i - 1].bins()]:
|
||||
bin = [
|
||||
bin for bin in done_bin_lst[i - 1].bins()
|
||||
if b in bin.name()
|
||||
][0]
|
||||
done_bin_lst.append(bin)
|
||||
else:
|
||||
create_bin = Bin(b)
|
||||
done_bin_lst[i - 1].addItem(create_bin)
|
||||
done_bin_lst.append(create_bin)
|
||||
# print [bin.name() for bin in clipsBin.bins()]
|
||||
return done_bin_lst[-1]
|
||||
|
||||
|
||||
def split_by_client_version(string, env=None):
|
||||
if not env:
|
||||
env = ft_utils.Env()
|
||||
|
||||
client_letter, client_digits = env.get_version_type('client')
|
||||
regex = "[/_.]" + client_letter + "\d+"
|
||||
try:
|
||||
matches = re.findall(regex, string, re.IGNORECASE)
|
||||
return string.split(matches[0])
|
||||
except Exception, e:
|
||||
print e
|
||||
return None
|
||||
|
|
@ -4,6 +4,7 @@ import pyblish.api
|
|||
class CollectActiveProject(pyblish.api.ContextPlugin):
|
||||
"""Inject the active project into context"""
|
||||
|
||||
label = "Collect Active Project"
|
||||
order = pyblish.api.CollectorOrder - 0.2
|
||||
|
||||
def process(self, context):
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import pyblish.api
|
|||
from avalon import api
|
||||
|
||||
|
||||
class CollectHierarchyContext(pyblish.api.ContextPlugin):
|
||||
class CollectHierarchyContext(pyblish.api.InstancePlugin):
|
||||
"""Collecting hierarchy context from `parents` and `hierarchy` data
|
||||
present in `clip` family instances coming from the request json data file
|
||||
|
||||
|
|
@ -13,6 +13,7 @@ class CollectHierarchyContext(pyblish.api.ContextPlugin):
|
|||
|
||||
label = "Collect Hierarchy Context"
|
||||
order = pyblish.api.CollectorOrder + 0.1
|
||||
families = ["clip"]
|
||||
|
||||
def update_dict(self, ex_dict, new_dict):
|
||||
for key in ex_dict:
|
||||
|
|
@ -22,51 +23,85 @@ class CollectHierarchyContext(pyblish.api.ContextPlugin):
|
|||
new_dict[key] = ex_dict[key]
|
||||
return new_dict
|
||||
|
||||
def process(self, context):
|
||||
json_data = context.data.get("jsonData", None)
|
||||
temp_context = {}
|
||||
for instance in json_data['instances']:
|
||||
if instance['family'] in 'projectfile':
|
||||
continue
|
||||
def convert_to_entity(self, key, value):
|
||||
types = {"shot": "Shot",
|
||||
"folder": "Folder",
|
||||
"episode": "Episode",
|
||||
"Sequence": "Sequence",
|
||||
}
|
||||
return {"entity_type": types.get(key, None), "entity_name": value}
|
||||
|
||||
in_info = {}
|
||||
name = instance['name']
|
||||
# suppose that all instances are Shots
|
||||
in_info['entity_type'] = 'Shot'
|
||||
def process(self, instance):
|
||||
context = instance.context
|
||||
tags = instance.data.get("tags", None)
|
||||
self.log.info(tags)
|
||||
if tags:
|
||||
for t in tags:
|
||||
t_metadata = dict(t["metadata"])
|
||||
t_type = t_metadata.get("tag._type", "")
|
||||
if "hierarchy" in t_type:
|
||||
self.log.info("__ type: {}".format(t_type))
|
||||
d_metadata = dict()
|
||||
for k, v in t_metadata.items():
|
||||
new_k = k.split(".")[1]
|
||||
try:
|
||||
d_metadata[new_k] = str(v).format(**context.data)
|
||||
except Exception:
|
||||
d_metadata[new_k] = v
|
||||
|
||||
instance_pyblish = [
|
||||
i for i in context.data["instances"] if i.data['asset'] in name][0]
|
||||
in_info['custom_attributes'] = {
|
||||
'fend': instance_pyblish.data['endFrame'],
|
||||
'fstart': instance_pyblish.data['startFrame'],
|
||||
'fps': instance_pyblish.data['fps']
|
||||
}
|
||||
|
||||
in_info['tasks'] = instance['tasks']
|
||||
self.log.info("__ projectroot: {}".format(context.data["projectroot"]))
|
||||
self.log.info("__ d_metadata: {}".format(d_metadata))
|
||||
self.log.info(
|
||||
"__ hierarchy: {}".format(d_metadata["note"]))
|
||||
# self.log.info("__ hierarchy.format: {}".format(d_metadata["note"].format(
|
||||
# **d_metadata)))
|
||||
|
||||
parents = instance.get('parents', [])
|
||||
|
||||
actual = {name: in_info}
|
||||
|
||||
for parent in reversed(parents):
|
||||
next_dict = {}
|
||||
parent_name = parent["entityName"]
|
||||
next_dict[parent_name] = {}
|
||||
next_dict[parent_name]["entity_type"] = parent["entityType"]
|
||||
next_dict[parent_name]["childs"] = actual
|
||||
actual = next_dict
|
||||
|
||||
temp_context = self.update_dict(temp_context, actual)
|
||||
self.log.debug(temp_context)
|
||||
|
||||
# TODO: 100% sure way of get project! Will be Name or Code?
|
||||
project_name = api.Session["AVALON_PROJECT"]
|
||||
final_context = {}
|
||||
final_context[project_name] = {}
|
||||
final_context[project_name]['entity_type'] = 'Project'
|
||||
final_context[project_name]['childs'] = temp_context
|
||||
|
||||
# adding hierarchy context to instance
|
||||
context.data["hierarchyContext"] = final_context
|
||||
self.log.debug("context.data[hierarchyContext] is: {}".format(
|
||||
context.data["hierarchyContext"]))
|
||||
#
|
||||
# json_data = context.data.get("jsonData", None)
|
||||
# temp_context = {}
|
||||
# for instance in json_data['instances']:
|
||||
# if instance['family'] in 'projectfile':
|
||||
# continue
|
||||
#
|
||||
# in_info = {}
|
||||
# name = instance['name']
|
||||
# # suppose that all instances are Shots
|
||||
# in_info['entity_type'] = 'Shot'
|
||||
#
|
||||
# instance_pyblish = [
|
||||
# i for i in context.data["instances"] if i.data['asset'] in name][0]
|
||||
# in_info['custom_attributes'] = {
|
||||
# 'fend': instance_pyblish.data['endFrame'],
|
||||
# 'fstart': instance_pyblish.data['startFrame'],
|
||||
# 'fps': instance_pyblish.data['fps']
|
||||
# }
|
||||
#
|
||||
# in_info['tasks'] = instance['tasks']
|
||||
#
|
||||
# parents = instance.get('parents', [])
|
||||
#
|
||||
# actual = {name: in_info}
|
||||
#
|
||||
# for parent in reversed(parents):
|
||||
# next_dict = {}
|
||||
# parent_name = parent["entityName"]
|
||||
# next_dict[parent_name] = {}
|
||||
# next_dict[parent_name]["entity_type"] = parent["entityType"]
|
||||
# next_dict[parent_name]["childs"] = actual
|
||||
# actual = next_dict
|
||||
#
|
||||
# temp_context = self.update_dict(temp_context, actual)
|
||||
# self.log.debug(temp_context)
|
||||
#
|
||||
# # TODO: 100% sure way of get project! Will be Name or Code?
|
||||
# project_name = api.Session["AVALON_PROJECT"]
|
||||
# final_context = {}
|
||||
# final_context[project_name] = {}
|
||||
# final_context[project_name]['entity_type'] = 'Project'
|
||||
# final_context[project_name]['childs'] = temp_context
|
||||
#
|
||||
# # adding hierarchy context to instance
|
||||
# context.data["hierarchyContext"] = final_context
|
||||
# self.log.debug("context.data[hierarchyContext] is: {}".format(
|
||||
# context.data["hierarchyContext"]))
|
||||
|
|
|
|||
12
pype/plugins/nukestudio/publish/collect_project_root.py
Normal file
12
pype/plugins/nukestudio/publish/collect_project_root.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import pyblish.api
|
||||
|
||||
|
||||
class CollectActiveProjectRoot(pyblish.api.ContextPlugin):
|
||||
"""Inject the active project into context"""
|
||||
|
||||
label = "Collect Project Root"
|
||||
order = pyblish.api.CollectorOrder - 0.1
|
||||
|
||||
def process(self, context):
|
||||
project = context.data["activeProject"]
|
||||
context.data["projectroot"] = project.projectRoot()
|
||||
|
|
@ -4,7 +4,7 @@ from pyblish import api
|
|||
class CollectClipTags(api.InstancePlugin):
|
||||
"""Collect Tags from selected track items."""
|
||||
|
||||
order = api.CollectorOrder
|
||||
order = api.CollectorOrder + 0.005
|
||||
label = "Collect Tags"
|
||||
hosts = ["nukestudio"]
|
||||
families = ['clip']
|
||||
|
|
|
|||
BIN
setup/nukestudio/hiero_plugin_path/Templates/hierarchy.png
Normal file
BIN
setup/nukestudio/hiero_plugin_path/Templates/hierarchy.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
Loading…
Add table
Add a link
Reference in a new issue