Dialog Boxes & AutoLISP - Part 2
We are now going to add a set of radio buttons enclosed in a radio column. This is to allow the user to select the type of bolt.
The DCL coding :
samp4 : dialog { //dialog name label = "Structural Holes" ; //give it a label :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 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 the AutoLISP coding :
(defun C:samp4 () ;define function (setq dcl_id (load_dialog "samp4.dcl")) ;load dialog (if (not (new_dialog "samp4" 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 (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 (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 " (done_dialog)(setq userclick T)" ;close dialog, set flag );action tile (start_dialog) ;start dialog (unload_dialog dcl_id) ;unload (princ) );defun C:samp (princ)
Now we'll add a drop down list so that we can select the bolt size.
The DCL coding :
samp5 : 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 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
Note how we have put the Radio Column and the Drop Down List box into a Row. Looks good hey… Now the AutoLISP coding :
(defun C:samp5 () ;define function (setq siz "M20") ;preset hole size (setq NAMES '("M6" "M8" "M10" "M12" "M16" "M20" "M24" "M30") ;define list );setq (setq dcl_id (load_dialog "samp5.dcl")) ;load dialog (if (not (new_dialog "samp5" 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 (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 (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 " (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)
This tutorial continues in Part 3.