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

Maya: Update frame range of instances when clicking on "Reset frame range" #4793

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4bb3da3
get instances and set frameStart attribute
Mar 31, 2023
7c46ed1
update animation instance frames attribute on reset frame range
Apr 5, 2023
68e3d1d
check if attribute exsits before modifying it
Apr 11, 2023
618a459
add a setting in maya project settings to enable updating animation i…
Apr 12, 2023
de0b46d
check if update instances is enabled in settings
Apr 12, 2023
ce90cb7
resolve conflicts
Apr 13, 2023
7e7a2af
change key and label to make the setting more understandable
Apr 18, 2023
d522ba8
add 'instances' to reset_frame_range function arguments and make sure…
Apr 18, 2023
bd84409
merge and refactor functions to updte asset frame range
May 3, 2023
3c2075d
add a 'type' key to the 'include handles' setting of maya
May 12, 2023
ee81e26
change function name + docstrings
May 12, 2023
19568bd
verify that 'family' attributes exists and equals to 'render'
May 12, 2023
50f1b5f
check id attribute before family attribute
May 15, 2023
acb83a3
cosmetic refactoring
May 15, 2023
5ae9c3e
rename variables
May 25, 2023
32d19b8
remove playbackOptions command from get_frame_range function
May 25, 2023
7284d39
fix linting error
May 25, 2023
43a41b1
add functions that were accidently removed
May 25, 2023
9544354
fix wrong rebase
May 25, 2023
731ab9f
get instances and set frameStart attribute
Mar 31, 2023
c03d3ab
update animation instance frames attribute on reset frame range
Apr 5, 2023
fb51b22
check if attribute exsits before modifying it
Apr 11, 2023
b6168c1
add a setting in maya project settings to enable updating animation i…
Apr 12, 2023
0fbe939
check if update instances is enabled in settings
Apr 12, 2023
a10dba4
resolve conflicts
Apr 13, 2023
15c672c
change key and label to make the setting more understandable
Apr 18, 2023
d1ea654
add 'instances' to reset_frame_range function arguments and make sure…
Apr 18, 2023
ebd3aba
merge and refactor functions to updte asset frame range
May 3, 2023
73a0c61
add a 'type' key to the 'include handles' setting of maya
May 12, 2023
34c2dc5
change function name + docstrings
May 12, 2023
1d80551
verify that 'family' attributes exists and equals to 'render'
May 12, 2023
8f3dc4c
check id attribute before family attribute
May 15, 2023
5200490
cosmetic refactoring
May 15, 2023
0aa63ac
rename variables
May 25, 2023
7dcb1c8
remove playbackOptions command from get_frame_range function
May 25, 2023
23ae58e
fix linting error
May 25, 2023
7a40def
add functions that were accidently removed
May 25, 2023
5834a0f
fix wrong rebase
May 25, 2023
77d6ff9
Merge branch 'develop' into 346-fix-studio-openpype-udpate-frame-rang…
friquette Jun 9, 2023
a83ee51
update docstring for reset_frame_range
friquette Jun 26, 2023
3e4cdb4
fix linting error
friquette Jun 26, 2023
7ea522f
Merge branch 'develop' into 346-fix-studio-openpype-udpate-frame-rang…
friquette Jun 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 57 additions & 27 deletions openpype/hosts/maya/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)
from openpype.pipeline.create import (
legacy_create,
get_legacy_creator_by_name,
get_legacy_creator_by_name
)
from openpype.pipeline.context_tools import (
get_current_asset_name,
Expand Down Expand Up @@ -2205,10 +2205,8 @@ def get_frame_range(include_animation_range=False):
include_animation_range (bool, optional): Whether to include
`animationStart` and `animationEnd` keys to define the outer
range of the timeline. It is excluded by default.

Returns:
dict: Asset's expected frame range values.

"""

# Set frame start/end
Expand All @@ -2232,6 +2230,7 @@ def get_frame_range(include_animation_range=False):
"handleStart": handle_start,
"handleEnd": handle_end
}

if include_animation_range:
# The animation range values are only included to define whether
# the Maya time slider should include the handles or not.
Expand Down Expand Up @@ -2261,7 +2260,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:
Expand All @@ -2270,6 +2269,10 @@ 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. Even when True this will only reset instances if
`update_publishable_frame_range` is also enabled
in project settings.
"""
if fps:
fps = convert_to_maya_fps(
Expand Down Expand Up @@ -2300,6 +2303,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
Expand Down Expand Up @@ -3129,31 +3138,52 @@ def remove_render_layer_observer():
pass


def update_content_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'
"""
This will update scene content to match new asset on context change
"""
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
tokejepsen marked this conversation as resolved.
Show resolved Hide resolved

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):
Expand Down
7 changes: 6 additions & 1 deletion openpype/hosts/maya/api/lib_rendersettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
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_instances_frame_range()

msg = " project: {}\n asset: {}\n task:{}".format(
legacy_io.active_project(),
Expand Down
3 changes: 3 additions & 0 deletions openpype/settings/defaults/project_settings/maya.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@
"destination-path": []
}
},
"update_publishable_frame_range": {
"enabled": false
},
"include_handles": {
"include_handles_default": false,
"per_task_type": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down