Notifications
Clear all

[Closed] Problems to close dialog if one already exists

Well,
this sounds like something common and easy but I just can’t get it to work. All I want to do is to make sure that a dialog can not be opened twice. If you try to create the dialog while one of the kind is still open, the old one should be destroyed. So far I tried like a 100 different ways to make this happen, but nothing works. The code to test whether a dialog is open works fine by itself (the part in test_dialog.ms) but not within my code structure.
I guess what I need is a function to get all open dialogs and test somehow if one of them is of the type “testDialog” or something like that.

Here the structure/ an excerpt of my code:

   ---------------------------------
   --test_inlcude.ms
 
   filein "wouldbethepath/test_ca.ms"
   filein "wouldbethepath/test_fns.ms"
   filein "wouldbethepath/test_dialog.ms"
   
   ---------------------------------
   --test_ca.ms

  testDataCaDef = attributes testDataCA
  attribID:#(0x6c0dbc3a, 0x23c71ad2)
       version:1
       (
   	...
       )
   
   ---------------------------------
   --test_fns.ms
   
   struct structTest
       (
   	...
       )
   
   ---------------------------------
   --test_dialog.ms
   
   global gTest=(structTest())
       gTest.fnInit()
       
       rollout testDialog "Test"
       (
   	...
       )
       
       if gTest.bStopDialog == false then (
       	
       	
       	try ( destroyDialog testDialog) catch ( print "no dialog open")
       	-->DOESN'T WORK;
       	if ((testDialog != undefined) and (testDialog.isDisplayed)) then
       	--> DOESN'T WORK;
       	(
       		destroyDialog testDialog
       	)
       	
       	createDialog testDialog 490 460
       	
       )
   
   ------------------------------------
   
   
 Like I said, if I put the code excerpt above, the part with the create/destroydialog, by itself in a file, everything works fine.
   But not within my code structure. Any easy solutions for that?
   
Thanks,
Lena
3 Replies

you have to destroy the dialog before you (re)define it.

i.e.

destroyDialog rolloutname
rollout rolloutname “” etc.
createDialog rolloutname

if you do:
rollout rolloutname – let’s call this instance A
destroyDialog rolloutname – will attempt to destroy A
createDialog rolloutname – creates A

and then again:
rollout rolloutname – let’s call this instance B
destroyDialog rolloutname – will attempt to destroy B; A still exists and remains open
createDialog rolloutname – opens B; now you have 2 dialogs.

Try putting the destroyDialog code before the rollout definition code. When you define the rollout, maxscript recreates that variable in memory, so the old dialog is no longer referenced by that variable, and hence cannot be destroyed with destroyDialog.

hOpe this helps,
o

Great, that did it. Thanks!