AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Home. Page II.

Nesting Dialogue Boxes.

This is another area that seems to cause a lot of confusion for some people.
Let's take a slow walk through the process of nesting and hiding dialogue boxes and see if we can't explain it more clearly.

To nest dialogue boxes is pretty straightforward. You simply call the new, nested dialogue box from within an action expression or callback function.
For example :

	(action_tile "next" "(nextfunction)")

This simply says that when the tile with the key of 'next' is selected, then run the function (nextfunction). (nextfunction), of course, would have it's own dialogue statements.

Just a couple of comments on nesting dialogue boxes.
Firstly, you cannot use the previous dialogue box whilst a nested dialogue is
active. You must close the nested dialogue first.
And secondly, AutoCAD states that there is a limit of no more than eight nested
dialogue boxes allowed, but recommends a maximum of four.
(Try it, I haven't!!!)
Thirdly, try and keep each nested dialogue smaller than the preceding dialogue.

Here's an example of a function with a main dialogue box and two nested
dialogue boxes.

Nested Dialogue Boxes

First the DCL Coding:

main : dialog {
        label = "Main Dialogue";

	: column {

	: text {
	key = "txt1";
	value = "This is the main dialogue box.";
	       }

	: text {
	key = "txt2";
	value = "To display the next, nested dialogue,";
	       }

	: text {
	key = "txt3";
	value = "Press Next....";
	       }
	}
   	: row {

	: spacer { width = 1; }

	: button {
	label = "OK";
	key = "accept";
	width = 12;
	fixed_width = true;
	mnemonic = "O";
	is_default = true;
	}

	: button {
	label = "Next";
	key = "next";
	width = 12;
	fixed_width = true;
	mnemonic = "N";
	}

	: button {
	label = "Cancel";
	key = "cancel";
	width = 12;
	fixed_width = true;
	mnemonic = "C";
	is_cancel = true;
  	}

	: spacer { width = 1;}

	}

  		 }

////////////////////////////////////////////////

nest1 : dialog {
        label = "1st Nested Dialogue";

	: column {

	: text {
	key = "txt1";
	value = "This is the first nested dialogue box.";
	       }

	: text {
	key = "txt2";
	value = "To display the next, nested dialogue, press Next";
	       }
		}
   	: row {

	: spacer { width = 1; }

	: button {
	label = "OK";
	key = "accept";
	width = 12;
	fixed_width = true;
	mnemonic = "O";
	is_default = true;
	}

	: button {
	label = "Next";
	key = "next";
	width = 12;
	fixed_width = true;
	mnemonic = "N";
	}

	: button {
	label = "Cancel";
	key = "cancel";
	width = 12;
	fixed_width = true;
	mnemonic = "C";
	is_cancel = true;
  	}

	: spacer { width = 1;}

	}

  		 }

////////////////////////////////////////////////

nest2 : dialog {
        label = "2nd Nested Dialogue";

	: column {

	: text {
	key = "txt1";
	value = "This is the last nested dialogue box.";
	       }
	}

   	: row {

	: spacer { width = 1; }

	: button {
	label = "OK";
	key = "accept";
	width = 12;
	fixed_width = true;
	mnemonic = "O";
	is_default = true;
	}

	: button {
	label = "Cancel";
	key = "cancel";
	width = 12;
	fixed_width = true;
	mnemonic = "C";
	is_cancel = true;
  	}

	: spacer { width = 1;}

	}

  		 }

////////////////////////////////////////////////

And now the Autolisp Coding:
(defun c:nest ()
;define the function

  (setq dcl_id (load_dialog "nest.dcl"))
  ;load the DCL file

  (if (not (new_dialog "main" dcl_id))
  ;load the dialogue box

    (exit)
    ;if not loaded exit

  )

  (action_tile
    "cancel"
    "(done_dialog)
     (setq result nil)"
  )
  ;do this if Cancel button selected

  (action_tile
    "accept"
    "(done_dialog)
     (setq result T)"
  )
  ;do this if OK button selected

  (action_tile
    "next"
    "(nest1)"
  )
  ;if Next button is selected, call 
  ;the nested dialogue function

  (start_dialog)
  ;start the dialogue

  (unload_dialog dcl_id)
  ;unload the dialogue

  (princ)

);defun

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun nest1 ()
;define the function

  (setq dcl_id1 (load_dialog "nest.dcl"))
  ;load the DCL file

  (if (not (new_dialog "nest1" dcl_id1))
  ;load the nested dialogue box

    (exit)
    ;if not loaded exit

  )

  (action_tile
    "cancel"
    "(done_dialog)
     (setq result1 nil)"
  )
  ;if cancel selected do this

  (action_tile
    "accept"
    "(done_dialog)
     (setq result1 T)"
  )
  ;if OK selected do this

  (action_tile
    "next"
    "(nest2)"
  )
  ;if Next selected call the
  ;second nested dialogue function


  (start_dialog)
  ;start the nested dialogue box

  (unload_dialog dcl_id1)
  ;unload the nested dialogue box

  (princ)

);defun

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun nest2 ()
;define the function

  (setq dcl_id2 (load_dialog "nest.dcl"))
  ;load the DCL file

  (if (not (new_dialog "nest2" dcl_id2))
  ;load the second nested dialogue box

    (exit)
    ;if not found exit

  )

  (action_tile
    "cancel"
    "(done_dialog)
     (setq result2 nil)"
  )
  ;do this if Cancel selected

  (action_tile
    "accept"
    "(done_dialog)
     (setq result2 T)"
  )
  ;do this if OK selected

  (start_dialog)
  ;start the second nested dialogue box

  (unload_dialog dcl_id2)
  ;unload it

  (princ)

);defun

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(princ);load clean

See, pretty simple, hey....
Now, what you have all been waiting for....Hiding Dialogue Boxes!!!
(Sorry, but you will have to go to the next page.)
Hurry up, I'm waiting.....

 


Home. Page II.
 
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website