Skip to content

Commit 4ef6822

Browse files
authored
Merge pull request #12 from ynput/11-show-ayon-context-in-ayon-menu
add AYON context to the AYON menu
2 parents 69d9a16 + a6e4e6c commit 4ef6822

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

client/ayon_cinema4d/api/pipeline.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
import c4d
66
import pyblish.api
77

8+
from ayon_core.lib import (
9+
register_event_callback,
10+
is_headless_mode_enabled
11+
)
812
from ayon_core.host import HostBase, IWorkfileHost, ILoadHost, IPublishHost
913
from ayon_core.pipeline import (
14+
get_current_folder_path,
15+
get_current_task_name,
1016
register_loader_plugin_path,
1117
register_creator_plugin_path,
1218
AYON_CONTAINER_ID,
@@ -55,6 +61,8 @@ def install(self):
5561
# register_inventory_action_path(INVENTORY_PATH)
5662
self.log.info(PUBLISH_PATH)
5763

64+
register_event_callback("taskChanged", on_task_changed)
65+
5866
def open_workfile(self, filepath):
5967
return open_file(filepath)
6068

@@ -263,3 +271,14 @@ def imprint_container(
263271
}
264272

265273
lib.imprint(container, data, group="AYON")
274+
275+
276+
def on_task_changed():
277+
278+
if not is_headless_mode_enabled():
279+
# Get AYON Context menu command plugin (menu item) by its unique id.
280+
ayon_context = c4d.plugins.FindPlugin(1064692)
281+
# Update its value with the new context.
282+
ayon_context.SetName(
283+
"{}, {}".format(get_current_folder_path(), get_current_task_name())
284+
)

client/ayon_cinema4d/startup/ayon_cinema4d.pyp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ if "win" in sys.platform:
3636

3737
import c4d # noqa: E402
3838

39-
from ayon_core.resources import get_resource # noqa: E402
40-
from ayon_core.pipeline import install_host # noqa: E402
39+
from ayon_core.resources import get_resource, get_ayon_icon_filepath # noqa: E402
40+
from ayon_core.pipeline import (
41+
install_host,
42+
get_current_folder_path,
43+
get_current_task_name
44+
)
4145
from ayon_cinema4d.api import Cinema4DHost # noqa: E402
4246
from ayon_cinema4d.api.lib import get_main_window # noqa: E402
4347
from ayon_cinema4d.api.commands import (
@@ -60,6 +64,8 @@ AYON_RESET_RESOLUTION_ID = 1064318
6064
AYON_RESET_COLORSPACE_ID = 1064320
6165
AYON_EXPERIMENTAL_TOOLS_ID = 1064319
6266

67+
AYON_CONTEXT_LABEL_ID = 1064692
68+
6369

6470
def get_icon_by_name(name):
6571
"""Get icon full path"""
@@ -72,6 +78,12 @@ def get_icon_bitmap_by_name(name):
7278
return bitmap
7379

7480

81+
def get_ayon_icon_bitmap():
82+
bitmap = c4d.bitmaps.BaseBitmap()
83+
bitmap.InitWith(get_ayon_icon_filepath())
84+
return bitmap
85+
86+
7587
class Creator(c4d.plugins.CommandData):
7688
id = AYON_CREATE_ID
7789
label = "Create..."
@@ -198,8 +210,14 @@ class ExperimentalTools(c4d.plugins.CommandData):
198210
return True
199211

200212

213+
class ContextLabel(c4d.plugins.CommandData):
214+
id = AYON_CONTEXT_LABEL_ID
215+
label = "{}, {}".format(get_current_folder_path(), get_current_task_name())
216+
icon = get_ayon_icon_bitmap()
217+
218+
201219
def install_menu():
202-
"""Register the OpenPype menu with Cinema4D"""
220+
"""Register the AYON menu with Cinema4D"""
203221
main_menu = c4d.gui.GetMenuResource("M_EDITOR")
204222
plugins_menu = c4d.gui.SearchPluginMenuResource()
205223

@@ -216,6 +234,9 @@ def install_menu():
216234
menuresource_separator = 2
217235

218236
# Define menu commands
237+
238+
add_command(menu, ContextLabel)
239+
menu.InsData(menuresource_separator, True)
219240
add_command(menu, Creator)
220241
add_command(menu, Loader)
221242
add_command(menu, Publish)
@@ -272,6 +293,7 @@ if __name__ == '__main__':
272293
ResetColorspace,
273294
# BuildWorkFileCommand,
274295
ExperimentalTools,
296+
ContextLabel,
275297
]:
276298
c4d.plugins.RegisterCommandPlugin(
277299
id=command_plugin.id,

0 commit comments

Comments
 (0)