GeDialog in a Python Script: error without exception set?
-
Hello again,
Thanks to Maxime's reply, I am one step further with my dialog in a script.
This works now:
def CreateLayout(self): self.SetTitle("The dialog of my dreams") self.AddDlgGroup(c4d.DLG_OK|c4d.DLG_CANCEL) return True
But if I try to add any gadgets myself, like this:
def CreateLayout(self): self.SetTitle("The dialog of my dreams") self.AddButton(id=1001, flags=c4d.BFH_SCALE|c4d.BFV_SCALE, 100, 25, "A button!") self.AddDlgGroup(c4d.DLG_OK|c4d.DLG_CANCEL) return True
I get an error in the Python console, pointing to the
Addbutton()
line:
SystemError: error return without exception setWhy? And how do I avoid it?
Thanks again in advance!
Cheers,
FrankPS: Yes, I do know that dialogs in scripts are not recommended
-
Additional info:
Funny, I can sneak around that error by simply catching and ignoring it:
def CreateLayout(self): self.SetTitle("The dialog of my dreams") try: self.AddButton(id=1001, flags=c4d.BFH_SCALE|c4d.BFV_SCALE, 100, 25, "A button!") except: pass self.AddDlgGroup(c4d.DLG_OK|c4d.DLG_CANCEL) return True
that way, the dialog seems to work as expected. Even the button appears and seems to work.
But it makes me shake of fear and disgust, so I'd like to actually fix it. -
Hi Frank, I would like to point you to How To post a question especially tagging and the Q&A Functionality.
With that's said, I'm not able to get the same error as you with the code provided but instead, I get
SyntaxError:non-keyword arg after keyword arg
.
Which is as the error state and error due to no-named parameter after named parameter. So it give us:self.AddButton(1001, c4d.BFH_SCALE|c4d.BFV_SCALE, 100, 25, "A button!")
or
self.AddButton(id=1001, flags=c4d.BFH_SCALE|c4d.BFV_SCALE, initw=100, inith=25, name="A button!")
If this not solve your issue (since I don't the same error) please provide us your full code if it's possible.
Cheers,
Maxime. -
Hi Maxime,
thanks for the reply! I did tag tag the post (R20, Python, Classic API) and did use MD syntax to format the code, didn't I? Will remember to set a topic as question, sorry, didn't know that one yet.
Anyway, I changed the line to this:
self.AddButton(id=self.BUTTON_ID, flags=c4d.BFH_SCALE|c4d.BFV_SCALE, initw=100, inith=25, name="Close Dialog")
The original line with the non-keyword args was my mistake, sorry.
Anyway, the error remains the same (SystemError:error return without exception set). As soon as I remove the line with the
Addbutton()
call, the error is gone. I'm stumped.Even if I break it down to the simplest form allowed, the error still remains:
self.AddButton(id=1001, flags=0)
Cheers,
Frank -
Here with the following code, it's working nicely on R20.026, Win10.
import c4d class TestDialog(c4d.gui.GeDialog): BUTTON_ID = 1001 def CreateLayout(self): self.SetTitle("The dialog of my dreams") self.AddButton(id=self.BUTTON_ID, flags=c4d.BFH_SCALE|c4d.BFV_SCALE, initw=100, inith=25, name="Close Dialog") self.AddDlgGroup(c4d.DLG_OK|c4d.DLG_CANCEL) return True def Command(self, id, msg): if id==self.BUTTON_ID: self.Close() return True # Main function def main(): # Test dialog diag = TestDialog() diag.Open(dlgtype=c4d.DLG_TYPE_MODAL, defaultw=400, defaulth=400) # Execute main() if __name__=='__main__': main()
May I ask your full code?
Do you use any 3rd party module?
What's your OS, exact Cinema 4D Version? Find The Cinema 4D version at the bottom of the about windowsCheers,
Maxime. -
Hi Maxime,
now that's interesting. You code runs perfectly fine. If I copy & paste your dialog code into my script, it still works, though your dialog is seemingly similar to mine. So, I have no idea what fixed it, but it did. Maybe some excess trailing spaces somewhere? Weird... but thank you for doing your magic If I ever find out what was happening here, I'll post here.
Cheers,
Frank