diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index b3216340c68..0cdd61901e0 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -2277,39 +2277,10 @@ def reset_frame_range(playback=True, render=True, fps=True, instances=True): cmds.setAttr("defaultRenderGlobals.endFrame", frame_end) if instances: - # Update animation instances attributes if enabled in settings project_name = get_current_project_name() settings = get_project_settings(project_name) if settings["maya"]["update_publishable_frame_range"]["enabled"]: - collected_instances = cmds.ls( - "*.id", - long=True, - type="objectSet", - recursive=True, - objectsOnly=True - ) - frames_attributes = { - 'frameStart': frame_start, - 'frameEnd': frame_end, - 'handleStart': frame_range["handleStart"], - 'handleEnd': frame_range["handleEnd"] - } - - for instance in collected_instances: - family_attr = "{}.family".format(instance) - if family_attr == "render": - continue - - 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): - cmds.setAttr( - "{}.{}".format(instance, key), - value - ) + update_assets_frame_range() def reset_scene_resolution(): @@ -3140,32 +3111,48 @@ def remove_render_layer_observer(): pass -def update_content_on_context_change(): - """ - This will update scene content to match new asset on context change - """ - scene_sets = cmds.listSets(allSets=True) +def update_assets_frame_range(): + 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 + frames_attributes = { + 'frameStart': new_data["frameStart"], + 'frameEnd': new_data["frameEnd"], + 'handleStart': new_data["handleStart"], + 'handleEnd': new_data["handleEnd"], + 'asset': new_asset + } + + for instance in collected_instances: + family_attr = "{}.family".format(instance) + if family_attr == "render": + continue + + 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 + ) def show_message(title, msg): from qtpy import QtWidgets diff --git a/openpype/hosts/maya/api/pipeline.py b/openpype/hosts/maya/api/pipeline.py index 5323717fa72..f1ee6f485c6 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_assets_frame_range() msg = " project: {}\n asset: {}\n task:{}".format( legacy_io.active_project(),