From 92f5046b357509b8b6f286e7314f0c39b12a8bca Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 27 Jun 2023 20:23:23 +0200 Subject: [PATCH 01/16] commit 7c2bb2d Author: Thomas Fricard Date: Mon May 15 17:12:13 2023 +0200 cosmetic refactoring commit 6fcb0a6 Author: Thomas Fricard Date: Mon May 15 16:55:19 2023 +0200 check id attribute before family attribute commit df6cc8c Author: Thomas Fricard Date: Fri May 12 16:01:52 2023 +0200 verify that 'family' attributes exists and equals to 'render' commit 5ae1847 Author: Thomas Fricard Date: Fri May 12 15:58:05 2023 +0200 change function name + docstrings commit ff09bbb Author: Thomas Fricard Date: Fri May 12 11:48:43 2023 +0200 add a 'type' key to the 'include handles' setting of maya commit ec96832 Author: Thomas Fricard Date: Wed May 3 15:32:06 2023 +0200 merge and refactor functions to updte asset frame range commit 661f494 Author: Thomas Fricard Date: Tue Apr 18 10:03:24 2023 +0200 add 'instances' to reset_frame_range function arguments and make sure it does not update frame range instances on creating render settings commit a10ecfc Merge: 19836b3 196f698 Author: Thomas Fricard Date: Tue Apr 18 09:32:32 2023 +0200 Merge branch '346-fix-studio-openpype-udpate-frame-range-of-scene-doesn-t-update-frame-range-in-animation-instance' of github.com:quadproduction/OpenPype into 346-fix-studio-openpype-udpate-frame-range-of-scene-doesn-t-update-frame-range-in-animation-instance commit 19836b3 Author: Thomas Fricard Date: Tue Apr 18 09:31:27 2023 +0200 change key and label to make the setting more understandable commit 196f698 Merge: 155a0c2 515c0ac Author: Thomas Fricard <51854004+friquette@users.noreply.github.com> Date: Thu Apr 13 11:06:26 2023 +0200 Merge branch 'develop' into 346-fix-studio-openpype-udpate-frame-range-of-scene-doesn-t-update-frame-range-in-animation-instance commit 155a0c2 Author: Thomas Fricard Date: Thu Apr 13 10:57:53 2023 +0200 resolve conflicts commit 6a6c9e0 Author: Thomas Fricard Date: Wed Apr 12 14:07:19 2023 +0200 check if update instances is enabled in settings commit 9211c4a Author: Thomas Fricard Date: Wed Apr 12 13:58:40 2023 +0200 add a setting in maya project settings to enable updating animation instances commit fde0b50 Author: Thomas Fricard Date: Tue Apr 11 16:58:37 2023 +0200 check if attribute exsits before modifying it commit 38eed31 Author: Thomas Fricard Date: Wed Apr 5 15:26:04 2023 +0200 update animation instance frames attribute on reset frame range commit dc47ca9 Author: Thomas Fricard Date: Fri Mar 31 15:56:19 2023 +0200 get instances and set frameStart attribute commit 0932341 Author: Thomas Fricard Date: Wed May 17 12:47:17 2023 +0200 call reset_frame_range function for instances after importing commit 4de8e6e Author: Thomas Fricard Date: Mon May 15 17:12:13 2023 +0200 cosmetic refactoring commit efe2dbb Author: Thomas Fricard Date: Mon May 15 16:55:19 2023 +0200 check id attribute before family attribute commit 2379c5c Author: Thomas Fricard Date: Fri May 12 16:01:52 2023 +0200 verify that 'family' attributes exists and equals to 'render' commit 3a57274 Author: Thomas Fricard Date: Fri May 12 15:58:05 2023 +0200 change function name + docstrings commit 7f68109 Author: Thomas Fricard Date: Fri May 12 11:48:43 2023 +0200 add a 'type' key to the 'include handles' setting of maya commit 58fb563 Author: Thomas Fricard Date: Wed May 3 15:32:06 2023 +0200 merge and refactor functions to updte asset frame range commit 49401c7 Author: Thomas Fricard Date: Tue Apr 18 10:03:24 2023 +0200 add 'instances' to reset_frame_range function arguments and make sure it does not update frame range instances on creating render settings commit 8c0c60d Author: Thomas Fricard Date: Tue Apr 18 09:31:27 2023 +0200 change key and label to make the setting more understandable commit bdcdab2 Author: Thomas Fricard Date: Thu Apr 13 10:57:53 2023 +0200 resolve conflicts commit 9040302 Author: Thomas Fricard Date: Wed Apr 12 14:07:19 2023 +0200 check if update instances is enabled in settings commit cd884e8 Author: Thomas Fricard Date: Wed Apr 12 13:58:40 2023 +0200 add a setting in maya project settings to enable updating animation instances commit 981c0b1 Author: Thomas Fricard Date: Tue Apr 11 16:58:37 2023 +0200 check if attribute exsits before modifying it commit 1755ce4 Author: Thomas Fricard Date: Wed Apr 5 15:26:04 2023 +0200 update animation instance frames attribute on reset frame range commit fdf6f43 Author: Thomas Fricard Date: Fri Mar 31 15:56:19 2023 +0200 get instances and set frameStart attribute --- openpype/hosts/maya/api/lib.py | 77 +++++++++++++------ openpype/hosts/maya/api/lib_rendersettings.py | 7 +- openpype/hosts/maya/api/pipeline.py | 2 +- .../maya/api/workfile_template_builder.py | 3 +- .../defaults/project_settings/maya.json | 3 + .../projects_schema/schema_project_maya.json | 18 +++++ 6 files changed, 83 insertions(+), 27 deletions(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index 83bb73c23fc..93178fa2228 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -2261,7 +2261,7 @@ def get_frame_range(include_animation_range=False): return frame_range -def reset_frame_range(playback=True, render=True, fps=True): +def reset_frame_range(playback=True, render=True, fps=True, instances=True): """Set frame range to current asset Args: @@ -2270,6 +2270,8 @@ def reset_frame_range(playback=True, render=True, fps=True): render (bool, Optional): Whether to set the maya render frame range. Defaults to True. fps (bool, Optional): Whether to set scene FPS. Defaults to True. + instances (bool, Optional): Whether to update publishable instances. + Defaults to True. """ if fps: fps = convert_to_maya_fps( @@ -2300,6 +2302,12 @@ def reset_frame_range(playback=True, render=True, fps=True): cmds.setAttr("defaultRenderGlobals.startFrame", animation_start) cmds.setAttr("defaultRenderGlobals.endFrame", animation_end) + if instances: + project_name = get_current_project_name() + settings = get_project_settings(project_name) + if settings["maya"]["update_publishable_frame_range"]["enabled"]: + update_instances_frame_range() + def reset_scene_resolution(): """Apply the scene resolution from the project definition @@ -3129,31 +3137,52 @@ def remove_render_layer_observer(): pass -def update_content_on_context_change(): - """ - This will update scene content to match new asset on context change +def update_instances_frame_range(): + """Update 'frameStart', 'frameEnd', 'handleStart', 'handleEnd' and 'asset' + attributes of sets that got one, execpt if instance family is 'render' """ - scene_sets = cmds.listSets(allSets=True) + collected_instances = cmds.ls( + "*.id", + long=True, + type="objectSet", + recursive=True, + objectsOnly=True + ) asset_doc = get_current_project_asset() - new_asset = asset_doc["name"] - new_data = asset_doc["data"] - for s in scene_sets: - try: - if cmds.getAttr("{}.id".format(s)) == "pyblish.avalon.instance": - attr = cmds.listAttr(s) - print(s) - if "asset" in attr: - print(" - setting asset to: [ {} ]".format(new_asset)) - cmds.setAttr("{}.asset".format(s), - new_asset, type="string") - if "frameStart" in attr: - cmds.setAttr("{}.frameStart".format(s), - new_data["frameStart"]) - if "frameEnd" in attr: - cmds.setAttr("{}.frameEnd".format(s), - new_data["frameEnd"],) - except ValueError: - pass + + asset_data = asset_doc["data"] + frames_attributes = { + 'frameStart': asset_data["frameStart"], + 'frameEnd': asset_data["frameEnd"], + 'handleStart': asset_data["handleStart"], + 'handleEnd': asset_data["handleEnd"], + 'asset': asset_doc['name'] + } + + for instance in collected_instances: + id_attr = "{}.id".format(instance) + if cmds.getAttr(id_attr) != "pyblish.avalon.instance": + continue + + if ( + cmds.attributeQuery('family', node=instance, exists=True) and + cmds.getAttr("{}.family".format(instance)) == "render" + ): + continue + + for key, value in frames_attributes.items(): + if cmds.attributeQuery(key, node=instance, exists=True): + if key == 'asset': + cmds.setAttr( + "{}.{}".format(instance, key), + value, + type="string" + ) + else: + cmds.setAttr( + "{}.{}".format(instance, key), + value + ) def show_message(title, msg): diff --git a/openpype/hosts/maya/api/lib_rendersettings.py b/openpype/hosts/maya/api/lib_rendersettings.py index eaa728a2f68..4deffcc46bf 100644 --- a/openpype/hosts/maya/api/lib_rendersettings.py +++ b/openpype/hosts/maya/api/lib_rendersettings.py @@ -158,7 +158,12 @@ def _set_arnold_settings(self, width, height): cmds.setAttr( "defaultArnoldDriver.mergeAOVs", multi_exr) self._additional_attribs_setter(additional_options) - reset_frame_range(playback=False, fps=False, render=True) + reset_frame_range( + playback=False, + fps=False, + render=True, + instances=False + ) def _set_redshift_settings(self, width, height): """Sets settings for Redshift.""" diff --git a/openpype/hosts/maya/api/pipeline.py b/openpype/hosts/maya/api/pipeline.py index 5323717fa72..9232a0651f5 100644 --- a/openpype/hosts/maya/api/pipeline.py +++ b/openpype/hosts/maya/api/pipeline.py @@ -653,7 +653,7 @@ def on_task_changed(): with lib.suspended_refresh(): lib.set_context_settings() - lib.update_content_on_context_change() + lib.update_instances_frame_range() msg = " project: {}\n asset: {}\n task:{}".format( legacy_io.active_project(), diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index b7e731bbb67..690fdc32cc2 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -14,7 +14,7 @@ WorkfileBuildPlaceholderDialog, ) -from .lib import read, imprint, get_main_window +from .lib import read, imprint, reset_frame_range, get_main_window PLACEHOLDER_SET = "PLACEHOLDERS_SET" @@ -251,6 +251,7 @@ def cleanup_placeholder(self, placeholder, failed): cmds.sets(node, addElement=PLACEHOLDER_SET) cmds.hide(node) cmds.setAttr(node + ".hiddenInOutliner", True) + reset_frame_range(playback=False, render=False, fps=False) def load_succeed(self, placeholder, container): self._parent_in_hierarchy(placeholder, container) diff --git a/openpype/settings/defaults/project_settings/maya.json b/openpype/settings/defaults/project_settings/maya.json index 19c3da13e6c..e3b5c25a1f1 100644 --- a/openpype/settings/defaults/project_settings/maya.json +++ b/openpype/settings/defaults/project_settings/maya.json @@ -457,6 +457,9 @@ "include_handles_default": false, "per_task_type": [] }, + "update_publishable_frame_range": { + "enabled": true + }, "scriptsmenu": { "name": "OpenPype Tools", "definition": [ diff --git a/openpype/settings/entities/schemas/projects_schema/schema_project_maya.json b/openpype/settings/entities/schemas/projects_schema/schema_project_maya.json index dca955dab43..b6804533216 100644 --- a/openpype/settings/entities/schemas/projects_schema/schema_project_maya.json +++ b/openpype/settings/entities/schemas/projects_schema/schema_project_maya.json @@ -197,6 +197,24 @@ } ] }, + { + "type": "dict", + "collapsible": true, + "key": "update_publishable_frame_range", + "label": "Update publishable instances on Reset Frame Range", + "checkbox_key": "enabled", + "children": [ + { + "type": "label", + "label": "If enabled, the frame range and the handles of all the publishable instances will be updated when using the 'Reset Frame Range' functionality" + }, + { + "type": "boolean", + "key": "enabled", + "label": "Enabled" + } + ] + }, { "type": "dict", "key": "include_handles", From 002f2c860a2e08f12cb30e1f2cf506bbd340c704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hector?= Date: Wed, 28 Jun 2023 16:36:05 +0200 Subject: [PATCH 02/16] Update openpype/hosts/maya/api/lib.py Co-authored-by: Roy Nieterau --- openpype/hosts/maya/api/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index 93178fa2228..4fe95723212 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -3139,7 +3139,7 @@ def remove_render_layer_observer(): def update_instances_frame_range(): """Update 'frameStart', 'frameEnd', 'handleStart', 'handleEnd' and 'asset' - attributes of sets that got one, execpt if instance family is 'render' + attributes of sets that got one, except if instance family is 'render' """ collected_instances = cmds.ls( "*.id", From 062cf52f64b50fd7d7be55d69c80bf3d026f9574 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Wed, 28 Jun 2023 16:42:10 +0200 Subject: [PATCH 03/16] remove rendre check --- openpype/hosts/maya/api/lib.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index 4fe95723212..412cf4f5532 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -3164,12 +3164,6 @@ def update_instances_frame_range(): if cmds.getAttr(id_attr) != "pyblish.avalon.instance": continue - if ( - cmds.attributeQuery('family', node=instance, exists=True) and - cmds.getAttr("{}.family".format(instance)) == "render" - ): - continue - for key, value in frames_attributes.items(): if cmds.attributeQuery(key, node=instance, exists=True): if key == 'asset': From 921eb4fcfc24512e47f2f7e680b71e4b677697dd Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Wed, 28 Jun 2023 17:00:52 +0200 Subject: [PATCH 04/16] add reset_frame_range instance=true --- openpype/hosts/maya/api/workfile_template_builder.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index 690fdc32cc2..8a23ebb032e 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -251,7 +251,12 @@ def cleanup_placeholder(self, placeholder, failed): cmds.sets(node, addElement=PLACEHOLDER_SET) cmds.hide(node) cmds.setAttr(node + ".hiddenInOutliner", True) - reset_frame_range(playback=False, render=False, fps=False) + reset_frame_range( + playback=False, + render=False, + fps=False, + instances=True + ) def load_succeed(self, placeholder, container): self._parent_in_hierarchy(placeholder, container) From de4bad20c222168baff8a34cdd48cc953398897a Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Wed, 28 Jun 2023 22:14:39 +0200 Subject: [PATCH 05/16] Change reset_frame_range default to false --- openpype/hosts/maya/api/lib.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index 412cf4f5532..e25f14c7de4 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -2261,7 +2261,7 @@ def get_frame_range(include_animation_range=False): return frame_range -def reset_frame_range(playback=True, render=True, fps=True, instances=True): +def reset_frame_range(playback=True, render=True, fps=True, instances=False): """Set frame range to current asset Args: @@ -2302,11 +2302,10 @@ def reset_frame_range(playback=True, render=True, fps=True, instances=True): cmds.setAttr("defaultRenderGlobals.startFrame", animation_start) cmds.setAttr("defaultRenderGlobals.endFrame", animation_end) - if instances: - project_name = get_current_project_name() - settings = get_project_settings(project_name) - if settings["maya"]["update_publishable_frame_range"]["enabled"]: - update_instances_frame_range() + project_name = get_current_project_name() + settings = get_project_settings(project_name) + if instances or settings["maya"]["update_publishable_frame_range"]["enabled"]: + update_instances_frame_range() def reset_scene_resolution(): From 435deedd488a7122cf0708908e8b5b7f33eac28a Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Wed, 28 Jun 2023 22:16:03 +0200 Subject: [PATCH 06/16] cosmetic fix --- openpype/hosts/maya/api/lib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index e25f14c7de4..280d4140322 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -2304,7 +2304,8 @@ def reset_frame_range(playback=True, render=True, fps=True, instances=False): project_name = get_current_project_name() settings = get_project_settings(project_name) - if instances or settings["maya"]["update_publishable_frame_range"]["enabled"]: + if instances or settings["maya"]["update_publishable_frame_range"][ + "enabled"]: update_instances_frame_range() From 6296fc52d956cfe83500b6d9e17468ea546ca403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hector?= Date: Mon, 3 Jul 2023 11:43:16 +0200 Subject: [PATCH 07/16] Update openpype/hosts/maya/api/lib.py Co-authored-by: Roy Nieterau --- openpype/hosts/maya/api/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index 280d4140322..f095fb0c71a 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -3139,7 +3139,7 @@ def remove_render_layer_observer(): def update_instances_frame_range(): """Update 'frameStart', 'frameEnd', 'handleStart', 'handleEnd' and 'asset' - attributes of sets that got one, except if instance family is 'render' + attributes of publishable instances (their objectSets) that got one. """ collected_instances = cmds.ls( "*.id", From 95b5fff890360b0e8d414b2e66b1810a383595bd Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Mon, 3 Jul 2023 11:49:58 +0200 Subject: [PATCH 08/16] update instance frame range --- openpype/hosts/maya/api/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index f095fb0c71a..caf6f7e48a7 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -2261,7 +2261,7 @@ def get_frame_range(include_animation_range=False): return frame_range -def reset_frame_range(playback=True, render=True, fps=True, instances=False): +def reset_frame_range(playback=True, render=True, fps=True, instances=True): """Set frame range to current asset Args: From 079abd03b896bcd702d96c3427b35e1169f537ef Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Mon, 3 Jul 2023 11:54:37 +0200 Subject: [PATCH 09/16] update instance frame range --- openpype/hosts/maya/api/workfile_template_builder.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index 8a23ebb032e..95dc281861a 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -14,7 +14,7 @@ WorkfileBuildPlaceholderDialog, ) -from .lib import read, imprint, reset_frame_range, get_main_window +from .lib import read, imprint, update_instances_frame_range, get_main_window PLACEHOLDER_SET = "PLACEHOLDERS_SET" @@ -251,12 +251,7 @@ def cleanup_placeholder(self, placeholder, failed): cmds.sets(node, addElement=PLACEHOLDER_SET) cmds.hide(node) cmds.setAttr(node + ".hiddenInOutliner", True) - reset_frame_range( - playback=False, - render=False, - fps=False, - instances=True - ) + update_instances_frame_range() def load_succeed(self, placeholder, container): self._parent_in_hierarchy(placeholder, container) From 399bbec6214c77c2684a456c7be17f44698558ab Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Mon, 3 Jul 2023 12:01:55 +0200 Subject: [PATCH 10/16] revert update instance option --- openpype/hosts/maya/api/lib.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index caf6f7e48a7..b4911af495a 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -2302,11 +2302,11 @@ def reset_frame_range(playback=True, render=True, fps=True, instances=True): cmds.setAttr("defaultRenderGlobals.startFrame", animation_start) cmds.setAttr("defaultRenderGlobals.endFrame", animation_end) - project_name = get_current_project_name() - settings = get_project_settings(project_name) - if instances or settings["maya"]["update_publishable_frame_range"][ - "enabled"]: - update_instances_frame_range() + if instances: + project_name = get_current_project_name() + settings = get_project_settings(project_name) + if settings["maya"]["update_publishable_frame_range"]["enabled"]: + update_instances_frame_range() def reset_scene_resolution(): From 8c4e0b7fa1351079a8626f717e697dadec15c06c Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Mon, 3 Jul 2023 15:39:52 +0200 Subject: [PATCH 11/16] extract asset update from framerange --- openpype/hosts/maya/api/lib.py | 59 +++++++++++-------- .../maya/api/workfile_template_builder.py | 9 ++- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index b4911af495a..13850b96255 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -3137,9 +3137,8 @@ def remove_render_layer_observer(): pass -def update_instances_frame_range(): - """Update 'frameStart', 'frameEnd', 'handleStart', 'handleEnd' and 'asset' - attributes of publishable instances (their objectSets) that got one. +def set_attribute_instances(attribute, value): + """Set attribute value of publishable instances (their objectSets) """ collected_instances = cmds.ls( "*.id", @@ -3148,35 +3147,43 @@ def update_instances_frame_range(): recursive=True, objectsOnly=True ) - asset_doc = get_current_project_asset() - - asset_data = asset_doc["data"] - frames_attributes = { - 'frameStart': asset_data["frameStart"], - 'frameEnd': asset_data["frameEnd"], - 'handleStart': asset_data["handleStart"], - 'handleEnd': asset_data["handleEnd"], - 'asset': asset_doc['name'] - } for instance in collected_instances: id_attr = "{}.id".format(instance) if cmds.getAttr(id_attr) != "pyblish.avalon.instance": continue - for key, value in frames_attributes.items(): - if cmds.attributeQuery(key, node=instance, exists=True): - if key == 'asset': - cmds.setAttr( - "{}.{}".format(instance, key), - value, - type="string" - ) - else: - cmds.setAttr( - "{}.{}".format(instance, key), - value - ) + if not cmds.attributeQuery(attribute, node=instance, exists=True): + continue + + attr = "{}.{}".format(instance, attribute) + + if cmds.getAttr(attr, type=True) == "string": + cmds.setAttr(attr, value, type="string") + else: + cmds.setAttr(attr, value) + + +def update_instances_asset_attribute(): + """Update 'asset' attribute of publishable instances (their objectSets) + that got one. + """ + + set_attribute_instances("asset", get_current_project_asset()['name']) + + +def update_instances_frame_range(): + """Update 'frameStart', 'frameEnd', 'handleStart', 'handleEnd' and 'fps' + attributes of publishable instances (their objectSets) that got one. + """ + asset_doc = get_current_project_asset() + asset_data = asset_doc["data"] + + set_attribute_instances("frameStart", asset_data["frameStart"]) + set_attribute_instances("frameEnd", asset_data["frameEnd"]) + set_attribute_instances("handleStart", asset_data["handleStart"]) + set_attribute_instances("handleEnd", asset_data["handleEnd"]) + set_attribute_instances("fps", asset_data['fps']) def show_message(title, msg): diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index 95dc281861a..598987ea551 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -14,7 +14,13 @@ WorkfileBuildPlaceholderDialog, ) -from .lib import read, imprint, update_instances_frame_range, get_main_window +from .lib import ( + read, + imprint, + get_main_window, + update_instances_frame_range, + update_instances_asset_attribute, +) PLACEHOLDER_SET = "PLACEHOLDERS_SET" @@ -252,6 +258,7 @@ def cleanup_placeholder(self, placeholder, failed): cmds.hide(node) cmds.setAttr(node + ".hiddenInOutliner", True) update_instances_frame_range() + update_instances_asset_attribute() def load_succeed(self, placeholder, container): self._parent_in_hierarchy(placeholder, container) From 248a8f616d7fe1a962e416d9d7032aa58d7e81fd Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 4 Jul 2023 11:04:46 +0200 Subject: [PATCH 12/16] iter over instance --- openpype/hosts/maya/api/lib.py | 60 ++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index 13850b96255..74d879a25f2 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -3137,31 +3137,19 @@ def remove_render_layer_observer(): pass -def set_attribute_instances(attribute, value): - """Set attribute value of publishable instances (their objectSets) +def iter_publish_instances(): + """Iterate over publishable instances (their objectSets). """ - collected_instances = cmds.ls( + for node in cmds.ls( "*.id", long=True, type="objectSet", recursive=True, objectsOnly=True - ) - - for instance in collected_instances: - id_attr = "{}.id".format(instance) - if cmds.getAttr(id_attr) != "pyblish.avalon.instance": - continue - - if not cmds.attributeQuery(attribute, node=instance, exists=True): + ): + if cmds.getAttr("{}.id".format(node)) != "pyblish.avalon.instance": continue - - attr = "{}.{}".format(instance, attribute) - - if cmds.getAttr(attr, type=True) == "string": - cmds.setAttr(attr, value, type="string") - else: - cmds.setAttr(attr, value) + yield node def update_instances_asset_attribute(): @@ -3169,21 +3157,43 @@ def update_instances_asset_attribute(): that got one. """ - set_attribute_instances("asset", get_current_project_asset()['name']) + for instance in iter_publish_instances(): + if not cmds.attributeQuery("asset", node=instance, exists=True): + continue + attr = "{}.asset".format(instance) + cmds.setAttr(attr, get_current_project_asset()['name'], type="string") def update_instances_frame_range(): """Update 'frameStart', 'frameEnd', 'handleStart', 'handleEnd' and 'fps' attributes of publishable instances (their objectSets) that got one. """ - asset_doc = get_current_project_asset() + + attributes = ["frameStart", "frameEnd", "handleStart", "handleEnd", "fps"] + + attrs_per_instance = {} + for instance in iter_publish_instances(): + instance_attrs = [ + attr for attr in attributes + if cmds.attributeQuery(attr, node=instance, exists=True) + ] + + if instance_attrs : + attrs_per_instance [instance] = instance_attrs + + if not attrs_per_instance: + # no instances with any frame related attributes + return + + fields = ["data.{}".format(key) for key in attributes] + asset_doc = get_current_project_asset(fields=fields) asset_data = asset_doc["data"] - set_attribute_instances("frameStart", asset_data["frameStart"]) - set_attribute_instances("frameEnd", asset_data["frameEnd"]) - set_attribute_instances("handleStart", asset_data["handleStart"]) - set_attribute_instances("handleEnd", asset_data["handleEnd"]) - set_attribute_instances("fps", asset_data['fps']) + for node, attrs in attrs_per_instance.items(): + for attr in attrs: + plug = "{}.{}".format(node, attr) + value = asset_data[attr] + cmds.setAttr(plug, value) def show_message(title, msg): From 359bc654a7cb43eb108e69e0cf3072491ec2f57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hector?= Date: Tue, 4 Jul 2023 15:53:15 +0200 Subject: [PATCH 13/16] Update openpype/hosts/maya/api/lib.py Co-authored-by: Roy Nieterau --- openpype/hosts/maya/api/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index 74d879a25f2..d3b69bef8de 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -3178,7 +3178,7 @@ def update_instances_frame_range(): if cmds.attributeQuery(attr, node=instance, exists=True) ] - if instance_attrs : + if instance_attrs: attrs_per_instance [instance] = instance_attrs if not attrs_per_instance: From 0ec7f993bdbd2201f2815cd38297a672ae7f6068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hector?= Date: Tue, 4 Jul 2023 15:53:46 +0200 Subject: [PATCH 14/16] Update openpype/hosts/maya/api/lib.py Co-authored-by: Roy Nieterau --- openpype/hosts/maya/api/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index d3b69bef8de..c3baa1f92da 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -3179,7 +3179,7 @@ def update_instances_frame_range(): ] if instance_attrs: - attrs_per_instance [instance] = instance_attrs + attrs_per_instance[instance] = instance_attrs if not attrs_per_instance: # no instances with any frame related attributes From d96495e8d3ee25a1bdb007e45c4fd3dc062e892a Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Tue, 4 Jul 2023 17:43:36 +0200 Subject: [PATCH 15/16] add update instances asset name --- openpype/hosts/maya/api/lib.py | 4 ++-- openpype/hosts/maya/api/pipeline.py | 1 + openpype/hosts/maya/api/workfile_template_builder.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index c3baa1f92da..86bd5196ab9 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -3152,7 +3152,7 @@ def iter_publish_instances(): yield node -def update_instances_asset_attribute(): +def update_instances_asset_name(): """Update 'asset' attribute of publishable instances (their objectSets) that got one. """ @@ -3161,7 +3161,7 @@ def update_instances_asset_attribute(): if not cmds.attributeQuery("asset", node=instance, exists=True): continue attr = "{}.asset".format(instance) - cmds.setAttr(attr, get_current_project_asset()['name'], type="string") + cmds.setAttr(attr, get_current_asset_name(), type="string") def update_instances_frame_range(): diff --git a/openpype/hosts/maya/api/pipeline.py b/openpype/hosts/maya/api/pipeline.py index 9232a0651f5..0f93f78ea79 100644 --- a/openpype/hosts/maya/api/pipeline.py +++ b/openpype/hosts/maya/api/pipeline.py @@ -654,6 +654,7 @@ def on_task_changed(): with lib.suspended_refresh(): lib.set_context_settings() lib.update_instances_frame_range() + lib.update_instances_asset_name() msg = " project: {}\n asset: {}\n task:{}".format( legacy_io.active_project(), diff --git a/openpype/hosts/maya/api/workfile_template_builder.py b/openpype/hosts/maya/api/workfile_template_builder.py index 598987ea551..f5e6da26b43 100644 --- a/openpype/hosts/maya/api/workfile_template_builder.py +++ b/openpype/hosts/maya/api/workfile_template_builder.py @@ -19,7 +19,7 @@ imprint, get_main_window, update_instances_frame_range, - update_instances_asset_attribute, + update_instances_asset_name, ) PLACEHOLDER_SET = "PLACEHOLDERS_SET" @@ -258,7 +258,7 @@ def cleanup_placeholder(self, placeholder, failed): cmds.hide(node) cmds.setAttr(node + ".hiddenInOutliner", True) update_instances_frame_range() - update_instances_asset_attribute() + update_instances_asset_name() def load_succeed(self, placeholder, container): self._parent_in_hierarchy(placeholder, container) From 2bf64a40105a0823bd70cf362afb3b1a22324c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hector?= Date: Thu, 6 Jul 2023 16:46:06 +0200 Subject: [PATCH 16/16] Update openpype/hosts/maya/api/lib.py Co-authored-by: Roy Nieterau --- openpype/hosts/maya/api/lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index 2353a59af92..56f7a17c4a9 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -3158,12 +3158,12 @@ def update_instances_asset_name(): """Update 'asset' attribute of publishable instances (their objectSets) that got one. """ - + asset_name = get_current_asset_name() for instance in iter_publish_instances(): if not cmds.attributeQuery("asset", node=instance, exists=True): continue attr = "{}.asset".format(instance) - cmds.setAttr(attr, get_current_asset_name(), type="string") + cmds.setAttr(attr, asset_name, type="string") def update_instances_frame_range():