KufCad

KufLISP

Ribbon: Manage ▸ Applications ▸ Load ApplicationCommand: APPLOADAlias: LSP

KufLISP runs AutoLISP applications as .lsp source (compiled .fas / .vlx files do not run). It is the long-standing CAD automation route and is compatible with most LISP routines you find online.

Loading a LISP file (APPLOAD)

Click Manage ▸ Applications ▸ Load Application or type APPLOAD.

APPLOAD
Figure 14.1 — The top of the Load/Unload Applications dialog: the Load… button 1 and the list of loaded programs 2.
  1. Click Load… and pick a .lsp file.
  2. The program appears under Loaded in this session. The commands it defines ((defun c:NAME …)) can be typed on the command line like built-in ones.
  3. To load it every time KufCad starts, add it to the Startup Suite (Add…; Remove to drop it).

Security

APPLOAD security
Figure 14.2 — Phần Security của hộp thoại: SECURELOAD 1 / 2 / 0 và Trusted folders.

LISP can do anything to your computer (delete files, start programs…), so KufCad uses an AutoCAD-like scheme:

SECURELOADMeaning
1 (default)Ask before loading a file outside the trusted folders
2Load only from trusted folders
0Load any file without asking (unsafe)

Trusted folders: ~/.kufcad/support (always trusted) and the folders you list under Trusted folders (separated by ;). The auto-loaded acad.lsp and acaddoc.lsp are only looked for in trusted folders — never next to a drawing you received from someone else (how LISP viruses spread). If KufCad asks to load a file you did not open yourself, choose No.

Your first command

Save the following as hello.lsp, load it with APPLOAD, then type HELLO:

(defun c:HELLO ()
  (princ "\nXin chao KufCad!")
  (princ))
HELLO
Figure 14.3 — The newly defined HELLO command run on the command line.

A drawing example: the STAR command below draws a five-point star with the LINE command.

(defun c:STAR ()
  (command "_LINE" (list 0 4) (list 1 1) (list 4 1) (list 2 -1) (list 3 -4)
           (list 0 -2) (list -3 -4) (list -2 -1) (list -4 1) (list -1 1) (list 0 4) "")
  (princ "\nStar drawn.")
  (princ))
STAR
Figure 14.4 — The result of the STAR command.

Type ( on the command line to run a LISP expression at once, for example (+ 1 2) returns 3, or (sq 7) returns 49 after (defun sq (x) (* x x)). The sample set in KufCad's samples/lisp folder: demo.lsp (STAR, L2, GRID…), dcl_callbacks.lsp, reactor_area.lsp, vlax_layers.lsp, xdata_tags.lsp, grread_circle.lsp.

Commonly used functions checked: defun, setq, command, entmake, entget, assoc, ssget, sslength, mapcar, foreach, strcat, itoa, rtos, vl-string-search, getpoint, getreal, getstring. The ActiveX vla-* / vlax-* functions are available too.