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".

;AUTOLISP CODING STARTS HERE
(prompt "\nType TEST_DCL3 to run...")

(defun C:TEST_DCL3 ( / dcl_id fn fname)

(vl-load-com)

(create_dialog)

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

(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)")

(start_dialog)
(unload_dialog dcl_id)

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

(vl-file-delete fname)

(princ)

);defun
-----------------------

(defun val1 ()

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

);defun
-------------------

(defun val2 ()

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

);defun
-------------------

(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)

);defun
-------------------

(princ)
;AUTOLISP CODING ENDS HERE

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".