AfraLISP - Learn AutoLISP for AutoCAD productivity

Dialog Boxes & AutoLISP - Part 4

by Kenny Ramage

To finish off the box, we'll add an Edit Box so that the user can include some notes, if he so wishes.

Sample 8

The Complete DCL coding :

samp8 : dialog {				//dialog name
      label = "Structural Holes" ;		//give it a label
 
       : row {					//define row
 
       :boxed_radio_column {			//define radio column
       label = "Type" ;				//give it a label
 
        : radio_button {			//define radion button
     	  key = "rb1" ;				//give it a name
     	  label = "Bolt Holes &Site" ;		//give it a label
     	  value = "1" ;				//switch it on
        }					//end definition
 
     	: radio_button {			//define radio button
     	  key = "rb2" ;				//give it a name
     	  label = "Bolt Holes Sho&p" ;		//give it a label
     	}					//end definition
 
     	: radio_button {			//define radio button
     	  key = "rb3" ;				//give it a name
     	  label = "Bolt Holes &Hidden" ;	//give it a label
     	  }					//end definition
 
     	: radio_button {			//define radio button
     	  key = "rb4" ;				//give it a name
     	  label = "Bolt Holes &Ctsnk" ;		//give it a label
     	}					//end definition
 
     	: radio_button {			//define radio button
     	  key = "rb5" ;				//give it a name
     	  label = "Bolt Holes &Elevation" ;	//give it a label
     	  }					//end definition
 
     	: radio_button {			//define radion button
     	  key = "rb6" ;				//give it a name
     	  label = "Bolt Holes &Slotted" ;	//give it a label
     	}					//end definition
 
        }					//end radio column
 
        : boxed_column {			//define boxed column
        label = "&Size";			//give it a label
 
     	: popup_list {				//define popup list
        key = "selections";			//give it a name
        value = "5" ;				//initial value
        }					//end list
 
       }					//end boxed column
 
       }					//end row
 
       : edit_box {				//define edit box
         key = "eb1" ;				//give it a name
         label = "Slot &Length (O/All Slot)" ;	//give it a label
         edit_width = 6 ;			//6 characters only
        }					//end edit box
 
        : slider {				//defin slider
        key = "myslider" ;			//give it a name
        max_value = 100;			//upper value
        min_value = 0;				//lower value
        value = "50";				//initial value
        }					//end slider
 
        :boxed_row {				//define boxed row
 
        :toggle {				//define toggle
        key = "tog1";				//give it a name
        label = "Ortho On/Off";			//give it a label
        }					//end toggle
 
        :toggle {				//define toggle
        key = "tog2";				//give it a name
        label = "Snap On/Off";			//give it a label
        }					//end definition
 
        }					//end boxed row
 
        : edit_box {				//define edit box
         key = "eb2" ;				//give it a name
         label = "Notes :" ;			//give it a label
         edit_width = 30 ;			//30 characters
        }					//end edit box
 
     ok_cancel ;				//predifined OK/Cancel
 
     : row {					//define row
 
     : image {					//define image tile
     key = "im" ;				//give it a name
     height = 1.0 ;				//and a height
     width = 1.0 ;				//and now a width
     }						//end image
 
     : paragraph {				//define paragraph
 
     : text_part {				//define text
     label = "Designed and Created";		//give it some text
     }						//end text
 
     : text_part {				//define more text
     label = "by Kenny Ramage";			//some more text
     }						//end text
 
     }						//end paragraph
 
     }						//end row
					
     }						//end dialog

And Now the Complete AutoLISP coding :

(defun C:samp8 ()					;define function	
 
  (setq lngth 50.0)					;preset slot length
 
  (setq hole "site")					;preset hole type
 
  (setq siz "M20")					;preset hole size
 
  (setq NAMES '("M6" "M8" "M10" "M12"
                "M16" "M20" "M24" "M30")		;define list
  );setq
 
  (setq dcl_id (load_dialog "samp8.dcl"))		;load dialog
 
  (if (not (new_dialog "samp8" dcl_id)			;test for dialog
 
      );not
 
    (exit)						;exit if no dialog
 
  );if
 
  (setq w (dimx_tile "im")				;get image tile width
        h (dimy_tile "im")				;get image tile height
 
);setq
 
  (start_image "im")					;start the image
  (fill_image 0 0 w h 5)				;fill it with blue
  (end_image)						;end image
 
  (start_list "selections")				;start the list box
  (mapcar 'add_list NAMES)				;fill the list box
  (end_list)						;end list
 
  (set_tile "eb1" "50")					;put dat into edit box
  (mode_tile "eb1" 1)					;disable edit box
  (mode_tile "myslider" 1)				;disable slider
 
  (setq orth (itoa (getvar "orthomode")))		;get orthomode value
  (set_tile "tog1" orth)				;switch toggle on or off
 
  (setq sna (itoa (getvar "snapmode")))			;get snap value
  (set_tile "tog2" sna)					;switch toggle on or off
 
  (action_tile "myslider"				;if user moves slider
	 "(slider_action $value $reason)")		;pass arguments to slider_action
 
  (action_tile "eb1" 					;is user enters slot length
	 "(ebox_action $value $reason)")		;pass arguments to ebox_action
 
  (defun slider_action (val why)			;define function
      (if (or (= why 2) (= why 1))			;check values
      (set_tile "eb1" val)))				;update edit box
 
  (defun ebox_action (val why)				;define function
      (if (or (= why 2) (= why 1))			;check values
      (set_tile "myslider" val)))			;update slider
 
  (action_tile "tog1" "(setq orth $value)")		;get ortho toggle value
  (action_tile "tog2" "(setq sna $value)")		;get snap toggle value
 
  (action_tile "rb1" "(setq hole \"site\")")		;store hole type
  (action_tile "rb2" "(setq hole \"shop\")")		;store hole type
  (action_tile "rb3" "(setq hole \"hid\")")		;store hole type
  (action_tile "rb4" "(setq hole \"ctsk\")")		;store hole type
  (action_tile "rb5" "(setq hole \"elev\")")		;store hole type
  (action_tile "rb6" "(setq hole \"slot\")		;store hole type
                      (mode_tile \"eb1\" 0)		;enable edit box
                      (mode_tile \"myslider\" 0)	;enable slider
                      (mode_tile \"eb1\" 2)")		;switch focus to edit box
 
    (action_tile
    "cancel"						;if cancel button pressed
    "(done_dialog) (setq userclick nil)"		;close dialog, set flag
    );action_tile
 
  (action_tile
    "accept"						;if O.K. pressed
    (strcat						;string 'em together
      "(progn 
       (setq SIZ (atof (get_tile \"selections\")))"	;get list selection
      "(setq lngth (atof (get_tile \"eb1\")))"		;get slot length
      "(setq notes (get_tile \"eb2\"))"			;get notes
      "(setvar \"orthomode\" (atoi orth))"		;ortho on/off
      "(setvar \"snapmode\" (atoi sna))"		;snap on/off
      " (done_dialog)(setq userclick T))"		;close dialog, set flag
    );strcat

  );action tile
 
  (start_dialog)					;start dialog
 
  (unload_dialog dcl_id)				;unload
 
   (if userclick					;check O.K. was selected
    (progn
 
      (setq SIZ (fix SIZ))				;convert to integer
      (setq SIZ (nth SIZ NAMES))			;get the size
 
    );progn
 
  );if userclick
 
(princ)
 
);defun C:samp
 
(princ)

I have deliberately left all variables local, so that you can check their values at the command line.

That's it Folks…

Enjoy your Dialogue Boxes…