On 20/02/2017 at 14:47, xxxxxxxx wrote:
Hi there,
i m trying here to get some kind of modular plugin
meaning i have one plugin folder with multiple pyp files
which all add their items to the same menu.
here is the code for the first pyp:
_# FILE plugins/test/test1.pyp
import c4d
from c4d import bitmaps
import os.path
import sys
PLUGIN_ID = 1234500+1
PLUGIN_NAME = 'Test Menu 1'
class MenuHandler(c4d.plugins.CommandData) :
def Register(self) :
bmp = bitmaps.BaseBitmap()
dir, f = os.path.split(__file__)
fn = os.path.join(dir, "res", "icon.png")
bmp.InitWith(fn)
return c4d.plugins.RegisterCommandPlugin(
id = PLUGIN_ID,
str = PLUGIN_NAME,
info = c4d.PLUGINFLAG_COMMAND_HOTKEY,
icon = bmp,
help = PLUGIN_NAME,
dat = MenuHandler())
def GetSubContainer(self, doc, submenu) :
'''Build submenu.'''
bc = c4d.BaseContainer()
bc.SetString(1, PLUGIN_NAME)
bc.SetString(1001, 'My Item 1')
bc.SetString(1002, 'My Item 2')
bc.SetString(1003, 'My Item 3')
submenu.InsData(0, bc)
return True
def ExecuteSubID(self, doc, id) :
return True
def Init(self, op) :
return True
def Execute(self, doc) :
return True
if __name__ == '__main__':
MenuHandler().Register()
_
now, if you add some more pyp files by
duplicating the file and changing the PLUGIN_ID / NAME ...
_# FILE plugins/test/test2.pyp
PLUGIN_ID = 1234500+2
PLUGIN_NAME = 'Test Menu 2'
_
you get a menu item "test" under plugins (the name is the plugin folders name)
having subitems (one item per pyp file)
with sub-sub items (My Item 1 to 3)
but... you dont get the drag-off handler for menu items that the standard menus have.
(i mean that you can drag off the menu, and have it in a small floating window)
i noted that when you return false in GetSubContainer()
then you get the drag-off handler, but then you dont get the sub-sub items.
is there a way to enable this handler somehow ?
preferably for both levels ?
at Test Menu 1/2/3 and also at each My Item 1/2/3 ?
i uploaded the example here :
http://www61.zippyshare.com/v/1N5gNr1Y/file.html
otherwise its not understandable i guess.