AfraLISP - Learn AutoLISP for AutoCAD productivity

Hiding Dialog Boxes Revisited - Part 2

by Kenny Ramage

We will now attempt to design a dialog box that will displays certain properties of a selected entity. We would like the dialog to display first, and then hide itself whilst we go about making up our mind which object we want to select. Once selected, the dialog will be updated with the objects property values. We also want to be able to continue selecting objects which means that the dialog must update after each selection.

Okay, let's give it a go.

Hide Dialog

First the DCL Coding :

hidedialog : dialog {
	label = "Hide Dialogue";
 
	: list_box {
        	label = "&Properties :";
        	key = "selections";
        	height = 7;
	width = 25;
     	}   
 
	: button {
	label = "Select Object >>";
	key = "hide";
	width = 8;
	fixed_width = true;
	mnemonic = "S";
                alignment = centered;
                is_default = true;
	}
 
	: spacer { width = 1;}
 
	ok_cancel;
 
  	 } 

Save this as HideDialog.dcl.

And now the AutoLisp coding. Save this as HideDialog.lsp :

(defun c:hidedialog ( / dcl_id thelist lay col ltp lwt flag)
 
  (vl-load-com)
 
  ;set up default list box values
  (setq thelist '("Layer = NULL" "Color = NULL" 
                 "Linetype = NULL" "Lineweight = NULL"))
 
  ;set flag to 4
  (setq flag 4)
 
  ;load the DCL file
  (setq dcl_id (load_dialog "hidedialog.dcl"))
  
  ;check the flag status and carry on looping
  ;if it is greater than 2
  (while (> flag 2)
 
  ;load the dialog box
  (if (not (new_dialog "hidedialog" dcl_id))
  
    ;if not loaded exit
    (exit))
 
  ;populate the list box with the values
  ;in thelist
  (start_list "selections")
  (mapcar 'add_list thelist)
  (end_list)
 
  ;if Cancel button selected, close
  ;the dialog. This action sets the
  ;flag to 0.
  (action_tile "cancel" "(done_dialog 0)")
 
  ;if OK button was selected, close
  ; the dialog. This action
  ;sets the flag to 1.
  (action_tile "accept" "(done_dialog 1)")
  
  ;if pick button selected, hide the dialog
  ;and set the flag to 4
  (action_tile "hide" "(done_dialog 4)")
 
  ;start the dialog and set flag
  ;to value of start dialog
  (setq flag (start_dialog))
 
  ;if the OK button was selected
  (if (= flag 1) (alert "You chose the OK button"))
 
  ;if the Cancel button was selected
  (if (= flag 0) (alert "You chose the Cancel button"))
 
  ;if the pick button was selected
  (if (= flag 4)
 
    ;do the following
    (progn
 
	;select the object
	(setq ent (entsel))
 
	;convert to vl object
	(setq ent (vlax-Ename->Vla-Object (car ent)))
 
	;get the properties and place them in a list
	;the layer first
	(setq lay (strcat "Layer = " 
                      (vla-get-layer ent))
 
	;then the color
              col (strcat "Color = " 
                       (itoa (vla-get-color ent)))
 
	;next the linetype
              ltp (strcat "Linetype = " 
                       (vla-get-linetype ent))
 
	;finally the lineweight
             lwt (strcat "Lineweight = " 
                       (itoa (vla-get-lineweight ent)))
 
	;create the list
      	     thelist  (list lay col ltp lwt)
 
	);setq
 
    );progn
 
  );if
 
  );while
 
  ;unload the dialog
  (unload_dialog dcl_id)
 
  (princ)
 
);defun
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
(princ);load clean

Hey just think! You can now design your own properties dialog.

Well that's about it regarding hiding dialog boxes. I hope you had a good time, enjoyed the snacks (especially the chicken) and didn't drink too much beer. Remember, don't drink and drive because you might spill some.

Did I forget? No I didn't. If you would like to download the source coding, just click here.