#This is an example of a GeDialog plugin that opens three dialogs #It also allows all three dialogs to be docked and saved in a custom layout
import c4d, os from c4d import gui, plugins, bitmaps
PLUGIN_ID = 1000004 #Testing ID SUBDLG_ID1 = 1000005 #Testing ID SUBDLG_ID2 = 1000006 #Testing ID
MAINDLG_BUTTON1_ID = 1000 MAINDLG_BUTTON2_ID = 1001 MAINDLG_BUTTON3_ID = 1002 SUBDLG_TEXT_ID = 1003 SUBDLG_CHKBOX_ID = 1004 SUBDLG_RESET_ID = 1005
############################ #The first sub dialog class SubDialog1(c4d.gui.GeDialog):
def CreateLayout(self): self.SetTitle('Sub-Dialog1') self.GroupBeginInMenuLine() self.AddCheckbox(SUBDLG_RESET_ID, c4d.BFH_RIGHT, 100, 20, name="Reset") self.GroupEnd() self.GroupBegin(0, c4d.BFH_SCALEFIT, 2, 0, "MyGroup") self.GroupBorderSpace(5, 5, 5, 5) self.GroupBorder(c4d.BORDER_BLACK) self.AddStaticText(SUBDLG_TEXT_ID, c4d.BFH_LEFT, 200, 20, "This is the sub-dialog1") self.AddCheckbox(SUBDLG_CHKBOX_ID, c4d.BFH_LEFT, 20, 20, "myChkbox") self.GroupEnd() return True def Command(self, id, msg): if id == SUBDLG_RESET_ID: self.SetBool(SUBDLG_CHKBOX_ID, False) self.SetBool(SUBDLG_RESET_ID, False) return True ############################ #The second sub dialog class SubDialog2(c4d.gui.GeDialog):
def CreateLayout(self): self.SetTitle('Sub-Dialog2') self.GroupBeginInMenuLine() self.AddCheckbox(SUBDLG_RESET_ID, c4d.BFH_RIGHT, 100, 20, name="Reset") self.GroupEnd() self.GroupBegin(0, c4d.BFH_SCALEFIT, 2, 0, "MyGroup") self.GroupBorderSpace(5, 5, 5, 5) self.GroupBorder(c4d.BORDER_BLACK) self.AddStaticText(SUBDLG_TEXT_ID, c4d.BFH_LEFT, 200, 20, "This is the sub-dialog2") self.AddCheckbox(SUBDLG_CHKBOX_ID, c4d.BFH_LEFT, 20, 20, "myChkbox") self.GroupEnd() return True def Command(self, id, msg): if id == SUBDLG_RESET_ID: self.SetBool(SUBDLG_CHKBOX_ID, False) self.SetBool(SUBDLG_RESET_ID, False) return True
############################ #The main dialog class MainDialog(c4d.gui.GeDialog):
sub_dialog1 = SubDialog1() sub_dialog2 = SubDialog2()
def CreateLayout(self): self.SetTitle('Main Dialog') self.AddButton(MAINDLG_BUTTON1_ID, 0, name="Open Sub-Dialog1") self.AddButton(MAINDLG_BUTTON2_ID, 0, name="Open Sub-Dialog2") self.AddButton(MAINDLG_BUTTON3_ID, 0, name="Change Sub-Dialog1") return True
def Command(self, id, msg): if id == MAINDLG_BUTTON1_ID: self.sub_dialog1.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=SUBDLG_ID1) if id == MAINDLG_BUTTON2_ID: self.sub_dialog2.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=SUBDLG_ID2) if id == MAINDLG_BUTTON3_ID: self.sub_dialog1.SetBool(SUBDLG_CHKBOX_ID, True) return True #Restore the subdialog and the main dialog in the layout def Restore(self, pluginid, secref): if secref['subid'] == SUBDLG_ID1: return self.sub_dialog1.Restore(pluginid, secref) if secref['subid'] == SUBDLG_ID2: return self.sub_dialog2.Restore(pluginid, secref) else: return super(MainDialog, self).Restore(pluginid, secref) ############################ #The Command Data section class MainDialog_CD(c4d.plugins.CommandData):
@property def dialog(self): if not hasattr(self, '_dialog'): self._dialog = MainDialog() return self._dialog
def Execute(self, doc): return self.dialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID)
def RestoreLayout(self, secref): return self.dialog.Restore(PLUGIN_ID, secref)
if __name__ == "__main__":
bmp = bitmaps.BaseBitmap() dir, file = os.path.split(__file__) fn = os.path.join(dir, "res", "icon.png") bmp.InitWith(fn) plugins.RegisterCommandPlugin(PLUGIN_ID, "Sub-Dialog Docking",0, bmp, "re-open", MainDialog_CD()) |