Satish Lele
satish.lele@gmail.com


Ready Routines for Creation of Dialog Boxes
All Lisp part of Dialog box functions can be written in one .lsp file.
All dialogs can be written in one .dcl file. Syntax of code in dcl (Doalog Control Language) files is similar to that of c language. There should be ; (semi colon) at the end of each statement.

Dialog box to select Metric or Foot-Inch units with Radio Buttons
;-----------------------------------------------------------------
; Lisp part of Dialog box to select Metric or Foot-Inch units,
; using Radio Buttons.
; to be copied in a .lsp file.
(defun lmmin ( / i1 i2)
	(setq i1 (load_dialog dcl_file_name) i2 5 dimstd "mm")
  (while (< 2 i2)
	(if (not (new_dialog "mmin_db" i1)) (exit))
	    ; if new_dialog "mmin_db" is not found in dcl_file_name, exit.
  	(set_tile "mm" "1") ; mm is set as default
  	(action_tile "accept" "(setq dimstd (get_tile \"mmin\"))")
	; mmin is key in dialog box, value of which is returned by get_tile.
	; It is stored in dimstd variable and then evaluated.
        (setq i2 (start_dialog)) ; starts dialog box
  )  	
  (unload_dialog i1) ; when value is selected it unloads dialog box.
    ; it returns value of 1 if you click OK button.
    ; since it is < 2 while loop ends.
; m1 for converting metric units to foot_inch, m2 for precision,
; m3 for hatch scale, m4 for decimal places, m5 for converting kg to lb.
; m1 and m2 values are used in (rtos m1 m2   ) convertion.
(if (and (= i1 1) (= dimstd "mm"))
     (progn 
	 (setq m1 1.0  m2 2 m4 0 m5 2.204)
     (setvar "lunits" 2) ; linear units, 2 for metric
	 (setvar "luprec" 0) ; linear units precision, 0 for metric
))
(if (and (= i1 1) (= dimstd "inch"))
     (progn 
	 (setq m1 25.0 m2 4 m4 4  m5 1.0)
     (setvar "lunits" 4) ; linear units, 4 for Foot-Inch
	 (setvar "luprec" 4) ; linear units precision, 4 for Foot-Inch
     (setq m3 0.1)
))
     (princ)
) ; end lmmin
; You can remove later all comments in your .lsp file.
;----------------------------------------------------------------
// Dcl part of Dialog box to select Metric or Foot-Inch units,
// You can add more radio buttons inside boxed_radio_column.
// This should be copied in dcl_file_name.dcl file.
// Whatever follows // is a comment. 
// { should match with }.
// ---------------------
mmin_db: dialog {
   aspect_ratio = 0.0;
   label = "Drawing Units";
   :boxed_radio_column {
      label = "System of Drawing";
      alignment = centered;
      fixed_width = true;
      key = "mmin";
   :radio_button {
      key = "mm";
      label = "Metric System";
      allow_accept = true;
   }  // end of radio_button
   :radio_button {
      key = "inch";
      label = "Foot-Inch System";
      allow_accept = true;
   }  // end of radio_button
  } // end of boxed_radio_column
   :text { value = "Double click to select option"; width = 35; 
           alignment = centered; vertical_margin = tiny; }
  ok_only;  // Displays OK button
}
// end mmin_db dialog, Metric or Foot-Inch.
// You can later remove all comments in your .dcl file.
//----------------------------------------------------------------

