@stereo_stan
As Ferdinand already said, you forgot to add the AddButton call, or rather (as I can see my line self.AddButton(ID_BUTTON3, c4d.BFH_SCALEFIT, name="Jump into code")
in the script), you inserted it in the wrong place (it's now inside a comment section, where it doesn't do anything, and also in the wrong method.
Additionally, I need to tell you that you must define ID_BUTTON3
somewhere, or it will raise an error. And the snippet if ID == ID_BUTTON3:
will not work since the parameter ID
that I used is actually called messageId
in your command
method. Oops, and you duplicated the whole command
method so now you have two of them and Python will only consider the latter and ignore the first.
Okay, I guess Maxon hates me for self promoting here, but this is not so much an API question now but a matter of plain Python understanding, so you may perhaps consider my Python/C4D API course under
https://www.patreon.com/cairyn
In section 10 I have multiple examples for dialog setup with layout, buttons, command method, text fields, radio buttons, separators, columns, etc.; too much to replicate here.
I have corrected the script for you a final time, removing all the comments and reducing the sample to the most necessary stuff:
import c4d
from c4d import gui
PLUGIN_ID = 1057171
ID_BUTTON3 = 1001
class ExampleDialog(c4d.gui.GeDialog):
def CreateLayout(self):
self.SetTitle("This is an example Dialog")
self.AddButton(ID_BUTTON3, c4d.BFH_SCALEFIT, name="Jump into code")
self.AddDlgGroup(c4d.DLG_OK | c4d.DLG_CANCEL)
return True
def Command(self, messageId, bc):
if messageId == c4d.DLG_OK:
print("User Click on yep")
return True
elif messageId == ID_BUTTON3:
print ("Button clicked")
return True
elif messageId == c4d.DLG_CANCEL:
print("User Click on Cancel")
self.Close()
return True
return True
class ExampleDialogCommand(c4d.plugins.CommandData):
dialog = None
def Execute(self, doc):
if self.dialog is None:
self.dialog = ExampleDialog()
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=400, defaulth=32)
def RestoreLayout(self, sec_ref):
if self.dialog is None:
self.dialog = ExampleDialog()
return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
if __name__ == "__main__":
c4d.plugins.RegisterCommandPlugin(id=PLUGIN_ID,
str="Py-CommandData Dialog",
info=0,
help="Display a basic GUI",
dat=ExampleDialogCommand(),
icon=None)
