switching context will now change content to new asset

This commit is contained in:
Ondřej Samohel 2020-02-26 16:05:33 +01:00
parent 77f58380ee
commit 09ef82cfd2
No known key found for this signature in database
GPG key ID: 8A29C663C672C2B7
2 changed files with 27 additions and 0 deletions

View file

@ -218,3 +218,4 @@ def on_task_changed(*args):
# Run
maya.pipeline._on_task_changed()
lib.update_content_on_context_change()

View file

@ -2452,3 +2452,29 @@ class shelf():
cmds.deleteUI(each)
else:
cmds.shelfLayout(self.name, p="ShelfLayout")
def update_content_on_context_change():
"""
This will update scene content to match new asset on context change
"""
scene_sets = cmds.listSets(allSets=True)
new_asset = api.Session["AVALON_ASSET"]
new_data = lib.get_asset()["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