Opening and closing Modal Dialogs from Modal Dialog problem

Started by LogicTools, April 24, 2023, 10:12:55 AM

Previous topic - Next topic

LogicTools

I am trying to combine two modal dialogs.
Clicking on the TextButtons of the first modal dialog should close the current second modal dialog, if any, and open a new one with different options.
It does the task, but after a limited number of times, it closes de current second modal dialog but does not open the new one.
Here is the code, 'my_odcl_dir' should be substituted by the directory where you have downloaded 'FormTest.odcl'.
(defun c:FormTest (/ g_form project)
(dcl_Project_Load (strcat my_odcl_dir "\\FormTest") T)
(dcl_form_show FormTest_Form1)
)


(defun c:FormTest/Form1#OnInitialize (/ TextButton11)
(setq
  TextButton11 (mt_pmp_dlg "Close")
  )
(dcl-Control-SetCaption FormTest/Form1/TextButton11 TextButton11)
(princ)
)


(defun mt_show_pict_form (form2show / form1_pos)
(setq
  form1_pos (dcl-Control-GetPos "FormTest" "Form1")
  )
(dcl-Form-Show "FormTest" form2show (car form1_pos) (+ (cadr form1_pos) (last form1_pos)))
)


(defun c:FormTest/Form1/TextButton0#OnClicked (/)
(if g_form
  (dcl-Form-Close "FormTest" g_form)
  )
(setq
  g_form "Form02"
  )
(mt_show_pict_form g_form)
)


(defun c:FormTest/Form1/TextButton1#OnClicked (/)
(if g_form
  (dcl-Form-Close "FormTest" g_form)
  )
(setq
  g_form "Form06"
  )
(mt_show_pict_form g_form)
)


(defun c:FormTest/Form1/TextButton2#OnClicked (/)
(if g_form
  (dcl-Form-Close "FormTest" g_form)
  )
(setq
  g_form "Form02"
  )
(mt_show_pict_form g_form)
)


(defun c:FormTest/Form1/TextButton3#OnClicked (/)
(if g_form
  (dcl-Form-Close "FormTest" g_form)
  )
(setq
  g_form "Form04"
  )
(mt_show_pict_form g_form)
)


(defun c:FormTest/Form1/TextButton4#OnClicked (/)
(if g_form
  (dcl-Form-Close "FormTest" g_form)
  )
(setq
  g_form "Form04"
  )
(mt_show_pict_form g_form)
)


(defun c:FormTest/Form1/TextButton5#OnClicked (/)
(if g_form
  (dcl-Form-Close "FormTest" g_form)
  )
(setq
  g_form "Form03"
  )
(mt_show_pict_form g_form)
)


(defun c:FormTest/Form1/TextButton6#OnClicked (/)
(if g_form
  (dcl-Form-Close "FormTest" g_form)
  )
(setq
  g_form "Form05"
  )
(mt_show_pict_form g_form)
)


(defun c:FormTest/Form1/TextButton11#OnClicked (/)
(if (and g_form (dcl-Form-IsActive "FormTest" g_form))
  (dcl-Form-Close "FormTest" g_form)
  )
(dcl-Form-Close FormTest/Form1)
)


