Stupid me. I already asked the same question a year ago here:
https://developers.maxon.net/forum/topic/11472/dialogue-box-manager-through-plug-in-vs-vanilla-script/5
Anyhow, for anyone interested on the working plug-in code. Here it is
import c4d
from c4d import bitmaps, documents, gui, plugins, threading, utils
PLUGIN_ID = 1011323
class MyDialog(gui.GeDialog):
def CreateLayout(self):
#self.SetTitle('Colorizer')
# Prepare a red bitmap for the button.
w = 50
h = 50
bmpRed = c4d.bitmaps.BaseBitmap()
bmpRed.Init(w, h)
for y in xrange(w):
for x in xrange(h):
bmpRed.SetPixel(x, y, 255, 0, 0)
# BitmapButton configuration
bcBitmapButton = c4d.BaseContainer()
bcBitmapButton[c4d.BITMAPBUTTON_BUTTON] = True
# Add a BitmapButton to the dialog.
# _bitmapButton is a member variable of the dialog class
buttonId = 2000
_bitmapButton = self.AddCustomGui(buttonId, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_CENTER|c4d.BFV_CENTER, w, h, bcBitmapButton)
if _bitmapButton is None:
print "Handle this error!"
# Assign the image to the button.
# Note: Let it create an internal copy as the created bitmap will be free'd, when scope is left.
_bitmapButton.SetImage(bmpRed, True)
def Command(self, id, msg):
if id==2000: # corresponds to the button ID used in the code snippet in the first answer in this thread
print "My Bitmap Button"
return True
class MyMenuPlugin(plugins.CommandData):
dialog = None
def Execute(self, doc):
# create the dialog
if self.dialog is None:
self.dialog = MyDialog()
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1)
def RestoreLayout(self, sec_ref):
# manage the dialog
if self.dialog is None:
self.dialog = MyDialog()
return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
if __name__ == "__main__":
okyn = plugins.RegisterCommandPlugin(PLUGIN_ID, "Cubey",0, None, "Cubey initialized", MyMenuPlugin())
if (okyn):
print "Cubey initialized"