On 05/04/2014 at 10:12, xxxxxxxx wrote:
I'm interested in knowing the answer to this one too.
Since it's much easier to communicate using a working example. Here's a very basic working example showing the problem of not being able to dock a sub dialog:
import c4d,os,sys
from c4d import gui, plugins, bitmaps, documents, utils
PLUGIN_ID = 1000003 #The plugin's ID#
MAINDLG = 1000040 #An ID to be assigned to the main dialog
SUBDLG = 1000041 #An ID to be assigned to the sub dialog
###### The sub dialog ######
class MySubDialog(gui.GeDialog) :
def CreateLayout(self) :
self.SetTitle("Sub Dialog")
self.GroupBegin(0, c4d.BFH_SCALEFIT, 2, 0, "MyGroup")
self.GroupBorderSpace(5, 5, 5, 5)
self.GroupBorder(c4d.BORDER_BLACK)
self.AddStaticText(1111, c4d.BFH_LEFT, 0, 0, "Hello World", 0)
self.AddEditSlider(2222, c4d.BFH_SCALEFIT, 500, 0)
self.GroupEnd()
return True
def InitValues(self) :
self.SetReal(id = 2222, value = 5.0, min = 0.0, max = 100.0, step = 1.0, format = c4d.FORMAT_METER)
return True
def Command(self, id, msg) :
if (id == 2222) :
print self.GetReal(2222) #Print the value of the slider
return True
###### The main dialog ######
class MyMainDialog(gui.GeDialog) :
subdlg = MySubDialog()
def CreateLayout(self) :
self.SetTitle("Main Dialog")
self.AddButton(10001, c4d.BFH_CENTER, 150, 0, "Open SubDlg")
return True
def InitValues(self) :
return True
def Command(self, id, msg) :
if (id == 10001) :
self.subdlg.Open(dlgtype = c4d.DLG_TYPE_ASYNC, pluginid = SUBDLG, defaultw = 200, defaulth = 100)
c4d.EventAdd()
return True
class Dialog_CD(c4d.plugins.CommandData) :
mainDialog = None
subDialog = None
def Init(self, op) :
return True
def Execute(self, doc) :
if self.mainDialog is None and self.subDialog is None:
self.mainDialog = MyMainDialog()
self.subDialog = MySubDialog()
self.mainDialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, -1, -1, 0, 0, MAINDLG)
#self.subDialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, -1, -1, 0, 0, SUBDLG) #For reference only...We don't want to open both dialogs here
return True
##### This does not work!!!! ########
#The function stops after it finds the mainDialog. And only restores that dialog!!!
#The sub dialog results in "plugin not found" in the layout!!!
def RestoreLayout(self, sec_ref) :
subid = sec_ref["subid"]
object = sec_ref["ptr"]
if self.mainDialog is None:
self.mainDialog = MyMainDialog()
print subid
if subid == MAINDLG:
print "subid == MAINDLG"
self.mainDialog.Restore(MAINDLG, sec_ref)
if self.subDialog is None:
self.subDialog = MySubDialog()
print subid
if subid == SUBDLG:
print "subid == SUBDLG"
self.subDialog.Restore(SUBDLG, sec_ref)
return True
if __name__ == "__main__":
bmp = c4d.bitmaps.BaseBitmap()
dir, file = os.path.split(__file__)
fn = os.path.join(dir, "res", "icon.tif")
bmp.InitWith(fn)
result = plugins.RegisterCommandPlugin(PLUGIN_ID, "Dockable SubDialogs", 0, bmp, "Dockable SubDialogs", Dialog_CD())
-ScottA