(defun c:FormTest/Form02#OnInitialize ()
(dcl-Form-Enable FormTest/Form1 'T)
)


(defun c:FormTest/Form03#OnInitialize ()
(dcl-Form-Enable FormTest/Form1 'T)
)


(defun c:FormTest/Form04#OnInitialize ()
(dcl-Form-Enable FormTest/Form1 'T)
)


(defun c:FormTest/Form05#OnInitialize ()
(dcl-Form-Enable FormTest/Form1 'T)
)


(defun c:FormTest/Form06#OnInitialize ()
(dcl-Form-Enable FormTest/Form1 'T)
)
[code]


Any ideas why this happens?




LogicTools


Basically the problem was,
(dcl-Form-Close "FormTest" g_form)
That had to be changed to,
(dcl-Form-Hide "FormTest" g_form)
on all of the TextButton#OnClicked actions.
It is also important to make sure that all the secondary forms are close at the time that Form1 is for the action to be returned to  AutoCad.
Here is the modified code, 'my_odcl_dir' should be substituted by the directory where 'FormTest.odcl' was downloaded.


(defun c:FormTest (/ g_form project)
(dcl_Project_Load (strcat my_odcl_dir "\\FormTest") T)
(dcl_form_show FormTest_Form1)
)


(defun c:FormTest/Form1#OnInitialize (/ TextButton11)
(setq
  TextButton11 (mt_pmp_dlg "Close")
  )
(dcl-Control-SetCaption FormTest/Form1/TextButton11 TextButton11)
(princ)
)


(defun mt_show_pict_form (form2show / form1_pos return)
(setq
  form1_pos (dcl-Control-GetPos "FormTest" "Form1")
  )
(setq
  return (dcl-Form-Show "FormTest" form2show (car form1_pos) (+ (cadr form1_pos) (last form1_pos)))
  )
(print return)
)


(defun c:FormTest/Form1/TextButton0#OnClicked (/)
(if (and g_form (dcl-Form-IsActive "FormTest" g_form))
  (dcl-Form-Hide "FormTest" g_form)
  )
(setq
  g_form "Form02"
  )
(mt_show_pict_form g_form)
)


(defun c:FormTest/Form1/TextButton1#OnClicked (/)
(if (and g_form (dcl-Form-IsActive "FormTest" g_form))
  (dcl-Form-Hide "FormTest" g_form)
  )
(setq
  g_form "Form06"
  )
(mt_show_pict_form g_form)
)




(defun c:FormTest/Form1/TextButton2#OnClicked (/)
(if (and g_form (dcl-Form-IsActive "FormTest" g_form))
  (dcl-Form-Hide "FormTest" g_form)
  )
(setq
  g_form "Form02"
  )
(mt_show_pict_form g_form)
)




(defun c:FormTest/Form1/TextButton3#OnClicked (/)
(if (and g_form (dcl-Form-IsActive "FormTest" g_form))
  (dcl-Form-Hide "FormTest" g_form)
  )
(setq
  g_form "Form04"
  )
(mt_show_pict_form g_form)
)




(defun c:FormTest/Form1/TextButton4#OnClicked (/)
(if (and g_form (dcl-Form-IsActive "FormTest" g_form))
  (dcl-Form-Hide "FormTest" g_form)
  )
(setq
  g_form "Form04"
  )
(mt_show_pict_form g_form)
)




(defun c:FormTest/Form1/TextButton5#OnClicked (/)
(if (and g_form (dcl-Form-IsActive "FormTest" g_form))
  (dcl-Form-Hide "FormTest" g_form)
  )
(setq
  g_form "Form03"
  )
(mt_show_pict_form g_form)
)




(defun c:FormTest/Form1/TextButton6#OnClicked (/)
(if (and g_form (dcl-Form-IsActive "FormTest" g_form))
  (dcl-Form-Hide "FormTest" g_form)
  )
(setq
  g_form "Form05"
  )
(mt_show_pict_form g_form)
)


(defun c:FormTest/Form1/TextButton11#OnClicked (/)
(if (and g_form (dcl-Form-IsActive "FormTest" g_form))
  (dcl-Form-Close "FormTest" g_form)
  )
(c:FormTest/Form1#OnCancelClose 3)
(dcl-Form-Close FormTest/Form1)
)


(defun c:FormTest/Form1#OnCancelClose (Reason /)
(if (dcl-Form-IsActive FormTest/Form02)
  (dcl-Form-Close FormTest/Form02)
  )
(if (dcl-Form-IsActive FormTest/Form03)
  (dcl-Form-Close FormTest/Form03)
  )
(if (dcl-Form-IsActive FormTest/Form04)
  (dcl-Form-Close FormTest/Form04)
  )
(if (dcl-Form-IsActive FormTest/Form05)
  (dcl-Form-Close FormTest/Form05)
  )
(if (dcl-Form-IsActive FormTest/Form06)
  (dcl-Form-Close FormTest/Form06)
  )
(princ)
)


(defun c:FormTest/Form02#OnInitialize ()
(dcl-Form-Enable FormTest/Form1 'T)
)


(defun c:FormTest/Form03#OnInitialize ()
(dcl-Form-Enable FormTest/Form1 'T)
)


(defun c:FormTest/Form04#OnInitialize ()
(dcl-Form-Enable FormTest/Form1 'T)
)


(defun c:FormTest/Form05#OnInitialize ()
(dcl-Form-Enable FormTest/Form1 'T)
)


(defun c:FormTest/Form06#OnInitialize ()
(dcl-Form-Enable FormTest/Form1 'T)
)


(defun c:FormTest/Form02#OnCancelClose (Reason /)
(c:FormTest/Form1#OnCancelClose 2)
(dcl-Form-Close FormTest/Form1)
)


(defun c:FormTest/Form03#OnCancelClose (Reason /)
(c:FormTest/Form1#OnCancelClose 2)
(dcl-Form-Close FormTest/Form1)
)


(defun c:FormTest/Form04#OnCancelClose (Reason /)
(c:FormTest/Form1#OnCancelClose 2)
(dcl-Form-Close FormTest/Form1)
)


(defun c:FormTest/Form05#OnCancelClose (Reason /)
(c:FormTest/Form1#OnCancelClose 2)
(dcl-Form-Close FormTest/Form1)
)


(defun c:FormTest/Form06#OnCancelClose (Reason /)
(c:FormTest/Form1#OnCancelClose 2)
(dcl-Form-Close FormTest/Form1)
)

Fred Tomke

Hm, thanks for sharing. I had no test, but in my experiences modal forms give no control to AutoCAD for picking points or entities after dcl-form-hide. You have to dcl-form-close before and reopen the form by dcl-form-show again. dcl-form-hide my work with modeless forms, but, as I said, I have no experiencee with that workflow.
Regards, Fred Tomke
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]