This is probably a silly question, but I'm stuck and need some help so I can move forward in my plugin without using global dialog.
The original dialog has much more checkboxes and edit texts to guide the whole processing, but I've been able to get a very simplified sample of my code with a similar structure.
I have a class
class processing
that needs to retrieve data from the dialog in order to process the script, but I really don't know how to get it since the code below is returning this error:
AttributeError: 'OptionsDialog' object has no attribute 'print_msg1'
I have to keep the structure like it is at the moment.
This the sample, any help would be awesome:
import c4d
pluginVersion = "v1.0.0"
pluginName = "Get Value From Dialog"
PLUGIN_ID = 1111222
class OptionsDialog (c4d.gui.GeDialog):
GROUP_OPTIONS = 1011
CHKBX1 = 1007
CHKBX2 = 1008
CHKBX3 = 1009
BTN_OK = 1010
def __init__(self):
self._hasBeenInitalized = False
self._hasLayoutDone = False
def Message(self, msg, result):
if msg.GetId() == c4d.BFM_ACTION: msg[c4d.BFM_ACTION_VALUE]
return c4d.gui.GeDialog.Message(self, msg, result)
def CreateLayout(self):
self.SetTitle(pluginName + ' ' + pluginVersion)
self.AddCheckbox(self.CHKBX1, c4d.BFH_SCALEFIT, initw=1, inith=1, name='Checkbox 1')
self.AddCheckbox(self.CHKBX2, c4d.BFH_SCALEFIT, initw=1, inith=1, name='Checkbox 2')
self.AddCheckbox(self.CHKBX3, c4d.BFH_SCALEFIT, initw=1, inith=1, name='Checkbox 3')
if self.GroupBegin(self.GROUP_OPTIONS, c4d.BFH_CENTER, 1, 1):
self.AddButton(self.BTN_OK, c4d.BFH_SCALEFIT, initw=500, inith=15,name='Go!')
self.GroupEnd()
self._hasLayoutDone = True
self._hasBeenInitalized = False
return True
def Command(self, id, msg):
if id==self.BTN_OK or id==c4d.IDC_OK:
self.print_msg1 = self.GetBool(self.CHKBX1)
self.print_msg2 = self.GetBool(self.CHKBX2)
self.print_msg3 = self.GetBool(self.CHKBX3)
self.Run()
return True
def InitValues(self):
if self._hasBeenInitalized is True:
return True
self.SetBool(self.CHKBX1, True)
self._hasBeenInitalized = True
return True
def Run(self):
message = processing().set_nice_message()
print(message)
c4d.EventAdd()
return True
class processing:
dlg = OptionsDialog()
def set_nice_message(self):
""" how can I get values from OptionsDialog() ???
"""
if self.dlg.print_msg1: result = 'Hello world 1'
if self.dlg.print_msg2: result = 'Hello world 2'
if self.dlg.print_msg3: result = 'Hello world 3'
return result
class DialogCommandData(c4d.plugins.CommandData):
dlg = None
def Execute(self, doc):
if self.dlg is None:
self.dlg = OptionsDialog()
return self.dlg.Open(dlgtype=c4d.DLG_TYPE_ASYNC,
pluginid=PLUGIN_ID,
xpos=-2, ypos=-2, defaultw=720, defaulth=50)
def RestoreLayout(self, secret):
if self.dlg is None:
self.dlg = OptionsDialog()
return self.dlg.Restore(pluginid=PLUGIN_ID, secret=secret)
if __name__ == '__main__':
myPlugin = DialogCommandData()
c4d.plugins.RegisterCommandPlugin(id=PLUGIN_ID,
str=pluginName,
info=0,
icon=None,
help=pluginName,
dat=myPlugin)