AfraLISP - Learn AutoLISP for AutoCAD productivity

DCL Without the DCL File - Part 1

by Kenny Ramage

Have you ever wanted to load and run a DCL file without having a DCL file?

"What are you talking about Kenny?"

Easy, let's take a simple AutoLisp dialog example and tweek the coding a little bit so that our program "writes" the DCL file for us. Copy and paste the following and save it as "TEST_DCL3.LSP".

(prompt "\nType TEST_DCL3 to run...")

(defun C:TEST_DCL3 ( / dcl_id fn fname)



(setq dcl_id (load_dialog fname))
     (if (not (new_dialog "temp" dcl_id))
	 (exit )

(set_tile "name" "Enter Name Here")
(mode_tile "name" 2)
(action_tile "name" "(setq name $value)")
(action_tile "age" "(setq age $value)")
(action_tile "accept" "(val1)")

(unload_dialog dcl_id)

(alert (strcat "Your name is " name
               "\nand you are " age " years of age."))

(vl-file-delete fname)



(defun val1 ()

(if (= (get_tile "name") "Enter Name Here")
	   (set_tile "error" "You must enter a name!")
	   (mode_tile "name" 2)


(defun val2 ()

(if (< (atoi (get_tile "age")) 1)
	  (set_tile "error" "Invalid Age - Please Try Again!!")
	  (mode_tile "age" 2)


(defun create_dialog ()

(setq fname (vl-filename-mktemp "dcl.dcl"))

(setq fn (open fname "w"))

(write-line "temp : dialog { label = \"Test Dialog No 3\";
 : edit_box { label = \"Enter Your Name :\"; mnemonic = \"N\";
 key = \"name\"; alignment = centered; edit_limit = 30;
 edit_width = 30; } : edit_box { label = \"Enter Your Age :\";
 mnemonic = \"A\"; key =\"age\"; alignment = centered;
 edit_limit = 3; edit_width = 3; value = \"22\";
 } : button { key = \"accept\"; label = \"OK\";
 is_default = true; fixed_width = true; alignment = centered;
 } : errtile { width = 34; } }" fn)

(close fn)



Notice that there is no DCL file this time. Now load and run it.

Test dialog

See, what did I tell you? We've just loaded and ran a DCL file even though we haven't got one!!!

You could now compile this into a FAS file if you wished. (Hey, a FAS file with DCL - cool!)

In part 2, we'll have a closer look at this truly amazing phenomenon and have a closer look at the coding. At the same time, we'll get really clever and design ourselves a "Variable-auto-self-sizing-Dialog-Box-without-a-DCL-file".