diff --git a/client/ayon_cinema4d/api/pipeline.py b/client/ayon_cinema4d/api/pipeline.py index f2bd12b..02968a6 100644 --- a/client/ayon_cinema4d/api/pipeline.py +++ b/client/ayon_cinema4d/api/pipeline.py @@ -5,8 +5,14 @@ import c4d import pyblish.api +from ayon_core.lib import ( + register_event_callback, + is_headless_mode_enabled +) from ayon_core.host import HostBase, IWorkfileHost, ILoadHost, IPublishHost from ayon_core.pipeline import ( + get_current_folder_path, + get_current_task_name, register_loader_plugin_path, register_creator_plugin_path, AYON_CONTAINER_ID, @@ -55,6 +61,8 @@ def install(self): # register_inventory_action_path(INVENTORY_PATH) self.log.info(PUBLISH_PATH) + register_event_callback("taskChanged", on_task_changed) + def open_workfile(self, filepath): return open_file(filepath) @@ -263,3 +271,14 @@ def imprint_container( } lib.imprint(container, data, group="AYON") + + +def on_task_changed(): + + if not is_headless_mode_enabled(): + # Get AYON Context menu command plugin (menu item) by its unique id. + ayon_context = c4d.plugins.FindPlugin(1064692) + # Update its value with the new context. + ayon_context.SetName( + "{}, {}".format(get_current_folder_path(), get_current_task_name()) + ) diff --git a/client/ayon_cinema4d/startup/ayon_cinema4d.pyp b/client/ayon_cinema4d/startup/ayon_cinema4d.pyp index 01db219..8b2aebc 100644 --- a/client/ayon_cinema4d/startup/ayon_cinema4d.pyp +++ b/client/ayon_cinema4d/startup/ayon_cinema4d.pyp @@ -36,8 +36,12 @@ if "win" in sys.platform: import c4d # noqa: E402 -from ayon_core.resources import get_resource # noqa: E402 -from ayon_core.pipeline import install_host # noqa: E402 +from ayon_core.resources import get_resource, get_ayon_icon_filepath # noqa: E402 +from ayon_core.pipeline import ( + install_host, + get_current_folder_path, + get_current_task_name +) from ayon_cinema4d.api import Cinema4DHost # noqa: E402 from ayon_cinema4d.api.lib import get_main_window # noqa: E402 from ayon_cinema4d.api.commands import ( @@ -60,6 +64,8 @@ AYON_RESET_RESOLUTION_ID = 1064318 AYON_RESET_COLORSPACE_ID = 1064320 AYON_EXPERIMENTAL_TOOLS_ID = 1064319 +AYON_CONTEXT_LABEL_ID = 1064692 + def get_icon_by_name(name): """Get icon full path""" @@ -72,6 +78,12 @@ def get_icon_bitmap_by_name(name): return bitmap +def get_ayon_icon_bitmap(): + bitmap = c4d.bitmaps.BaseBitmap() + bitmap.InitWith(get_ayon_icon_filepath()) + return bitmap + + class Creator(c4d.plugins.CommandData): id = AYON_CREATE_ID label = "Create..." @@ -198,8 +210,14 @@ class ExperimentalTools(c4d.plugins.CommandData): return True +class ContextLabel(c4d.plugins.CommandData): + id = AYON_CONTEXT_LABEL_ID + label = "{}, {}".format(get_current_folder_path(), get_current_task_name()) + icon = get_ayon_icon_bitmap() + + def install_menu(): - """Register the OpenPype menu with Cinema4D""" + """Register the AYON menu with Cinema4D""" main_menu = c4d.gui.GetMenuResource("M_EDITOR") plugins_menu = c4d.gui.SearchPluginMenuResource() @@ -216,6 +234,9 @@ def install_menu(): menuresource_separator = 2 # Define menu commands + + add_command(menu, ContextLabel) + menu.InsData(menuresource_separator, True) add_command(menu, Creator) add_command(menu, Loader) add_command(menu, Publish) @@ -272,6 +293,7 @@ if __name__ == '__main__': ResetColorspace, # BuildWorkFileCommand, ExperimentalTools, + ContextLabel, ]: c4d.plugins.RegisterCommandPlugin( id=command_plugin.id,