feat(nuke): adding callback to nuke for change color of Loader nodes regarding to last version

This commit is contained in:
Jakub Jezek 2019-05-15 21:45:52 +02:00
parent 61618dd5fc
commit 0c5f876137
3 changed files with 60 additions and 3 deletions

View file

@ -29,6 +29,53 @@ def onScriptLoad():
nuke.tcl('load movWriter')
def checkInventoryVersions():
"""
Actiual version idetifier of Loaded containers
Any time this function is run it will check all nodes and filter only Loader nodes for its version. It will get all versions from database
and check if the node is having actual version. If not then it will color it to red.
"""
# get all Loader nodes by avalon attribute metadata
for each in nuke.allNodes():
if each.Class() == 'Read':
container = avalon.nuke.parse_container(each)
if container:
node = container["_tool"]
avalon_knob_data = get_avalon_knob_data(node)
# get representation from io
representation = io.find_one({
"type": "representation",
"_id": io.ObjectId(avalon_knob_data["representation"])
})
# Get start frame from version data
version = io.find_one({
"type": "version",
"_id": representation["parent"]
})
# get all versions in list
versions = io.find({
"type": "version",
"parent": version["parent"]
}).distinct('name')
max_version = max(versions)
# check the available version and do match
# change color of node if not max verion
if version.get("name") not in [max_version]:
node["tile_color"].setValue(int("0xd84f20ff", 16))
else:
node["tile_color"].setValue(int("0x4ecd25ff", 16))
def writes_version_sync():
try:
rootVersion = pype.get_version_from_path(nuke.root().name())

View file

@ -128,11 +128,15 @@ class LoadSequence(api.Loader):
# add additional metadata from the version to imprint to Avalon knob
add_keys = ["startFrame", "endFrame", "handles",
"source", "colorspace", "author", "fps"]
"source", "colorspace", "author", "fps", "version"]
data_imprint = {}
for k in add_keys:
data_imprint.update({k: context["version"]['data'][k]})
if k is 'version':
data_imprint.update({k: context["version"]['name']})
else:
data_imprint.update({k: context["version"]['data'][k]})
data_imprint.update({"objectName": read_name})
r["tile_color"].setValue(int("0x4ecd25ff", 16))

View file

@ -1,5 +1,10 @@
from pype.nuke.lib import writes_version_sync, onScriptLoad
from pype.nuke.lib import (
writes_version_sync,
onScriptLoad,
checkInventoryVersions
)
import nuke
from pypeapp import Logger
@ -8,5 +13,6 @@ log = Logger().get_logger(__name__, "nuke")
nuke.addOnScriptSave(writes_version_sync)
nuke.addOnScriptSave(onScriptLoad)
nuke.addOnScriptSave(checkInventoryVersions)
log.info('Automatic syncing of write file knob to script version')