List Variables/Functions.
It is very important when writing AutoLISP routines to declare all
your Local Variables. This prevents your variables stepping on other
variables of the same name defined from other routines.
It often happens though, that on completion of your application, it can be
quite difficult to remember and locate all the variables that you have
used. This application will list all the un-declared variables and all
functions used within your routine.
If you need help with Functions and Local/Global Variables, then refer to
the DEFUN Function Tutorial.
Usage
I have included two sample AutoLISP files with this application, to
demonstrate
how to run and use 'ListVar.Lsp.
First of all, ensure that ListVar.Lsp and ListVar.Dcl are in your
AutoCAD
support path.
Now type (load "ListVar") at the command prompt.
A message will appear prompting you to type INIT to run the application.
Do just that. A dialogue box will appear that looks like this :
Read the instructions carefully.
Now load and run Sample.Lsp. The AutoLisp coding is as follows :
(defun c:sample ()
(setq l1 10.0
l2 20.0
l3 30.0
l4 40.0
l5 50.0
l6 (fDTR 45)
g1 "Global1"
g2 "Global2"
);setq
(princ)
);defun
(defun fDTR (x)
(* PI (/ x 180.0))
);defun
(princ)
This is a very simple routine that basically defines 8 variables, 6 of
which we want to declare Local and 2 of which we would like to declare as
Global. We have also defined a sub-function that converts degrees to
radians.
After running this routine type 'ListVar' at the command line.
Another dialogue will appear that looks like this :
As you can see, all the functions and variables used within
the routine are listed in the list box.
To keep a permanent record of the list, select the 'Print to File' button.
This will print the list to the file 'ListVar.Txt :
C:SAMPLE
FDTR
G1
G2
L1
L2
L3
L4
L5
L6
You can use this file to cut and paste the variables that you want to
declare as Local into your AutoLisp file.
Now, re-run 'INIT' then load and run Sample1.Lsp.
Here is the coding for Sample1.Lsp.
(defun c:sample1 ( / L1 L2 L3 L4 L5 L6)
(setq l1 10.0
l2 20.0
l3 30.0
l4 40.0
l5 50.0
l6 (fDTR 45)
g1 "Global1"
g2 "Global2"
);setq
(princ)
);defun
(defun fDTR (x)
(* PI (/ x 180.0))
);defun
(princ)
As you can see, we have declared all the Local Variables.
Now run 'ListVar' again. The dialogue should now look like this.
Do you see that the Local Variables that we declared are now
not listed.
Using this application you can produce a list of all local variables that
need to be declared when you have written a new AutoLisp routine or, you
can check your existing routines for variables that you may have missed.
To download this application including the sample AutoLisp files, then
just Click Here. (30 Kb) |