CommandData and Gedialog

On 08/12/2015 at 18:54, xxxxxxxx wrote:

Hello guys,

just a stupid but id-like-to-know question. I have a CommandData with GeDialog for user input. Usually I do stuff in GeDialog->Command->if id == BUTTON_OK. But Im not sure if it is the recommended way. So, where do I have to do stuff?

class MyDialog(gui.GeDialog) :  
  
  refs = None  
  
  def CreateLayout(self) :  
      self.SetTitle('Commandtest')  
      self.GroupBegin(10001, c4d.BFH_LEFT, 1, 1)  
      self.AddEditNumberArrows(10004, c4d.BFH_LEFT, initw=150, inith=0)  
      self.AddButton(10002, c4d.BFH_LEFT, name='OK')  
      self.AddButton(10003, c4d.BFH_LEFT, name='Cancel')  
      self.GroupEnd()  
      return True  
  
  def InitValues(self) :  
      return True  
  
  def Command(self, id, msg) :  
      if id==10003: self.Close()  
      elif id==10002: pass  
      return True  
  
    
class CommandTest(plugins.CommandData) :  
  
  dialog = None  
  
  def Execute(self, doc) :  
      if self.dialog is None: self.dialog = MyDialog()  
      return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=300, defaulth=0)  
  
  def RestoreLayout(self, sec_ref) :  
      if self.dialog is None: self.dialog = MyDialog()  
      return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)  
  
  
if __name__ == "__main__":  
   bmp = bitmaps.BaseBitmap()  
   dir, f = os.path.split(__file__)  
   fn = os.path.join(dir, "", "icon.tif")  
   bmp.InitWith(fn)  
   plugins.RegisterCommandPlugin(id=PLUGIN_ID,   
                                str="CommandTest",  
                                info=0,  
                                help="CommandTest",   
                                dat=CommandTest(),  
                                icon=bmp)

Thx and greetings
rownn

On 09/12/2015 at 01:26, xxxxxxxx wrote:

Hello,

depending on the stuff it is perfectly fine to do stuff in GeDialog.Command(). See for example the RSS reader plugin. If you just want to add a "OK" and "Cancel" button you could simply add a dialog group with AddDlgGroup().

Best wishes,
Sebastian

On 09/12/2015 at 05:22, xxxxxxxx wrote:

Hello Sebastian,

sorry, my misstake. Of course, it depends on the stuff. In case of Py-MemoryViewer it makes totally sense not to lieve gui.GeUserArea to do the stuff. But Id like to change objects in the active scene after calling button. Relating to this I like the following structur of a script with GeDialog.

import c4d  
from c4d import gui  
#Welcome to the world of Python  
  
class OptionsDialog(gui.GeDialog) :  
  def CreateLayout(self) :  
      self.GroupBegin(1000, c4d.BFH_LEFT, 2, 1)  
      self.AddButton(1001, c4d.BFH_SCALE, name='OK')  
      self.AddButton(1002, c4d.BFH_SCALE, name='Cancel')  
      self.GroupEnd()  
      self.ok = False  
      return True  
  
  def InitValues(self) :  
      return True  
   
  def Command(self, id, msg) :  
      if id==1002:  
          self.Close()  
      elif id==1001:  
          self.ok = True  
          self.variable = "Hallo World!"  
          self.Close()  
      return True  
  
  
def main() :  
  dlg = OptionsDialog()  
  dlg.Open(c4d.DLG_TYPE_MODAL, defaultw=100, defaulth=50)  
  if not dlg.ok: return  
    
  print dlg.variable  
    
    
   
if __name__=='__main__':  
  main()  

In this structur GeDialog is just responsible for getting user input and passing to main(). In my case I also would like to use the MessageMethod of the CommandData, but Im really not sure where to put in the stuff.

Thx alot and greetings
rownn

On 10/12/2015 at 00:45, xxxxxxxx wrote:

Hello,

I'm not quite sure what your question is. In your first example you use a CommandData plugin, in your second example a Script Manager script. How are these examples related to each other and your question? Why would you like to use the CommandData.Message function? Maybe it would be useful to stop talking about "stuff" and to tell us what you really want to do ;)

best wishes,
Sebastian