AutoLISP and DCL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good day!
I am slowly venturing into the world of DCL and with the help of online tutorials I've written my first successful AutoLISP/DCL program.
However, I've now hit a wall and after searching around a bit I was not successful in finding help with this particular case.
AutoLISP code:
;;;;;-------- CVU --------;;;;;
;
; Goal: Provide local routine to convert quantities between basic unit types.
;
; ACAD button call CVU (none)
;
;;; by Zachary Hull
;;; 5.24.2016
;===================================;
(defun c:cvu ( / adoc eFlag uList *error* uI u1 u2 uR tw th bw bh)
(vl-load-com)
(vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(setvar "cmdecho" 0)
(setq eFlag 1)
(setq uList
(list
"in" "inches"
"ft" "feet"
"mm" "millimeters"
"cm" "centimeters"
"me" "meters"
) ;list
)
(defun *error* (msg)
(if (member msg '("quit / exit abort" "Conversion failed." "*Cancel*"))
(progn
(setvar "cmdecho" 1)
(vla-endundomark adoc)
(cond
((= eFlag 1) (princ "\n <!> Routine aborted <!> "))
((= eFlag 2) (princ "\n <!> Routine finished <!> "))
) ;cond
) ;progn
) ;if
) ;*error*
(defun conv1 ()
(strcat (rtos uI) " " u1 " = " (rtos (cvunit uI u1 u2)) " " u2)
)
(if (not (setq CVU_DCL_ID (load_dialog "CVU.DCL")))
(progn (princ "\n\033\n Verify CVU.dcl file path ")(exit))
(if (not (new_dialog "main" CVU_DCL_ID))
(progn (princ "\n\033\n Verify CVU.DCL 'main : dialog' naming definition ")(exit))
(progn
;*********************** Bottom color bar **********************;
;
(setq bw (dimx_tile "botBar")) ;
(setq bh (dimy_tile "botBar")) ;
(start_image "botBar") ;
(fill_image 0 0 bw bh 5) ;
(end_image) ;
;
;******************** Unit conversion types ********************;
;
(action_tile "f_In" "(setq u1 \"in\")") ;
(action_tile "f_Ft" "(setq u1 \"ft\")") ;
(action_tile "f_Mm" "(setq u1 \"mm\")") ;
(action_tile "f_Cm" "(setq u1 \"cm\")") ;
(action_tile "f_Me" "(setq u1 \"me\")") ;
;
(action_tile "t_In" "(setq u2 \"in\")") ;
(action_tile "t_Ft" "(setq u2 \"ft\")") ;
(action_tile "t_Mm" "(setq u2 \"mm\")") ;
(action_tile "t_Cm" "(setq u2 \"cm\")") ;
(action_tile "t_Me" "(setq u2 \"me\")") ;
;
;***************************************************************;
(action_tile "Quantity" "(setq uI (distof $value))")
(set_tile "result" "(conv1)")
(action_tile "done" "(done_dialog 1)") ;"Exit"
(action_tile "conv" "(done_dialog 2)") ;"Convert"
(setq ddiag (start_dialog))
(unload_dialog CVU_DCL_ID)
(cond
((= ddiag 1)
(progn (princ "\n Closing dialog box ")(setq eFlag 2)(exit))
)
((= ddiag 2)
(progn
(princ "\n Selected 'Convert' ")
(if (or (= uI nil)(= u1 nil)(= u2 nil))
(progn
(cond
((= uI nil) (princ "\n\033\n 'Base' value empty"))
((= u1 nil) (princ "\n\033\n 'Base' unit not selected"))
((= u2 nil) (princ "\n\033\n 'Desired' unit not selected"))
) ;cond
(exit)
) ;progn
) ;if
(setq uR (cvunit uI u1 u2))
(if (member u1 uList)
(setq u1 (nth (1+ (vl-position u1 uList)) uList))
(progn (princ "\n\033\n see variable 'uList'")(exit))
) ;if
(if (member u2 uList)
(setq u2 (nth (1+ (vl-position u2 uList)) uList))
(progn (princ "\n\033\n see variable 'uList'")(exit))
) ;if
(alert (strcat (rtos uI) " " u1 " = " (rtos uR) " " u2))
(princ (strcat "\n * "(rtos uI) " " u1 " = " (rtos uR) " " u2 " * "))
) ;progn
)
) ;cond
) ;progn
) ;if
) ;if
;----;
;(if (setq uI (getreal "\n\033\n Quantity to convert: "))
;
; (progn
; (initget "in ft mm cm me")
; (setq u1 (getkword "\n\033\n First unit type [in/ft/mm/cm/me]: "))
; (initget "in ft mm cm me")
; (setq u2 (getkword "\n\033\n Second unit type [in/ft/mm/cm/me]: "))
; (setq uR (cvunit uI u1 u2))
; ) ;progn
;
; (progn (princ "\n\033\n Quantity required ")(exit))
😉 ;if
;
;(if (member u1 uList)
;(setq u1 (nth (1+ (vl-position u1 uList)) uList))
;(progn (princ "\n\033\n see routine CVU, unit value not included in variable 'uList'")(exit))
😉 ;if
;
;(if (member u2 uList)
;(setq u2 (nth (1+ (vl-position u2 uList)) uList))
;(progn (princ "\n\033\n see routine CVU, unit value not included in variable 'uList'")(exit))
😉 ;if
;
;(alert (strcat "\n " (rtos uI) " " u1 "\n\t = \n\t\t" (rtos uR) " " u2 "."))
;(setq eFlag 2)
;(exit)
(princ)
) ;cvu
;********************************** End of File **********************************;
DCL code:
main : dialog
{label = "CVU - Convert Units";
: boxed_row
{
label = "Provide 'Base' quantity in text box";
: edit_box
{
key = "Quantity";
label = "Quantity";
edit_width = 15;
value = "";
initial_focus = true;
}
: button
{
key = "conv";
label = "Convert";
is_default = false;
}
} //quantity & convert
: boxed_row
{
label = "Conversion Results";
fixed_height = true;
height = 2;
: text
{
key = "result";
value = "Select 'Convert' to display results...";
}
} //results box
: boxed_row
{
label = "Unit Conversion Options";
: radio_column
{
key = "unit1";
label = "'Base' Unit";
fixed_width = true;
width = 19;
: radio_button
{
label = "Inches";
key = "f_In";
mnemonic = "i";
}
: radio_button
{
label = "Feet";
key = "f_Ft";
mnemonic = "f";
}
: radio_button
{
label = "Millimeters";
key = "f_Mm";
mnemonic = "m";
}
: radio_button
{
label = "Centimeters";
key = "f_Cm";
mnemonic = "c";
}
: radio_button
{
label = "Meters";
key = "f_Me";
mnemonic = "e";
}
} // radio column
: radio_column
{
key = "unit2";
label = "Desired Unit";
fixed_width = true;
width = 19;
: radio_button
{
label = "Inches";
key = "t_In";
mnemonic = "i";
}
: radio_button
{
label = "Feet";
key = "t_Ft";
mnemonic = "f";
}
: radio_button
{
label = "Millimeters";
key = "t_Mm";
mnemonic = "m";
fixed_width = true;
}
: radio_button
{
label = "Centimeters";
key = "t_Cm";
mnemonic = "c";
}
: radio_button
{
label = "Meters";
key = "t_Me";
mnemonic = "e";
}
} // radio column
} // units conversion options
spacer_1;
: row
{
: button
{
key = "done";
label = "Exit";
is_default = false;
is_cancel = true;
}
} //Exit box
: image
{
key = "botBar";
height = 1.0;
width = 1.0;
}
} // main
I've highlited the parts of both pieces of code in RED that are related to the issue. When I comment this lines out, the program executes without error.
Currently, the program takes three inputs (based upon the CVUNIT function) and the result (if all three inputs are 'acceptable') will be displayed using the ALERT function and the dialog box closes.
What I am trying to figure out is how to keep the dialog box 'open' after selecting the 'Convert' button and by selecting the 'Convert' button, display what would be displayed by the ALERT function as the value of the "results" text in the dialog box. I want the dialog box to ONLY close after the 'Exit' button is selected.
Does this make sense?