LISP FORMAT

 

LISP is the second oldest programming language, next to FORTRAN.  LISP is an anachronism for LISt Programming.  LISP is considered an artificial intelligence language.  The main function of LISP is to construct, organize, sort, and pass along lists.  The main list used in graphics is the list to define a point: (X,Y,Z).

 

;; a semi-colon allows for unrecognized remarks within a LISP program

;; LISP always returns an value, even if it is zero or a “carriage return”

;; Each LISP function is constrained within a pair of parenthesis (function), and they can be nested (( first function)(second function)(third function))

 

(defun NAME (local variables\global variables) ;; C:NAME executed as an AutoCAD command

            (setq nnn (getvar “NNN”)) ;; create variable, retrieve and store AutoCAD variable value

(setvar “NNN” nn) ;; set necessary conditions and variables

            (getpoint P1 “Pick a point:”) ;; gather data with base and prompt

            (getkword “Enter the value:”) ;; restricted data entry

            ;; calculate or find specific data

            X value = (car NNN), Y value = (cadr NNN), Z value = (caddr NNN)

            (cond   (test 1) (progn (function1) (function 2) (function 3))

                        (test 2) (function)

                        (test n) (function))

            (if (test) (then) (else))

            ;; construct and display

            (command “.LINE” P1 P2 “”) ;; or any other AutoCAD command

            (setvar “NNN” nnn) ;; restore the pre-existing conditions

            (end) or (princ) ;; to clean up and exit without footprints

) ;; end of routine

 

A LISP Routine used transparently within another AutoCAD command

 

;*********************BETWEEN.LSP**************************

;

; Find a 3D point midway from two indicated points

;

(defun BETWEEN (/ P1 P2)

  (setq P1 (getpoint "\nChoose first point: ")

        P2 (getpoint P1 "\ncChoose second point: ")

        PT (list (/ (+ (car P1) (car P2)) 2.0)

                 (/ (+ (cadr P1) (cadr P2)) 2.0)))

  (if (caddr P1) (setq PT (append PT (list

                  (/ (+ (caddr P1) (caddr P2)) 2.0))))) PT)

 

The second LISP routine used as a stand-alone program

 

;**********************RECT.LSP********************

;

;Draw a rectangle with square, chamfered or filleted corners.

;

(defun C:RECT (/ SA OM BM GM P1 P2 P3 P4 CNR P5 P6 P7 P8 RAD)

  (command".UNDO" "M")

  (setvar "CMDECHO" 0)

  (setq SA (getvar "SNAPANG")

        OM (getvar "ORTHOMODE")

        BM (getvar "BLIPMODE")

        GM (getvar "GRIDMODE"))

  (setvar "BLIPMODE" 0)

  (setq P1 (getpoint "\nCorner point: ")

        P2 (getpoint P1 "\nAdjacent corner point: "))

  (command ".LINE" P1 P2 "")

  (setvar "SNAPANG" (angle P1 P2))

  (setvar "ORTHOMODE" 1)

  (setq P3 (getpoint P2 "\nTo point: ")

        P4 (polar P3 (angle P2 P1) (distance P2 P1)))

  (command ".LINE" P2 P3 P4 P1 "")

  (initget 1 "S F C")

  (setq CNR (getkword "\nThe corners are <C>hamfered <F>illeted or <S>quare : "))

  (cond ((= CNR "F")

            (setq P5 (list (/ (+ (car P1)(car P2)) 2.0)

                           (/ (+ (cadr P1)(cadr P2)) 2.0))

                  P6 (list (/ (+ (car P2)(car P3)) 2.0)

                           (/ (+ (cadr P2)(cadr P3)) 2.0))

                  P7 (list (/ (+ (car P3)(car P4)) 2.0)

                           (/ (+ (cadr P3)(cadr P4)) 2.0))

                  P8 (list (/ (+ (car P4)(car P1)) 2.0)

                           (/ (+ (cadr P4)(cadr P1)) 2.0))

                  RAD (getreal "\nFillett radius:<0.125> "))

            (if (= RAD nil)(setq RAD 0.125))

            (command ".FILLET" "R" RAD

                     ".FILLET" P5 P6

                     ".FILLET" P6 P7

                     ".FILLET" P7 P8

                     ".FILLET" P8 P5)

         )

         ((= CNR "C")

            (setq P5 (list (/ (+ (car P1)(car P2)) 2.0)

                           (/ (+ (cadr P1)(cadr P2)) 2.0))

                  P6 (list (/ (+ (car P2)(car P3)) 2.0)

                           (/ (+ (cadr P2)(cadr P3)) 2.0))

                  P7 (list (/ (+ (car P3)(car P4)) 2.0)

                           (/ (+ (cadr P3)(cadr P4)) 2.0))

                  P8 (list (/ (+ (car P4)(car P1)) 2.0)

                           (/ (+ (cadr P4)(cadr P1)) 2.0))

                  CH1 (getreal "\nFirst chamfer distance:<0.125> ")

                  CH2 (getreal "\nSecond chamfer distance:<0.125> "))

            (if (= CH1 nil)(setq CH1 0.125))

            (if (= CH2 nil)(setq CH2 0.125))

            (command ".CHAMFER" "D" CH1 CH2

                     ".CHAMFER" P5 P6

                     ".CHAMFER" P6 P7

                     ".CHAMFER" P7 P8

                     ".CHAMFER" P8 P5)

         )

         ((= CNR "S")

            (setq CNR nil)

         )

  );end of COND

  (setvar "SNAPANG" SA)  ; returns the variables to their original condition

  (setvar "ORTHOMODE" OM)

  (setvar "BLIPMODE" BM)

  (setvar "GRIDMODE" GM)

  (princ)

);end of RECT.lsp

 

 

DIALOG FORMAT

// remarks

// for those brave soles who want their LISP programs to work with user input from dialog boxes

(setq dcl_id (load_dialogNNN.dcl

(if (setq dcl_id (load_dialogNNN.dcl”)) 0) (exit))

(if (not (new_dialog “NNN” dcl_id)) (exit))

            (action_tile “key” “action expression”) // $value = correct tile value

            (mode_tile “key” mode) // 0 for enable mode, 1 for disable mode

// other initializations from within the action

// expression call back functions or other input handling

(start_dialog)

            (get_tile “key”)

            (set_tile “key” value)

            (mode_tile “key” mode)

(done_dialog status)

(unload_dialog dcl_id)