AfraLISP - Learn AutoLISP for AutoCAD productivity

Hiding Dialog Boxes

by Kenny Ramage

Often you need to make a selection on the screen whilst a dialogue box is active. But, to do this, you need to be able to hide the dialogue box to allow the user to make a selection from the screen. You must then restore the dialogue box, along with the values that the user has selected.

When you end a dialogue box you use the (done_dialog) function. But did you know that when you call the (done_dialog) function a status argument is returned? Well it's true!

Now think about this. When (done_dialog) is called from a tile who's key is "cancel" (The Cancel button), it returns a status of 0. If a tile who's key is 'accept' is choosen (The OK button), it returns a status of 1. So, if you use the (done_dialog) function alongwith a status argument of say 4, you know that the dialogue box has been hidden and not ended or cancelled.

But how do I retrieve that status argument? Easy, when you call (start_dialog), it returns the (done_dialog) status value. eg. (setq flag (start_dialogue). By testing this value in a loop we can determine whether the dialogue was simply hidden or ended or cancelled. Below is a sample routine that should, hopefully, I hope and pray, explain it to you a lot better.

This routine simply displays a dialogue box that asks the user for a point. If the user choosers the pick point button the dialogue is hidden to allow the user to pick a point on the screen. The dialogue is then re-displayed and the x, y and z edit boxes are updated to the new point value. It also allows the user to enter the point values directly into the edit boxes if he so wishes.

Hiding Dialogues

First the DCL Coding :

hidebox : dialog {
        label = "Hide Dialogue";
	: boxed_column {
	  label = "Sample Point";
	: button {
	label = "Pick Point <";
	key = "hide";
	width = 12;
	fixed_width = true;
	mnemonic = "P";
	: edit_box {
	key = "eb1";
	label = "&X:";
        width = 8;
	fixed_width = true;
	: edit_box {
	key = "eb2";
	label = "&Y:";
        width = 8;
	fixed_width = true;
	: edit_box {
	key = "eb3";
	label = "&Z:";
        width = 8;
	fixed_width = true;

And now the AutoLISP Coding :

(defun c:hidebox ()
;define the function
  (setq ptx "1.000"
	pty "0.000"
	ptz "0.000"
        flag 4
  ;set default x,y, and z values
  ;and set flag to 4
  (setq dcl_id (load_dialog "hidebox.dcl"))
  ;load the DCL file
  (while (> flag 2)
  ;check the flag status and carry on looping
  ;if it is greater than 2
  (if (not (new_dialog "hidebox" dcl_id))
  ;load the dialogue box
    ;if not loaded exit
  (set_tile "eb1" ptx)
  ;display x value
  (set_tile "eb2" pty)
  ;display y value
  (set_tile "eb3" ptz)
  ;display z value
  (mode_tile "eb1" 2)
  ;set focus to x edit box
  (mode_tile "eb1" 3)
  ;select contents
     (setq result nil)"
  ;if Cancel button selected, close
  ;the dialogue. This action sets the
  ;flag to 0.
    "(setq ptx (get_tile \"eb1\"))
     (setq pty (get_tile \"eb2\"))
     (setq ptz (get_tile \"eb3\"))
     (setq result T)"
  ;if OK button was selected, get the edit box
  ;point values, close the dialogue. This action
  ;sets the flag to 1.
    "(done_dialog 4)"
  ;if pick button selected, hide the dialogue
  ;and set the flag to 4
  (setq flag (start_dialog))
  ;start the dialogue and set flag
  ;to value of start dialogue
  (if (= flag 4)
  ;if the pick button was selected
    ;do the following
      (setq selpoint (getpoint "\nInsertion Point: "))
      ;get the insertion point
      (setq ptx (rtos (car selpoint) 2 4))
      ;get the x value
      (setq pty (rtos (cadr selpoint) 2 4))
      ;get the y value
      (setq ptz (rtos (caddr selpoint) 2 4))
      ;get the z value
  (unload_dialog dcl_id)
  ;unload the dialogue
(princ);load clean

To hide AND nest dialogue boxes is just a case of combining the two. (I'll leave that to you to figure out…)

Would you like the coding for these routines? Then put one leg in the air, close your left eye, scream as loud as you can and click here.