AutoLISP is one of the oldest and easiest ways of extending AutoCAD, but did you ever wonder what functions are currently defined or which global variables are already set?
The ATOMS-FAMILY (not the Adams Family) function returns a list of all the symbols, global variables, and functions currently defined for use by AutoLISP. You can also use the function to check to see if a specific symbol, global variable, and/or function is currently defined or set. This ability to check for the existence of previous definitions is helpful if you want to see which functions are exposed before loading an AutoLISP file.
Syntax:
(atoms-family format [symbol_list])
format - Determines how the values in the returned list are formated. Valid values are 0 for Symbols or 1 for Strings.
symbol_list - Optional; List of symbols, variables, or functions to search for.
For example:
Entering (atoms-family 1) at the Command prompt returns a long list that might look like the following.
("ACTOOLBARDOCKBOTTOM" "ACET-VAR-SETVAR" "ACVIEWPORT4" "AC3IN_1FT" "VLA-ADDBOX"
...
"VLA-GET-SHOWPLOTSTYLES" "VLA-GET-NUMCELLSTYLES" "AI_RETURN" "C:SAVEALL")
The list returned is useful, but can take a while to sort through as it is not in alphabetical order or an order that will make much sense.
As mentioned previously, you can use the ATOMS-FAMILY function to test for the existence of a symbol, function, or variable by passing in a list of the items you want to see exist. This check can be helpful if your routines depend on the definition of a function from a previously loaded file. If the check fails, you can then load the necessary file.
For example:
Entering (atoms-family 1 '("getpoint" "getpoints" "PI")) at the Command prompt returns a long list that might look like the following.
("GETPOINT" nil "PI")
The following is some sample code that exports the symbols, functions, global variables, and commands that are defined via AutoLISP or exposted to AutoLISP from .NET/ObjectARX. The command that is defined creates four lists, and then sorts each before exporting the definitions out. To determine the type of definition in the list returned by ATOMS-FAMILY, I used the TYPE function and to see if a definition is prefixed with "C:" to determine which functions at like a command at the Command prompt.
After the command is ran, the number of symbols, functions, global variables, and commands is output to the Command Line window, and a file named LspDumpFile.log is created under the root of the C drive. You can do a comparison AutoLISP definitions by exporting out what is currently defined, renamed the file created, load an AutoLISP file, and then before a second export. To do the comparison between the files, you can use a utility like WinDiff or UltraEdit or even MS Word.
(defun c:LISPDumpFile ( / afList nSyms nFuncs nCmds nVars
lstSyms lstFuncs lstCmds lstVars
item fp)
(setq afList (atoms-family 1))
(setq nSyms 0 nFuncs 0 nCmds 0 nVars 0
lstSyms nil lstFuncs nil lstCmds nil lstVars nil)
(foreach item aflist
(progn
(cond
((= (type (eval (read item))) 'SYM)
(progn
(setq nSyms (1+ nSyms))
(if (/= lstSyms nil)
(setq lstSyms (append lstSyms (list item)))
(setq lstSyms (list item))
)
)
)
((and (= (type (eval (read item))) 'SUBR) (/= (substr (strcase item) 1 2) "C:"))
(progn
(setq nFuncs (1+ nFuncs))
(if (/= lstFuncs nil)
(setq lstFuncs (append lstFuncs (list item)))
(setq lstFuncs (list item))
)
)
)
((and (= (type (eval (read item))) 'SUBR) (= (substr (strcase item) 1 2) "C:"))
(progn
(if (/= (strcase item) (strcase "c:LISPDumpFile"))
(progn
(setq nCmds (1+ nCmds))
(if (/= lstCmds nil)
(setq lstCmds (append lstCmds (list item)))
(setq lstCmds (list item))
)
)
)
)
)
((or (= (type (eval (read item))) 'REAL)
(= (type (eval (read item))) 'INT)
(= (type (eval (read item))) 'LIST)
(= (type (eval (read item))) 'PICKSET)
(= (type (eval (read item))) 'ENAME)
(= (type (eval (read item))) 'VLA-OBJECT)
(= (type (eval (read item))) 'FILE)
(= (type (eval (read item))) 'VARIANT)
(= (type (eval (read item))) 'STR))
(progn
(setq nVars (1+ nVars))
(if (/= lstVars nil)
(setq lstVars (append lstVars (list item)))
(setq lstVars (list item))
)
)
)
)
)
)
;; Output details about defined Symbols and Functions
(prompt (strcat "\nAutoLISP Symbols and Functions count: "
"\nSymbols - " (itoa nSyms)
"\nFunctions - " (itoa nFuncs)
"\nGlobal Variables - " (itoa nVars)
"\nCommands - " (itoa nCmds))
)
(setq fp (open "c:\\LspDumpFile.log" "w"))
(write-line "Symbols" fp)
(setq lstSyms (acad_strlsort lstSyms))
(foreach item lstSyms
(write-line item fp)
)
(write-line "" fp)
(write-line "Functions" fp)
(setq lstFuncs (acad_strlsort lstFuncs))
(foreach item lstFuncs
(write-line item fp)
)
(write-line "" fp)
(write-line "Global Variables" fp)
(setq lstVars (acad_strlsort lstVars))
(foreach item lstVars
(write-line item fp)
)
(write-line "" fp)
(write-line "Commands" fp)
(setq lstCmds (acad_strlsort lstCmds))
(foreach item lstCmds
(write-line item fp)
)
(close fp)
(princ)
)
The following is a sampling of the LOG file that is generated.
Symbols
*LAST-VALUE*
:AUTOLISP
...
Functions
-
*
*ERROR*
*MERR*
...
Global Variables
AC0DEGREES
AC1_1
AC1_10
...
Commands
C:-BLOCKREPLACE
C:-BLOCKTOXREF
C:-CDORDER
...
Sincerely,
Lee
External Link of Interest:
Commands that “work” in the AutoCAD 2013 Core Console - Through the Interface (by Kean Walmsley)
Comments