From 7a875f68c0438f029a1ea27196e20718948ec942 Mon Sep 17 00:00:00 2001 From: Patrick Macdonald <4705216+reformstudios@users.noreply.github.com> Date: Thu, 5 Dec 2019 16:22:07 +0000 Subject: [PATCH 1/3] Added support for Nuke publishing tree serialization When publishing using farm_wrapper and serializing the publish tree in Nuke, the presence of a nuke node (eg the writenode) causes the tree.save method to error. Whilst this may be pointing to another greater bug in the code ( `super(_PublishTreeEncoder).default(data)` errors saying the parent class has no attribute `default`) a workaround is to gracefully handle writenodes before the default return is called. It will probably be necessary to catch other publish types in this code, and if so, perhaps it should be exposed as a hook so studios won't need to fork this code to define how custom items are serialized. This workaround checks that we're in a nuke environment before importing nuke and checking the data is an instance of a nuke.Gizmo. IF it is a gizmo, we serialise the name of the node. --- python/tk_multi_publish2/api/tree.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/python/tk_multi_publish2/api/tree.py b/python/tk_multi_publish2/api/tree.py index 591ef5f1..b22ecd2b 100644 --- a/python/tk_multi_publish2/api/tree.py +++ b/python/tk_multi_publish2/api/tree.py @@ -344,6 +344,16 @@ class _PublishTreeEncoder(json.JSONEncoder): Implements the json encoder interface for custom publish tree serialization. """ def default(self, data): + + is_nuke_session = False + + try: + import nuke + except ImportError: + pass + else: + is_nuke_session = True + if isinstance(data, PublishTree): return data.to_dict() elif isinstance(data, sgtk.Template): @@ -351,10 +361,23 @@ def default(self, data): "_sgtk_custom_type": "sgtk.Template", "name": data.name } + elif sgtk.platform.current_engine() == 'tk-nuke': + import nuke + if isinstance(data, nuke.Gizmo): + return { + "_sgtk_custom_type": "sgtk.tk-nuke-writenode", + "name": data.name() + } else: return super(_PublishTreeEncoder).default(data) - +def get_dcc(): + try: + import nuke + except ImportError: + pass + else: + return 't def _json_to_objects(data): """ Check if an dictionary is actually representing a Toolkit object and From 0f20a07c79811f0a482d872700f6226ffc514a6b Mon Sep 17 00:00:00 2001 From: Patrick Macdonald <4705216+reformstudios@users.noreply.github.com> Date: Thu, 5 Dec 2019 16:26:11 +0000 Subject: [PATCH 2/3] Removed erroneous code. Oops... I forgot to delete some old code. --- python/tk_multi_publish2/api/tree.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/python/tk_multi_publish2/api/tree.py b/python/tk_multi_publish2/api/tree.py index b22ecd2b..6ff57fb6 100644 --- a/python/tk_multi_publish2/api/tree.py +++ b/python/tk_multi_publish2/api/tree.py @@ -345,15 +345,6 @@ class _PublishTreeEncoder(json.JSONEncoder): """ def default(self, data): - is_nuke_session = False - - try: - import nuke - except ImportError: - pass - else: - is_nuke_session = True - if isinstance(data, PublishTree): return data.to_dict() elif isinstance(data, sgtk.Template): From 0e769018dcde2c8f51ba868e8e4bffabe2a119e5 Mon Sep 17 00:00:00 2001 From: Patrick Macdonald <4705216+reformstudios@users.noreply.github.com> Date: Thu, 5 Dec 2019 16:27:36 +0000 Subject: [PATCH 3/3] And another removal of old code... --- python/tk_multi_publish2/api/tree.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/python/tk_multi_publish2/api/tree.py b/python/tk_multi_publish2/api/tree.py index 6ff57fb6..a218d56b 100644 --- a/python/tk_multi_publish2/api/tree.py +++ b/python/tk_multi_publish2/api/tree.py @@ -362,13 +362,7 @@ def default(self, data): else: return super(_PublishTreeEncoder).default(data) -def get_dcc(): - try: - import nuke - except ImportError: - pass - else: - return 't + def _json_to_objects(data): """ Check if an dictionary is actually representing a Toolkit object and