How to Use LISP in BricsCAD
Last updated: July 20, 2026. Verified against Octave’s official V26 documentation.
Quick answer: BricsCAD’s LISP implementation runs existing AutoLISP code with virtually no differences, your code loads and behaves identically. Migrating mainly involves a few setup steps: renaming auto-launch files, enabling auto-launch, and pointing BricsCAD at your support folders.
Migrating LISP Routines from AutoCAD
If you auto-launch programs using Acad.lsp or Acaddoc.lsp, rename them to on_start.lsp or on_doc_load.lsp respectively; on_doc_load.lsp is the better choice of the two.
To enable auto-launching, set ACADLSPASDOC to 1, or toggle the equivalent option in Settings > Program options > System.
Add your support folders to the Files search path, found in Settings > Program Options > Files. It’s recommended to use paths added this way, and/or a location one level below the current project folder. A good habit is validating a file exists with findfile before loading it:
(if (findfile "custom-code.lsp") (load "custom-code"))
DEFUN (define function) names a function to match one inside on_doc_load.lsp, redefining the calling function when it launches.
A Sample Drawing Setup Routine
This routine can be adapted with minimal changes:
(defun C:MYSETUP ( / ) ;define the command line function "mysetup"
(setvar "cmdecho" 0)
(command "_audit" "_y") ;audit current drawing
(command "_-purge" "_all" "*" "_n") ;purge all unused styles, etc
(command "_-layer" "_m" "1" "_c" "1" "" "") ; create layer "1" color "1"
(command "_-layer" "_m" "2" "_c" "2" "" "")
(command "_-layer" "_m" "3" "_c" "3" "" "")
(command "_-layer" "_m" "4" "_c" "4" "" "")
(command "_viewres" "_y" "20000") ;set view resolution to maximum
(setvar "filedia" 1) ;turn file dialogs on
(setvar "attdia" 1) ;turn attribute dialogs on
(setvar "attreq" 1) ;enable attribute editing on placement
(setvar "cecolor" "bylayer") ;set current color bylayer
(setvar "clayer" "0") ;set current layer to "0"
(setvar "maxsort" 5000) ;set maximum layer sort to 5,000
(command "_zoom" "_e" "_zoom" "0.95x") ;zoom extents, then out a little
(setvar "cmdecho" 1)
(princ)
)
Each line here could be typed individually at the Command line, but wrapping them in defun makes the whole routine callable from a menu or by typing its name, mysetup, at any point. Without defun, the code would only run once, immediately when loaded by filename.
A few things worth understanding about this routine:
- Commands preceded by a hyphen (
-layer,-purge) run their Command line version, preventing a dialog box from opening, the same convention covered elsewhere in this hub. - Always use English command and option names in LISP code; non-English names can fail on localized BricsCAD versions.
- Running an audit followed by a purge is good practice when opening drawings from others, to clear out unused items. Purge can be run multiple times to catch nested unused items too:
(repeat 3 (command "-purge" "all" "*" "n")). Purge runs before the new empty layers are created here, since running it afterward would remove those layers too. - The layer-creation commands could be combined into a single statement, but keeping them on separate lines makes the routine easier to read.
maxsortcontrols the maximum number of entries sorted in a dialog box; its default of 1,000 can be too low for larger modern projects, if layer names aren’t sorting alphabetically, this setting is a likely cause.
A More Versatile Layer Maker Using an External File
Rather than hard-coding layer names, this variant reads them from a simple text file, Layers.txt, created with any text editor like Notepad, one layer name per line. findfile searches the current directory first, then each support folder in sequence, so you can keep a default version in your support path and alternative versions in individual project folders.
(if (not (findfile "Layers.txt")) ;"not" = looking for no result from findfile
(alert "Can't find Layers.txt!") ;No file? Yell at the user and exit!
(progn ;Otherwise, do the stuff in the progn group
(setq layerfile (open (findfile "Layers.txt") "r")) ;open layers.txt to "read"
(while (setq layername (read-line layerfile)) ;while reading each line, store the text to layername
(command "-layer" "m" layername "") ;make layer with the layername
) ;end the while loop
(close layerfile) ;close the Layers.txt file
) ;end the progn
) ;end the if
For more detail, Octave publishes a full BricsCAD V26 Developer Reference on its developer site.
Frequently Asked Questions
Do I need to rewrite my existing AutoLISP code to use it in BricsCAD? No, it loads and runs with identical functionality; migration mainly involves renaming auto-launch files and a few setup steps, not rewriting the code itself.
Why should I rename Acaddoc.lsp to on_doc_load.lsp instead of Acad.lsp to on_start.lsp? Both work, but on_doc_load.lsp is the recommended choice of the two for auto-launching your programs.
Why do some commands in these LISP routines have a hyphen in front of them? The hyphen runs the Command line version of that command, preventing its dialog box from opening, useful when a routine needs to run unattended.
What does the maxsort setting actually control? The maximum number of entries sorted in a dialog box; its default of 1,000 can be too low for large modern projects, showing up as layer names that won’t sort alphabetically.