CommandData Plugin with submenu
On 28/08/2018 at 02:32, xxxxxxxx wrote:
i'm failing to get a submenu with a commanddata plugin...
could anybody more experienced maybe have a look at this code?
my folder structure is:
what i would like to get in the plugin menu is:
but what i get with the following code is just: (no submenu!)
from c4d import bitmaps
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__":
On 29/08/2018 at 00:03, xxxxxxxx wrote:
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:
now i get:
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?
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
On 30/08/2018 at 03:03, xxxxxxxx wrote:
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.
On 30/08/2018 at 03:36, xxxxxxxx wrote:
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?)
On 30/08/2018 at 14:58, xxxxxxxx wrote:
a followup question to the post above:
ShowPopupDialog() has these flags
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?
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.