Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
merge and refactor functions to updte asset frame range
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Fricard committed May 24, 2023
1 parent 49401c7 commit 58fb563
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 53 deletions.
91 changes: 39 additions & 52 deletions openpype/hosts/maya/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion openpype/hosts/maya/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 58fb563

Please sign in to comment.