Solved Adding an Icon to a GeDialog Menu Group

Hello!
Is it possible to add an icon next to a GeDialog Menu Group as in the File > Export menu? I didn't see anything in the Python or C++ documentation. Thank you!

What I have so far...

self.MenuSubBegin("Export...")
self.MenuAddString(ALEMBIC_ID,"Alembic (*.abc)")
self.MenuSubEnd()

573545b6-3c4d-45a8-83af-abe227a567c8-image.png

Hi @blastframe,

I am sorry to inform you, that this is currently not possible. Because the procedures used by Cinema internally cannot be reflected to Python at the moment. We will continue to track this topic internally and inform you here if there are going to be changes and/or we did find an alternative route.

Cheers
Ferdinand

MAXON SDK Specialist
developers.maxon.net

Hi,

unfortunately string menu definitions with an icon are not being recognised by dialogs (unlike in pop up menus). If you want to have a menu item with an icon, you will have to use GeDialog.MenuAddCommand, which will display their icon next to them. Clicking on these will however immediately execute said command. So this:

self.MenuAddCommand(c4d.Ocube)

will add a the string "Cube" to the menu, display the cube object icon next to it and add a cube object to your scene when clicked. If you want anything custom, you will have to implement a dedicated CommandData plugin for it.

Cheers,
Ferdinand

MAXON SDK Specialist
developers.maxon.net

Hello MAXON SDK Specialist :smile: ! Congrats again.

I had tried your suggestion already: creating a dedicated CommandData for my command, but I couldn't get a submenu working with it. Do you know if it's possible to have a submenu for a dedicated CommandData plugin?

Thank you!

Hi,

I hadn't any problems regarding your problem. At least in my understanding of it. Below you will find an example for two CommandData plugins, where one does reference the other in the dialog it displays. Feel free to ask further questions if anything remains unclear ;)

PS: I ran this on R23 and R21 Win. I know from your screenshots that you are on Win (if I am not mixing something up here), but please add OS tags and version tags in the future, as they can be important.

Cheers,
Ferdinand

"""Demonstrates the usage of icons in a dialog menu.
"""
import c4d

# Please use unique plugin IDs obtained from PluginCafe.com.
ID_CMD_ICON = 1053528
ID_CMD_MENU = 1053529

class IconMenueDialog(c4d.gui.GeDialog):
    """The dialog opend by MenuCommandData.

    References IconCommandData in its menu.
    """

    def CreateLayout(self):
        """Creates the menu of the dialog.
        """
        self.MenuFlushAll()
        self.MenuSubBegin("Stuff")
        # You can also pass in some of the node types. Thhis here will
        # act like clicking on the cube object in the menus of Cinema.
        self.MenuAddCommand(c4d.Ocube)
        # Our little CommandData plugin.
        self.MenuAddCommand(ID_CMD_ICON)
        self.MenuSubEnd()
        self.MenuFinished()

        self.AddStaticText(2000, c4d.BFH_CENTER, name="Blah")
        return True

    def InitValues(self):
        """
        """
        return True

    def Command(self, id, msg):
        """
        """
        return True


class IconCommandData(c4d.plugins.CommandData):
    """Just a plugin that acts as command to be executed.
    """

    def Execute(self, doc):
        """Just prints something to the console.
        """
        print("IconCommandData is being executed.")
        return True


class MenuCommandData(c4d.plugins.CommandData):
    """The plugin that opens the menu.
    """

    def __init__(self):
        """
        """
        self._dialog = None

    def Execute(self, doc):
        """Just opens IconMenueDialog.
        """
        if self._dialog is None:
            self._dialog = IconMenueDialog()

        self._dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, 
                          pluginid=ID_CMD_MENU, 
                          xpos=- 1, 
                          ypos=- 1)
        return True

    def RestoreLayout(self, sec_ref):
        """Retores the dialog on layout changes.
        """
        if self._dialog is None:
            self._dialog = IconMenueDialog()

        # Restores the layout
        return self._dialog.Restore(pluginid=ID_CMD_MENU, secret=sec_ref)


def register():
    """Regissters the plugins.
    """
    # A makeshift icon.
    icon = c4d.bitmaps.BaseBitmap()
    icon.Init(32, 32)

    # Registration.

    # The plugin with a icon.
    c4d.plugins.RegisterCommandPlugin(id=ID_CMD_ICON, 
                                      str="IconCommand", 
                                      info=0, 
                                      icon=icon, 
                                      help="The command to call.", 
                                      dat=IconCommandData())
    # The menu command that does not have an icon.
    c4d.plugins.RegisterCommandPlugin(id=ID_CMD_MENU, 
                                      str="MenuCommand", 
                                      info=0, 
                                      icon=None, 
                                      help="Opens the dialog with a menu.", 
                                      dat=MenuCommandData())

if __name__ == "__main__":
    register()

MAXON SDK Specialist
developers.maxon.net

@zipit Hi!

Thank you for the example. This is not what I am seeking unfortunately.

As in the initial post's screenshot, I'm looking to add an icon next to the menu group (where the green star is in this screenshot):
7b092f54-8548-46b8-b293-a9f3dd7853c6-image.png

Is it possible?

Thanks!

Hi,

execute MenuCommand, it will do what you want.

blah.png

Cheers,
Ferdinand

MAXON SDK Specialist
developers.maxon.net

@zipit I think we're not understanding each other. I want to put an icon to the left of a menu command that has a sub menu. Your GeDialog example's menu commands with icons do not have sub menus. If you go to File > Export and look at the disk icon next to Export (which has a sub menu), THAT is what I want to create in a GeDialog. I hope it's clearer.

Thank you!

Hi @blastframe,

sorry for taking so long to answer. I do understand your problem now. You want to display the icon on the sub menu header. I have been working on your problem, but my initial solution did not work. I now had a look on how Cinema does it internally, and will try to do this on Monday in Python (with unfortunately no guarantee that this will be possible) .

Sorry again for the delay, but I had mostly to settle in here at Maxon this week. Have a nice weekend.

Cheers
Ferdinand

MAXON SDK Specialist
developers.maxon.net

Hi @blastframe,

I am sorry to inform you, that this is currently not possible. Because the procedures used by Cinema internally cannot be reflected to Python at the moment. We will continue to track this topic internally and inform you here if there are going to be changes and/or we did find an alternative route.

Cheers
Ferdinand

MAXON SDK Specialist
developers.maxon.net

@zipit Thank you, Ferdinand, for looking into it!