Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AYON context to the AYON menu #12

Merged
merged 11 commits into from
Dec 9, 2024
19 changes: 19 additions & 0 deletions client/ayon_cinema4d/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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(1064309)
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
# Update its value with the new context.
ayon_context.SetName(
"{}, {}".format(get_current_folder_path(), get_current_task_name())
)
28 changes: 25 additions & 3 deletions client/ayon_cinema4d/startup/ayon_cinema4d.pyp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -60,6 +64,8 @@ AYON_RESET_RESOLUTION_ID = 1064318
AYON_RESET_COLORSPACE_ID = 1064320
AYON_EXPERIMENTAL_TOOLS_ID = 1064319

AYON_CONTEXT_LABEL = 1064309
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you base this number on @MustafaJafar - is this officially registered with Maxon?

Copy link
Contributor Author

@MustafaJafar MustafaJafar Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't know.

I assume these are unique numbers to register the plugins/commands. I picked the smallest number - 1 in the pyp file.

BigRoy marked this conversation as resolved.
Show resolved Hide resolved


def get_icon_by_name(name):
"""Get icon full path"""
Expand All @@ -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..."
Expand Down Expand Up @@ -198,8 +210,14 @@ class ExperimentalTools(c4d.plugins.CommandData):
return True


class ContextLabel(c4d.plugins.CommandData):
id = AYON_CONTEXT_LABEL
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
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()

Expand All @@ -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)
Expand Down Expand Up @@ -272,6 +293,7 @@ if __name__ == '__main__':
ResetColorspace,
# BuildWorkFileCommand,
ExperimentalTools,
ContextLabel,
]:
c4d.plugins.RegisterCommandPlugin(
id=command_plugin.id,
Expand Down
Loading