Hello,
I am trying to send messages from a SubDialog to a parent GeDialog. I am using a variation of this example implementation from NiklasR.
import c4d
PLUGIN_ID = 1000004 # Test ID
ACTION_ID = 123456
class MainDialog(c4d.gui.GeDialog):
@property
def sub_dialog(self):
if not hasattr(self, '_sub_dialog'):
self._sub_dialog = SubDialog()
return self._sub_dialog
def CreateLayout(self):
self.SetTitle('Main Dialog')
self.AddButton(1000, 0, name="Open Sub-Dialog")
return True
def Message(self, msg, result):
if msg.GetId() == ACTION_ID:
print msg
return c4d.gui.GeDialog.Message(self, msg, result)
def Command(self, param, bc):
print bc
if param == 1000:
self.sub_dialog.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=1)
return True
def Restore(self, pluginid, secref):
if secref['subid'] == 1:
return self.sub_dialog.Restore(pluginid, secref)
else:
return super(MainDialog, self).Restore(pluginid, secref)
class SubDialog(c4d.gui.GeDialog):
def CreateLayout(self):
self.SetTitle('Sub-Dialog')
self.AddButton(1000, 0, name="Send Message")
return True
def Command(self, id, msg):
if id == 1001:
bc = c4d.BaseContainer()
bc.SetId(c4d.BFM_ACTION)
bc.SetInt32(c4d.BFM_ACTION_ID, ACTION_ID)
self.SendParentMessage(bc)
return True
class Command(c4d.plugins.CommandData):
def Register(self):
return c4d.plugins.RegisterCommandPlugin(
PLUGIN_ID, "Sub-Dialog Message", 0, None, "", self)
@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__':
Command().Register()
I've tried using SendParentMessage but, for whatever reason, my parent dialog isn't receiving the message.
In my parent GeDialog I've tried using the Command and Message methods, but neither receives the message from the SubDialog.
Can anyone help? Thank you!