; Lisp part of Dialog box to select text in edit_box,
; using edit_box. It returns a string.
; It is either converted to float using rtos or distof function
; or returned as text (as it is or with strcase function).
; This to be copied in a .lsp file.
;--------------------------------------------------
(defun text_det ( / i1 i2)
  (setq i1 (load_dialog dcl_file_name) i2 5)
	(while (< 2 i2)
      (if (not (new_dialog "text_det" i1)) (exit))
	  ; if value to be entered in text box is float
	    (setq text1 5.0 text2 7.0 text3 10.0)
        (set_tile "text1_db" (rtos text1 m2 m4))
	    (set_tile "text2_db" (rtos text2 m2 m4))
        (set_tile "text3_db" (rtos text3 m2 m4))
	  ; if value to be entered in text box is text
	    (setq text1 "abc" text2 "def" text3 "ghi")
        (set_tile "text1_db" text1)
        (set_tile "text2_db" text2)
        (set_tile "text3_db" text3)		  
       	(action_tile "text1_db" "(get_text1)")
       	(action_tile "text2_db" "(get_text2)")
       	(action_tile "text3_db" "(get_text3)")
   	    (action_tile "accept" "(done_dialog 1)")
     ; if OK is clicked, done_dialog return value of 1
	    (action_tile "cancel" "(done_dialog 0)")
	 ; if CANCEL is clicked, done_dialog causes (exit)
	   	(setq i2 (start_dialog))
    ) ; end while
        (unload_dialog i1)(princ)
	    ; if one or more values are not selected in dialog box
		; or left blank
	  ; if value to be entered in text box is float
      (if (not text1) (setq text1 (getreal "\nValue of text1 : ")))
      (if (not text2) (setq text2 (getreal "\nValue of text2 : ")))
      (if (not text3) (setq text3 (getreal "\nValue of text3 : ")))
	  ; if value to be entered in text box is text
      (if (not text1) (setq text1 (getstring "\nValue of text1 : ")))
      (if (not text2) (setq text2 (getstring "\nValue of text2 : ")))
      (if (not text3) (setq text3 (getstring "\nValue of text3 : ")))
) ; end text_det ----------------------------------------
; if value to be returned as float
(defun get_text1 () (setq text1 (distof (get_tile "text1_db"))))
(defun get_text2 () (setq text1 (distof (get_tile "text2_db"))))
(defun get_text3 () (setq text1 (distof (get_tile "text3_db"))))
; if text value to be returned as Capitalized text
(defun get_text1 () (setq text1 (strcase (get_tile "text1_db"))))
(defun get_text2 () (setq text1 (strcase (get_tile "text2_db"))))
(defun get_text3 () (setq text1 (strcase (get_tile "text3_db"))))
; if text value to be returned as it is
(defun get_text1 () (setq text1 (get_tile "text1_db")))
(defun get_text2 () (setq text1 (get_tile "text2_db")))
(defun get_text3 () (setq text1 (get_tile "text3_db")))
; end of portion to be copied in .lsp file
;---------------------------------------------------------------
// Dialog boxes to get text details
text_det :dialog {
  aspect_ratio = 0.0;
: row {
  label = "Values to be collected from text boxes";
 : boxed_column {
  alignment = centered;
  fixed_width = true;
  :edit_box {
  label = "Value of text1 : ";
  key = "text1_db";
  edit_width = 8;
  edit_limit = 15;
  horizontal_alignment = right;
  }
  :edit_box {
  label = "Value of text2 : ";
  key = "text2_db";
  edit_width = 8;
  edit_limit = 15;
  horizontal_alignment = right;
  }
  :edit_box {
  label = "Value of text3 : ";
  key = "text3_db";
  edit_width = 8;
  edit_limit = 15;
  horizontal_alignment = right;
  }
 }
}
	ok_only;
}
// end text_det dialog box for text selection  ------------

