add menu item

This commit is contained in:
karimmozlia 2021-10-22 16:11:40 +02:00
parent 1c72a5ecce
commit dc206f0ce6
2 changed files with 73 additions and 0 deletions

View file

@ -22,6 +22,7 @@ import avalon.maya.lib
import avalon.maya.interactive
from openpype import lib
from openpype.api import get_anatomy_settings
log = logging.getLogger(__name__)
@ -2740,3 +2741,48 @@ def iter_shader_edits(relationships, shader_nodes, nodes_by_id, label=None):
"uuid": data["uuid"],
"nodes": nodes,
"attributes": attr_value}
def set_colorspace():
"""Set Colorspace from project configuration
"""
imageio = get_anatomy_settings(os.getenv("AVALON_PROJECT"))["imageio"]["maya"]
root_dict = imageio["colorManagmentPreference"]
if not isinstance(root_dict, dict):
msg = "set_colorspace(): argument should be dictionary"
log.error(msg)
log.debug(">> root_dict: {}".format(root_dict))
# first enable color management
cmds.colorManagementPrefs(e=True, cmEnabled=True)
cmds.colorManagementPrefs(e=True, ocioRulesEnabled=True)
# second set config path
if root_dict.get("configFilePath"):
unresolved_path = root_dict["configFilePath"]
ocio_paths = unresolved_path[platform.system().lower()]
resolved_path = None
for ocio_p in ocio_paths:
resolved_path = str(ocio_p).format(**os.environ)
if not os.path.exists(resolved_path):
continue
if resolved_path:
cmds.colorManagementPrefs(e=True, configFilePath= str(resolved_path).replace("\\", "/") )
cmds.colorManagementPrefs(e=True, cmConfigFileEnabled=True)
log.debug("maya '{}' changed to: {}".format(
"configFilePath", resolved_path))
root_dict.pop("configFilePath")
# third define rendering space and view transform
renderSpace = root_dict["renderSpace"]
cmds.colorManagementPrefs(e=True, renderingSpaceName=renderSpace)
viewTransform = root_dict["viewTransform"]
cmds.colorManagementPrefs(e=True, viewTransformName=viewTransform)

View file

@ -11,6 +11,7 @@ from avalon.maya import pipeline
from openpype.api import BuildWorkfile
from openpype.settings import get_project_settings
from openpype.tools.utils import host_tools
from openpype.hosts.maya.api import lib
log = logging.getLogger(__name__)
@ -125,6 +126,31 @@ def deferred():
if project_manager_action is not None:
system_menu.menu().removeAction(project_manager_action)
def add_colorspace():
# Find the pipeline menu
top_menu = _get_menu()
# Try to find workfile tool action in the menu
workfile_action = None
for action in top_menu.actions():
if action.text() == "Reset Resolution":
workfile_action = action
break
# Add at the top of menu if "Work Files" action was not found
after_action = ""
if workfile_action:
# Use action's object name for `insertAfter` argument
after_action = workfile_action.objectName()
# Insert action to menu
cmds.menuItem(
"Set Colorspace",
parent=pipeline._menu,
command=lambda *args: lib.set_colorspace(),
insertAfter=after_action
)
log.info("Attempting to install scripts menu ...")
# add_scripts_menu()
@ -132,6 +158,7 @@ def deferred():
add_look_assigner_item()
modify_workfiles()
remove_project_manager()
add_colorspace()
add_scripts_menu()