AfraLISP - Learn AutoLISP for AutoCAD productivity

Application Data

by Kenny Ramage

Have you ever looked at the ACAD14.CFG (Autocad Configuration) file?

This is simply a text file divided into sections. The only section that you have control over is the [AppData] section. Let's do something with it.

Say you wanted to store 2 bits of information that you use in one of your AutoLisp routines. You would store them like this :

(setcfg "appdata/test/bolt" "M24")
(setcfg "appdata/test/length "90")

After (setcfg must come "appdata" followed by your application name, which must be unique. Following this is the variable tag and then the information you wish to store. If you open the ACAD14.CFG file, this is what the [AppData] section will look like :

[AppData/test]
bolt=4
length=90

To retrieve this data you would use the following syntax :

(setq a (getcfg "appdata/test/bolt"))
(setq b (getcfg "appdata/test/length"))

This would set a to "M24" and b to "90". Now this is great, I hear you say, but were would you use it. Here's a good example for you :

Say you've written a routine that you would like other people to use on a trial basis, say 5 times. After the 5 times they either pay up, or the routine ceases to work.

What we are going to do is first write a simple routine.
Then we will write a sub-routine that stores the number of times the routine is run in the [AppData] section. Next, we will check the number of times it has been run and then decide whether the limit has expired or not. Have a look :

;Main function
 
(defun c:test8 ()
	(register)
	(if flagset
		(alert "\nThe programme will now run.")
        );if
   (princ)
)defun
 
;Sub-function
 
(defun register ()
	(setq v1 (getcfg "AppData/CadKen/test"))
           (if (= v1 nil)
             (progn
                 (setcfg "AppData/CadKen/test" "1")
                 (setq v1 (getcfg "AppData/CadKen/test"))
             );progn
           );if
        (setq v2 5)
        (setq v1 (atoi v1))
           (if (< v1 v2)
             (progn
                (setq v1 (+ v1 1))
        	  (cond
         		((= v1 1)  (setcfg "AppData/CadKen/test" "1"))
	 		((= v1 2)  (setcfg "AppData/CadKen/test" "2"))
	 		((= v1 3)  (setcfg "AppData/CadKen/test" "3"))
	 		((= v1 4)  (setcfg "AppData/CadKen/test" "4"))
	 		((= v1 5)  (setcfg "AppData/CadKen/test" "5"))
       		  );cond
       		  (setq v3 v1)
       		  (setq v3 (rtos (- v2 v1)))
       		  (alert (strcat "\n You Have " v3 " more Loadings Left"))
		  (setq flagset T)  
     	    );progn
	    (progn
       		(alert "\nEvalution Period has Expired
	       		\n   Contact Kenny Ramage
	       		\n      ndbe51d1@db.za
	       		\n     For Licensed Copy")
		(setq flagset nil)
	    );progn
     	);if
    (princ)    
);defun
(princ)  

This is a very simple but usefull routine that demonstrates the use of [AppData]. You would still, of course, have to encrypt or compile your routine to stop the user simply changing the variable that contains the usage control number. If you would like the source code, I have included it here.