Create an asynchronous dialog in script
-
On 23/02/2017 at 05:42, xxxxxxxx wrote:
I have a problem at work. When I create an asynchronous dialog in script, the application aways stops working.But it is OK when I create a modal dialog.
-
On 23/02/2017 at 07:43, xxxxxxxx wrote:
You simply can't create async dialog in a script.
For that oyu must do a command plugin which lunch an async dialog. -
On 23/02/2017 at 09:27, xxxxxxxx wrote:
Sure you can.
The real question to ask is whether or not it's a good idea.
This is probably not be the safest, most stable way to use it. But it can be done.import c4d from c4d import gui class ExampleDlg(gui.GeDialog) : def CreateLayout(self) : self.SetTitle("Simple Dialog") self.AddButton(1111, c4d.BFH_SCALE, name="MessadeDialog") return True def InitValues(self) : return True def Command(self, id, msg) : if id==1111: print "button was pressed" return c4d.gui.GeDialog.Command(self, id, msg) def CoreMessage(self, id, msg) : if id==c4d.EVMSG_CHANGE: print "Scene was Changed" return gui.GeDialog.CoreMessage(self, id, msg) def Message(self, id, msg) : if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.KEY_ESC, msg) : if msg[c4d.BFM_INPUT_VALUE]: print "ESC Pressed" if c4d.gui.GetInputState(c4d.BFM_INPUT_MOUSE,c4d.BFM_INPUT_MOUSELEFT, msg) : mx = msg[c4d.BFM_INPUT_X] my = msg[c4d.BFM_INPUT_Y] bd = doc.GetActiveBaseDraw() win = bd.GetEditorWindow() x, y = win.Local2Screen() print mx-x, (my-y)+22 return gui.GeDialog.Message(self, id, msg) dlg = ExampleDlg() dlg.Open(c4d.DLG_TYPE_ASYNC, defaultw=300, defaulth=50)
-ScottA
-
On 23/02/2017 at 18:55, xxxxxxxx wrote:
Yeah,thanks for your help!
-
On 24/02/2017 at 04:51, xxxxxxxx wrote:
Hi,
even if it may seem to work, we can only discourage to use a non-modal/asynchronous dialog from a script.
Think about it, a dialog always needs to be owned by "someone", in Scott's example script the dialog gets stored in a global variable and the script (or rather the context executing the script) would be owner of the dialog. Similar to the CommandData plugin usually used to "host" non-modal/asynchronous dialogs.
But what happens, after the script execution is done?
Or even worse, the dialog is still open and the script is executed a second time?
Who is storing its context?
Who has the ownership?
Right, that's not defined anymore. There's a window floating around, orphaned and lonely. Chances are high, poor windows memory being corrupted by someone else. Or perhaps, as not being happy about its situation, using memory that by now might be owned by somebody else...
Scary, right?
And as I said, not a good idea.
If needed, use either modal/synchronous dialogs in scripts, or if in need for an asynchronous dialog, add a few more lines of code and convert your script into a CommandData plugin. -
On 25/02/2017 at 23:16, xxxxxxxx wrote:
That is great!
Thanks!!!