BadBit CAD
BadBit CAD LISP
BadBit CAD has its own LISP, compatible with AutoCAD's AutoLISP: it runs the routines you
already have, with expressions typed on the command line, c: commands, APPLOAD,
badbit.lsp and badbitdoc.lsp (the equivalents of acad.lsp and acaddoc.lsp).
Besides the native functions (command, getpoint, entget, ssget...), badbit-call
calls any BadBit operation through the same path as Python and AI.
LISP is only in BadBit CAD, for people coming from AutoCAD; the other programs of the BadBit suite will have MCP and Python.
The editor: BadBit Scripts
Type SCRIPTEDITOR (or SED) and Enter. It is BadBit CAD's simple LISP and Python editor:
tabs, Open, Save, Save as, Load and Run, the Output panel and
the Console. (In AutoCAD the editor is VLIDE; in BadBit, VLIDE only shows a hint
with the right name.) For a full editor, the BadBit extension for VS Code runs and debugs
.lsp files in the open BadBit (see the VS Code guide).
- Load (or Run) sends the
.lspto the LISP session, expression by expression: its functions andc:commands become available. - An error shows in the output with the line where the expression starts ("Line 12: ; error: bad argument type"); click it to go there. An unmatched parenthesis also gives the line.
- In the Console, choose LISP and type one expression at a time; the value appears right below.
Your first program
(defun c:BLOCKCOUNT (/ ss)
(setq ss (ssget "X" '((0 . "INSERT"))))
(princ (strcat "\nBlocks in the drawing: " (itoa (if ss (sslength ss) 0))))
(princ)
)Load it and type BLOCKCOUNT on the command line. The whole c: command is one undo
step.
badbit-call: the BadBit operations
(badbit-call "cad.layer.create" '(("name" . "Walls") ("color" . 1)))The first argument is the operation (the list is in the operations reference); the second, the parameters as an association list. The answer also comes back as an association list.
| Parameter in JSON | In LISP |
|---|---|
{"name": "Walls", "color": 1} | '(("name" . "Walls") ("color" . 1)) |
"start": [0, 0] | ("start" 0 0) |
"closed": true / false | ("closed" . T) / ("closed") |
| a list of objects | ("entities" (("type" . "line") ...) (("type" . "circle") ...)) |
null | :null (and :false, :true, when needed) |
(setq r (badbit-call "cad.entity.create"
'(("entities" (("type" . "line") ("start" 0 0) ("end" 100 0) ("layer" . "Walls"))))))
(setq id (cadr (assoc "ids" r))) ; the id createdEach badbit-call is one undo step. If the operation fails, nothing is left done and
the error carries a message saying what to fix; vl-catch-all-apply catches it:
(setq r (vl-catch-all-apply 'badbit-call '("cad.layer.create" (("name" . "")))))
(if (vl-catch-all-error-p r) (princ (vl-catch-all-error-message r)))Examples
Number the texts of a layer
(defun c:NUMBER (/ ss i e)
(setq ss (ssget "X" '((0 . "TEXT") (8 . "Rooms"))) i 0)
(while (and ss (< i (sslength ss)))
(setq e (entget (ssname ss i)))
(entmod (subst (cons 1 (itoa (1+ i))) (assoc 1 e) e))
(setq i (1+ i)))
(princ))Point coordinates as CSV
BadBit CAD's LISP does not write files (for security, like the rest: no access to the system). For a CSV, the program writes the lines to the BadBit Scripts Output, where you copy them; or use Python, which writes the file directly (see the Python guide).
(defun c:POINTSCSV (/ ss i p)
(setq ss (ssget "X" '((0 . "POINT"))) i 0)
(princ "\nx;y")
(while (and ss (< i (sslength ss)))
(setq p (cdr (assoc 10 (entget (ssname ss i)))))
(princ (strcat "\n" (rtos (car p) 2 3) ";" (rtos (cadr p) 2 3)))
(setq i (1+ i)))
(princ))The whole project in one call (batch)
(badbit-call "suite.batch.run"
'(("steps"
(("id" . "axes") ("operation" . "cad.layer.create") ("arguments" ("name" . "Axes")))
(("operation" . "cad.entity.create")
("arguments" ("entities" (("type" . "line") ("start" 0 0) ("end" 1000 0) ("layer" . "Axes"))))))))All of it is one undo step; if a step fails, nothing is applied.
Dynamic block and .scr script through badbit-call
The dynamic block definition changes without opening the block editor (the item indexes are
those of cad.block.definition), and a .scr runs like SCRIPT:
(badbit-call "cad.block.parameter_add"
'(("name" . "Door") ("parameter_type" . "linear")
("base_location" 0 0) ("end_location" 900 0) ("parameter_label" . "Width")))
(badbit-call "cad.block.action_add"
'(("name" . "Door") ("parameter" . "Width") ("action_type" . "stretch")
("stretch_frame" (850 -50) (950 -50) (950 2150) (850 2150))
("selection_items" 1 2 3)))
(badbit-call "suite.script.run_commands"
'(("script_text" . "LINE 0,0 100,0 100,50 \nZOOM E\n")))Each call is one undo step; the block's inserts become dynamic at once.
Asking the person
In LISP use the native functions: getpoint, getdist, getstring, getkword
with initget, entsel and ssget. The questions appear on the command line, with
object snaps; Esc cancels the program (Function cancelled).
Security
- Trusted folders (Options and APPLOAD) and SECURELOAD: a
.lspoutside them asks before loading (the same goes for the.pyfiles of BadBit Scripts); with SECURELOAD 2, only trusted folders load. - BadBit CAD's LISP does not run system programs (
startappdoes not exist) and does not load.fas,.vlx,.arxor.dllfiles. - LISP is your own code: it always works, with nothing to turn on and nothing to accept.
badbit-callacts like LISP itself, regardless of the AI (MCP) switch in Options, which is only for AI assistants.