Dialog box to select Nozzle Number as text by edit_box and angle by list_box.
; --------------------------------------------------------------
; Lisp part of Dialog box. Both edit_box, and list_box return strings.
; Angle is converted to float, using rtos or distof function.
; Nozzle number is returned as text (as it is or with strcase function).
; This to be copied in a .lsp file.
(defun get_tag ( / i1 i2 i1_db)
(setq i1 (load_dialog dcl_file_name) i2 5 i3 45 mht1 "N")
(while (< 2 i2)
   (if (not (new_dialog "tag_db" i1)) (exit))
   (setq i1_db '("0" "30" "45" "60" "90" "120" "135" "150" "180" 
               "210" "225" "240" "270" "300" "330" "345" "Other"))
			   ; it is a list of text entities.
   (start_list "i1_db")
   (mapcar 'add_list i1_db)
   (end_list)
   (set_tile "mht1_db" mht1)
   (action_tile "i1_db" "(get_i1)")
   (action_tile "mht1_db" "(get_mht1_db)")
   (action_tile "accept" "(done_dialog 1)")
   (action_tile "cancel" "(done_dialog 0)")
   (setq i2 (start_dialog))
  (if (= i2 1)
    (progn
       (cond
            ((= i1 "0")    (setq i3 0)(princ))
            ((= i1 "30")   (setq i3 30)(princ))
            ((= i1 "45")   (setq i3 45)(princ))
            ((= i1 "60")   (setq i3 60)(princ))
            ((= i1 "90")   (setq i3 90)(princ))
            ((= i1 "120")  (setq i3 120)(princ))
            ((= i1 "135")  (setq i3 135)(princ))
            ((= i1 "150")  (setq i3 150)(princ))
            ((= i1 "180")  (setq i3 180)(princ))
            ((= i1 "210")  (setq i3 210)(princ))
            ((= i1 "225")  (setq i3 225)(princ))
            ((= i1 "240")  (setq i3 240)(princ))
            ((= i1 "270")  (setq i3 270)(princ))
            ((= i1 "300")  (setq i3 300)(princ))
            ((= i1 "330")  (setq i3 330)(princ))
            ((= i1 "345")  (setq i3 345)(princ))
            ((= i1 "Other")(setq i3 nil)(princ))
      )
    )
  )
)
(unload_dialog i1)
    (princ) (princ)
)
; end get_tag -----------------------------------------------
(defun get_i1 () (setq i1 (nth (atoi (get_tile "i1_db")) i1_db)))
; get_tile "i1_db" returns location of entity as text. 0 for first 
; location. nth subroutine returns that entity.
(defun get_mht1_db ()(setq mht1   (strcase (get_tile "mht1_db"))))
; ---------------------------------------------------------
// Dialog boxes to get tag details
tag_db : dialog {
  aspect_ratio = 0;
    label = "Tag :";
  initial_focus = "mht1_db";
  :boxed_column {
    label = "Please enter all data:";
    :edit_box {
      label = "Nozzle Number : ";
      mnemonic = "N";
      key = "mht1_db";
      edit_width = 15;
      edit_limit = 30;
      horizontal_alignment = right;
    }
    :  list_box {
     label = "Angle : ";
     mnemonic = "A";
     key = "i1_db";
     width = 20;
     height = 8;
            }
  }
  ok_only;
}// end tag_db----------------------------------------------

Dialog box to select image by image_button.
; Lisp part of Dialog box to select image buttons,
; using image_button.
; to be copied in a .lsp file.
;-----------------------------------------
(defun sel_image ( / i8 i9 i1)
(setq i9 (load_dilog dcl_file_name))
(setq i8 5)
(while (< 2 i8)
	(if (not (new_dialog "sel_image" i9)) (exit))
	(start_image)
	(action_tile "image1" "(get_image1)")
	(action_tile "image2" "(get_image2)")
	(action_tile "image3" "(get_image3)")
	(action_tile "image4" "(get_image4)")
	(action_tile "accept" "(done_dialog 1)")
	(action_tile "cancel" "(done_dialog 0)")
        (setq i8 (start_dialog))
	(if (and (= i8 1) (= i1 11)) (run some function related to image1))
	(if (and (= i8 1) (= i1 12)) (run some function related to image2))
	(if (and (= i8 1) (= i1 13)) (run some function related to image3))
	(if (and (= i8 1) (= i1 14)) (run some function related to image4))
)
(unload_dialog i9)
(princ)
) ;------
(defun get_image1 () (setq i1 11))
(defun get_image2 () (setq i1 12))
(defun get_image3 () (setq i1 13))
(defun get_image4 () (setq i1 14))
;-----
(defun start_image ()
  (foreach v0 '("image1" "image2" "image3" "image4")
    (start_image v0)
    (slide_image
      0 0
      (- (dimx_tile v0) 1)
      (- (dimy_tile v0) 1)
          v0
	)
    (end_image)
  )
) ;-------------------------------------------------------
// Dcl part of Dialog box to select image buttons,
// You can add more image buttons inside row and column.
// This should be copied in dcl_file_name.dcl file.
// Whatever follows // is a comment. 
// { should match with }.
// ---------------------
sel_image : dialog {
  aspect_ratio = 0;
  label = "Image Buttons";
 : column {
           label = "Select image";
           alignment = centered;
           fixed_width = true;
           : row { 
               : image_button {
                 key            = "image1";
                 width          = 10;
                 aspect_ratio   = 1.0;
                 color          = 0;
                 allow_accept   = true;
               }
               : image_button {
                 key            = "image2";
                 width          = 10;
                 aspect_ratio   = 1.0;
                 color          = 0;
                 allow_accept   = true;
               }
           }
           : row { 
               : image_button {
                 key            = "image3";
                 width          = 10;
                 aspect_ratio   = 1.0;
                 color          = 0;
                 allow_accept   = true;
               }
               : image_button {
                 key            = "image4";
                 width          = 10;
                 aspect_ratio   = 1.0;
                 color          = 0;
                 allow_accept   = true;
               }
           }
        }
        ok_cancel;        
}
//------------------------------------------------------------------
backBack top