Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
On 21/12/2016 at 04:54, xxxxxxxx wrote:
Hi, guys! I made some experiments trying to find a way to open a subdialogs with parameters. But when i press the first button parameter is sending only once, and then with other button, it is used again. Is there a solution of the issue?
There is my code based on NiclasR example:
import c4d PLUGIN_ID = 1000004 # Test ID class MainDialog(c4d.gui.GeDialog) : # Do not create the object on class-level, although it might # be unimportant since you do not open multiple objects of your # MainDialog, it is contradicting to have one instance of sub # dialog for all instances of the main dialog. # A property that creates the dialog on-demand is perfect for # this purpose. # data = 'Testtt' # @property def sub_dialog(self,name) : if not hasattr(self, '_sub_dialog') : self._sub_dialog = SubDialog(name) return self._sub_dialog # c4d.gui.GeDialog def CreateLayout(self) : self.SetTitle('Main Dialog') self.AddButton(1000, 0, name="Open Sub-Dialog") self.AddButton(1001, 0, name="Open Sub-Dialog 2") return True def Command(self, param, bc) : if param == 1000: self.sub_dialog('First param').Open(c4d.DLG_TYPE_MODAL, PLUGIN_ID, subid=1) if param == 1001: # self.data = self.sub_dialog('Sec param').Open(c4d.DLG_TYPE_MODAL, PLUGIN_ID, subid=1) return True def Restore(self, pluginid, secref) : # We override this method so we don't have to handle the sub- # dialog from the CommandData plugin. THIS dialog is responsible # for the sub-dialog, do not split such management throughout # your program or it gets confusing. if secref['subid'] == 1: return self.sub_dialog('').Restore(pluginid, secref) else: return super(MainDialog, self).Restore(pluginid, secref) # if secref['subid'] == 2: # return self.sub_dialog('Udin').Restore(pluginid, secref) # else: # return super(MainDialog, self).Restore(pluginid, secref) class SubDialog(c4d.gui.GeDialog) : def __init__(self,name) : self.name = name def CreateLayout(self) : self.SetTitle('Sub-Dialog') # md = MainDialog() self.AddStaticText(1000, 0, name=self.name) return True class Command(c4d.plugins.CommandData) : def Register(self) : return c4d.plugins.RegisterCommandPlugin( PLUGIN_ID, "Sub-Dialog Docking Test", 0, None, "", self) @property def dialog(self) : if not hasattr(self, '_dialog') : self._dialog = MainDialog() return self._dialog # c4d.plugins.CommandData 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()
G M T
|
Звуковая функция ограничена 100 символами
On 21/12/2016 at 08:48, xxxxxxxx wrote:
Give this one a try Mike. It's a little bit more organized than your code. So hopefully it's easier to follow what's going on in it
#This is an example of a GeDialog plugin that opens another dialog using properties #It also allows both dialogs to be docked and saved in a custom layout import c4d PLUGIN_ID = 1000004 # Test ID class MainDialog(c4d.gui.GeDialog) : #Create 2 properties for each sub dialog #A property can create the sub dialogs on-demand as if they were class objects @property def sub_dialog1(self) : if not hasattr(self, '_sub_dialog1') : self._sub_dialog1 = SubDialog1() return self._sub_dialog1 @property def sub_dialog2(self) : if not hasattr(self, '_sub_dialog2') : self._sub_dialog2 = SubDialog2() return self._sub_dialog2 ############### GeDialog section ################### def CreateLayout(self) : self.SetTitle('Main Dialog') self.AddButton(1000, 0, name="Open Sub-Dialog 1") self.AddButton(1001, 0, name="Open Sub-Dialog 2") return True def Command(self, param, bc) : if param == 1000: self.sub_dialog1.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=1) if param == 1001: self.sub_dialog2.Open(c4d.DLG_TYPE_ASYNC, PLUGIN_ID, subid=2) return True def Restore(self, pluginid, secref) : #Set the pointers to the specific sub dialog here rather than in the CommandData section of this plugin if secref['subid'] == 1: return self.sub_dialog1.Restore(pluginid, secref) if secref['subid'] == 2: return self.sub_dialog2.Restore(pluginid, secref) else: return super(MainDialog, self).Restore(pluginid, secref) ############### Sub Dialogs section ###################### class SubDialog1(c4d.gui.GeDialog) : def CreateLayout(self) : self.SetTitle('Sub-Dialog') self.AddStaticText(1000, 0, name="This is sub-dialog #1") return True class SubDialog2(c4d.gui.GeDialog) : def CreateLayout(self) : self.SetTitle('Sub-Dialog2') self.AddStaticText(1001, 0, name="This is sub-dialog #2") return True ################# CommandData section ####################### class Command(c4d.plugins.CommandData) : def Register(self) : return c4d.plugins.RegisterCommandPlugin(PLUGIN_ID, "Sub-Dialog Docking Test", 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()
-ScottA
On 21/12/2016 at 10:26, xxxxxxxx wrote:
Thanks for the reply, Scott! The fact is that I do not know how many subdialogs user may need. Buttons will be added by the loop. G M T
And I need to get a dialogs with different details.