Using scripts to run LISP or VBA routines and setting variables. Post 7 in series “AutoCAD Cleanup”

Run LISP routines or VBA macros

You can batch process multiple files using scripts which call LISP or VBA macros.

Example: the following script runs a lisp routine to delete layer filters. It loads the Layerfilterdelete.lsp file, then deletes layer filters using a command LFD defined in the routine.

(LOAD “C:\\AU-CLEANUP\\EXERCISES\\SCRIPTING\\LAYERFILTERDELETE.LSP”)
 LFD
 QSAVE
 blank line

Layerfilterdelete.lsp was downloaded from AcadX.com, author: R. Robert Bell.

(DEFUN C:LAYERFILTERSDELETE () (VL-LOAD-COM) (VL-CATCH-ALL-APPLY ‘(LAMBDA () (VLA-REMOVE (VLA-GETEXTENSIONDICTIONARY (VLA-GET-LAYERS (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)))) “ACAD_LAYERFILTERS”))) (PRINC “\NALL LAYER FILTERS HAVE BEEN DELETED.”) (PRINC)) (DEFUN C:LFD () (C:LAYERFILTERSDELETE))

If a routine expects a user response, you need to script the response also.

Set up Variables

You can use scripts to set up variables. Here is an example where you set some variables you need for your environment. Keep in mind that not all variables are saved in files, some are saved in the registry, and some cannot be saved at all.

ATTMODE 1
 ATTDIA 1
 DIMASSOC 2
 FILLETRAD 0
 FILLMODE 1
 MIRRTEXT 0
 PDMODE 0
 VISRETAIN 1
 XEDIT 0
 QSAVE
 blank line