Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Register
    • Login

    CommandData Plugin with submenu

    PYTHON Development
    0
    7
    1.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 28/08/2018 at 02:32, xxxxxxxx wrote:

      Hi there,

      i'm failing to get a submenu with a commanddata plugin...
      could anybody more experienced maybe have a look at this code?

      best, index

      my folder structure is:
      plugins
      Test
      test.pyp
      icon.png

      what i would like to get in the plugin menu is:
      Plugins
      Test Plugin
      Submenu1
      Submenu2

      but what i get with the following code is just: (no submenu!)
      Plugins
      Test

      import c4d
      from c4d import bitmaps
      import os.path

      PLUGIN_ID = 1234567  # unique ID (obtained from www.plugincafe.com)
      PLUGIN_SHORT = "Test Plugin"

      MENUID_SUB1 = 1000
      MENUID_SUB2 = 1010

      class MenuHandler(c4d.plugins.CommandData) :

      def Register(self) :
      	bmp = bitmaps.BaseBitmap()
      	dir, f = os.path.split(\__file\_\_)
      	fn = os.path.join(dir, "icon.png")
      	bmp.InitWith(fn)
      	return c4d.plugins.RegisterCommandPlugin(
      		id=PLUGIN_ID,
      		str=PLUGIN_SHORT,
      		info=c4d.PLUGINFLAG_COMMAND_HOTKEY,
      		icon=bmp,
      		help="",
      		dat=self
      	)
      
      
      def GetSubContainer(self, doc, submenu) :
      	bc = c4d.BaseContainer()
      	bc.SetString(1, PLUGIN_SHORT)
      	bc.SetString(MENUID_SUB1, "Submenu1")
      	bc.SetString(MENUID_SUB2, "Submenu2")
      	submenu.InsData(0, bc)
      	return True
      
      
      def ExecuteSubID(self, doc, id) :
      	if id == MENUID_SUB1: print "Submenu1"
      	elif id == MENUID_SUB2: print "Submenu2"
      	return True
      
      
      def Execute(self, doc) :
      	return True
      

      if __name__ == "__main__":
      MenuHandler().Register()

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 29/08/2018 at 00:03, xxxxxxxx wrote:

        strange!
        if i add a copy of this source in the same plugin folder 
        then i get two plugin entries, both with the two desired submenus:

        folder structure:
        plugins
        Test
        test1.pyp
        test2.pyp
        icon.png
        now i get:
        Plugins
        Test
        Test1 Plugin
        Submenu1
        Submenu2
        Test2 Plugin
        Submenu1
        Submenu2

        but if i remove one pyp,
        the remaining one does not show the submenus!
        how can i use only one pyp and show a submenu?

        ???

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 30/08/2018 at 01:17, xxxxxxxx wrote:

          no help here? 
          i tried for hours, but still cant create a plugin 
          with a sub menu to execute different actions
          😕

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 30/08/2018 at 03:03, xxxxxxxx wrote:

            Hi,

            Sorry for the late answer.

            There are limitations with GetSubContainer() and the "Plugins" menu.
            If there is only one plugin registered then its menu structure returned by GetSubContainer() is not taken into account. But if the plugin is added to another menu then it is shown as expected.

            So the solution is to register a CommandData plugin with c4d.PLUGINFLAG_HIDEPLUGINMENU flag. Then the plugin can be added to any other menu either manually or with code using the menu functions in c4d.gui module.

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 30/08/2018 at 03:36, xxxxxxxx wrote:

              thanks yannick,

              i actually had that idea this morning, but couldnt make it work

              i added a 2nd pyp to the plugin with c4d.PLUGINFLAG_HIDEPLUGINMENU
              but the main pyp didnt show its submenu then

              are you sure this works?
              (maybe i dont understand correctly)
              it also needs a bogus plugin id, which is a bit odd, right?

              another approach i'm trying is:
              generate a PopupDialog and show it with ShowPopupDialog when the menu is selected (works already)
              but i would also like to be able to have a drag off window with the (main) menu items as buttons
              that could be generated by opt-selecting the menu (any tips on how to create such a window?)

              best index

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 30/08/2018 at 14:58, xxxxxxxx wrote:

                a followup question to the post above:

                ShowPopupDialog() has these flags 
                c4d.POPUP_ALLOWUNDOCK
                c4d.POPUP_ALLOWUNDOCK_REC

                https://developers.maxon.net/docs/py/2023_2/modules/c4d.gui/index.html?highlight=first_popup_id#c4d.gui.ShowPopupDialog

                what are these for?
                i was hoping that you get a drag off handle, 
                but i cant see anything happen if i use these flags

                is there a way to make a PopupDialog sticky?
                or can i create a palette containing my command?

                best index

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 31/08/2018 at 00:22, xxxxxxxx wrote:

                  Your workaround with a popup dialog sounds too hacky to me.

                  The command can be registered with c4d.PLUGINFLAG_HIDEPLUGINMENU flag (plugin won't be shown in "Plugins" menu).
                  Then manually add the command to any other menu/command palette with "Customize Commands" and "Customize Menu". The menu structure returned by the command's GetSubContainer() should be dynamically added as expected.

                  Note it is possible to customize the Cinema menu by code from a plugin.

                  If you have questions related to another subject, please create a new thread.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post