BricsCAD LISP Automation: Custom Commands and Batch Processing Scripts
A developer-focused guide to writing and deploying LISP automation routines in BricsCAD, covering command definition, entity selection methods, and batch processing across multiple DWG files.

BricsCAD LISP Automation: Custom Commands and Batch Processing Scripts
LISP automation in BricsCAD is one of the most powerful ways to eliminate repetitive tasks and enforce CAD standards across a team. BricsCAD's LISP engine is compatible with AutoCAD Visual LISP, which means most existing routines work with minimal modification. This guide covers practical LISP development — from defining custom commands to building batch processors that operate on hundreds of DWG files unattended.
Setting Up the LISP Development Environment
BricsCAD includes a built-in LISP IDE called BLADE (BricsCAD LISP Advanced Development Environment). To launch it:
- Type
BLADEat the command line - The IDE opens with a code editor, console, and debugger
- Create a new
.lspfile or open an existing one
BLADE provides syntax highlighting, auto-completion for BricsCAD-specific functions, breakpoints, watch variables, and step-by-step execution. It is significantly more capable than the legacy Visual LISP IDE in AutoCAD.
Auto-Loading LISP Files
To have LISP routines load automatically on startup:
- Place
.lspfiles in a folder included inSRCHPATH(check withSRCHPATHcommand) - Add the file path to
LOADBE(Load on Begin) or use theSTARTUP.lspfile - Alternatively, use
APPLOADand check "Load on Startup" for each file
For enterprise deployment, create a single startup.lsp that loads all project routines:
;; startup.lsp - Central loader for all custom routines
(load "layer-tools.lsp")
(load "batch-plot.lsp")
(load "title-block-update.lsp")
(princ "\nCustom routines loaded successfully.")
(princ)
Defining Custom Commands
Use defun with the c: prefix to create command-line commands:
;; Define a command to freeze all layers except the current one
(defun c:FreezeAll (/ ss i ent layname currentlay)
(setq currentlay (getvar "CLAYER"))
(setq ss (ssget "X" '((8 . "~*"))))
(if ss
(progn
(setq i 0)
(while (< i (sslength ss))
(setq ent (entget (ssname ss i)))
(setq layname (cdr (assoc 8 ent)))
(if (/= layname currentlay)
(command "_.-LAYER" "_F" layname "")
)
(setq i (1+ i))
)
(princ (strcat "\nFroze all layers except " currentlay))
)
(princ "\nNo entities found.")
)
(princ)
)
Command Naming Conventions
- Use a consistent prefix for your firm's commands (e.g.,
c:XX-FreezeAllwhereXXis your company abbreviation) - Keep command names under 15 characters for command-line compatibility
- Avoid names that conflict with built-in BricsCAD commands
Entity Selection Strategies
Efficient entity selection is the foundation of performant LISP routines. BricsCAD supports all standard selection methods:
Selection Set with Filters
;; Select all text entities on the "NOTES" layer
(setq ss (ssget "X" '((0 . "TEXT") (8 . "NOTES"))))
Selection by DXF Group Codes
Common DXF codes for filtering:
0— Entity type (TEXT, LINE, CIRCLE, LWPOLYLINE, etc.)8— Layer name62— Color number6— Linetype name67— Model space (0) vs paper space (1)410— Layout name
Wildcard Layer Selection
;; Select all entities on layers starting with "A-"
(setq ss (ssget "X" '((8 . "A-*"))))
Batch Processing Multiple DWG Files
One of the most valuable LISP patterns is batch processing — running a routine across dozens or hundreds of DWG files without manual intervention. BricsCAD supports this through the SDI (Single Document Interface) mode and the _.OPEN / _.SAVE / _.CLOSE command sequence.
Batch File Processor Template
;; batch-process.lsp - Process multiple DWG files
(defun c:BatchProcess ( / filelist filepath dwgpath filename fulldoc)
;; Get list of DWG files from a directory
(setq dwgpath (getstring "\nEnter folder path: "))
(setq filelist (vl-directory-files dwgpath "*.dwg" 1))
;; Save current drawing state
(setq fulldoc (vla-get-ActiveDocument (vlax-get-acad-object)))
;; Process each file
(foreach filename filelist
(setq filepath (strcat dwgpath "\\" filename))
(princ (strcat "\nProcessing: " filename))
;; Open the file
(command "_.OPEN" filepath)
;; --- Insert your processing code here ---
;; Example: Purge all unused layers
(command "_.-PURGE" "_LA" "*" "_N")
(command "_.-PURGE" "_ST" "*" "_N")
(command "_.AUDIT" "_Y")
;; --- End processing code ---
;; Save and close
(command "_.QSAVE")
(command "_.CLOSE")
)
(princ "\nBatch processing complete.")
(princ)
)
Running Batch Processing Safely
Before running batch operations:
- Back up all files — batch routines modify files in place
- Test on a sample folder — copy 3-5 files to a test directory and verify results
- Set
SDIto 0 — BricsCAD must be in multi-document mode for batch open/close to work correctly - Disable dialog boxes — set
FILEDIAto 0 andCMDDIAto 0 so file dialogs do not interrupt the batch - Log results — add
(princ)statements that write to a log file for post-run verification
Error Handling in LISP Routines
Robust error handling prevents a single failure from crashing the entire routine. Use *error* function override:
(defun c:SafeRoutine ( / olderr oldcmdecho)
;; Save system state
(setq oldcmdecho (getvar "CMDECHO"))
(setq olderr *error*)
;; Define custom error handler
(defun *error* (msg)
(princ (strcat "\nError: " msg))
(setvar "CMDECHO" oldcmdecho)
(setq *error* olderr)
(princ)
)
;; Set safe environment
(setvar "CMDECHO" 0)
;; Main routine code here
(command "_.ZOOM" "_E")
;; Restore state
(setvar "CMDECHO" oldcmdecho)
(setq *error* olderr)
(princ)
)
Working with External Data
Reading CSV Files for Attribute Updates
;; Read a CSV file and update title block attributes
(defun c:UpdateTitleBlock ( / csvfile line data)
(setq csvfile (open (getfiled "Select CSV file" "" "csv" 8) "r"))
(if csvfile
(progn
(while (setq line (read-line csvfile))
(setq data (parse-csv line))
;; data is a list: (dwgname title project date)
(update-attributes (nth 0 data) (nth 1 data) (nth 2 data) (nth 3 data))
)
(close csvfile)
(princ "\nTitle blocks updated.")
)
(princ "\nNo file selected.")
)
(princ)
)
Deployment Across a Team
To deploy LISP routines to multiple users:
- Create a network share (e.g.,
\\server\cad-tools\lisp\) - Add the share to
SRCHPATHon each workstation via a profile (.arg) file - Create a master
startup.lspon the network share that loads all routines - Use
PROFILEimport to distribute the profile with correct support paths - Version control the LISP files using Git or SVN for change tracking
BRX API for Advanced Development
When LISP isn't sufficient for your automation needs in BricsCAD, the BRX (BricsCAD Runtime eXtension) API provides a C++ development path similar to AutoCAD's ObjectARX. BRX gives you direct access to the drawing database, graphics system, and command registration framework. You can create custom commands that appear in the command line, build dialog boxes using BRX UI tools, and implement real-time entity manipulation that responds to user interaction. The BRX SDK is available from Bricsys and includes documentation, sample projects, and header files. Development is done in Visual Studio on Windows or GCC on Linux. The key advantage of BRX over LISP is performance — BRX programs run as compiled native code, making them orders of magnitude faster than interpreted LISP for computationally intensive tasks. BRX also provides access to features that LISP can't reach: custom entity types, direct graphics pipeline manipulation, and integration with external databases. For teams migrating from AutoCAD, BRX code is similar to ObjectARX code and can often be ported with moderate effort, making BricsCAD the strongest AutoCAD alternative for teams with existing C++ development investments.
Conclusion
LISP automation in BricsCAD is a practical, high-ROI investment for any team doing repetitive CAD work. The combination of BLADE for development, defun c: for custom commands, and batch processing loops for multi-file operations covers the majority of automation needs. By following the error handling patterns and deployment strategies in this guide, you can build a robust LISP toolkit that saves hours of manual work across your organization.
Source Verification
More Bricscad Guides
workflow
BricsCAD BIM Modeling: Walls, Slabs, and Roof Tools from 2D Plans
14 min read
workflow
BricsCAD to AutoCAD DWG Compatibility: Seamless Workflow Transition Guide
11 min read
deployment
BricsCAD Licensing and Deployment: Network Licenses, Silent Install, and Activation Troubleshooting
11 min read
performance
BricsCAD Performance Optimization: Large Files, Hardware Acceleration, and System Tuning
12 min read
Related workflow Guides
Similar workflow content for other CAD tools
Abaqus
•workflow
Abaqus Composite Material Analysis: Laminate Modeling, Damage, and Progressive Failure
12 min read
Abaqus
•workflow
Abaqus Contact Mechanics: General Contact, Friction, and Wear Simulation
12 min read
Abaqus
•workflow
Abaqus/Explicit Dynamic Analysis: Crash, Drop Test, and High-Speed Impact Simulation
13 min read
Abaqus
•workflow
Abaqus Fracture Mechanics: XFEM, Cohesive Zone, and J-Integral for Crack Propagation
12 min read