(defun define
( name cmd lst
/ functiondef
) ;; (define <NAME> <CMD> <LST>)
;; Creates a lisp function for a `NAME` which has a built-in error trapping.
;;
;; I found myself wanting to create a more customized version of some built-in
;; commands, like: line, pline, etc. where layer, osnap, orthomode changing was
;; a little more automatic but the code to do this was very redundant (the same
;; essential routine for each of these commands). I created this to offer myself
;; an easy(er) way to create those functions which allows me to focus on the
;; actual code I care about--and not the support functions.
;;
;; For example, the following will create a simple function to draw a line.
;; ;; -define a line command with no enviorment variables saved.
;; (define "bl" '(command "_.line") nil)
;;
;; This will create a function which looks like this:
;; (DEFUN C:BL nil
;; (EVAL (COMMAND "_.line"))
;; (WHILE (EQ 1 (LOGAND 1 (GETVAR (QUOTE CMDACTIVE)))) (COMMAND PAUSE))
;; (QUIT)
;; )
;;
;; Or using a more complicated example the following will produce more complicated code.
;;
;; ;; -Define a line function that will adopt the entities layer under the picked point.
;; (define
;; "b" ;; -name
;; '((lambda (pt) ;; -command to run
;; (setvar 'CLAYER (getlayerfrompickedpoint pt)) ;; -using custom function to get layer
;; (command "_.line" pt) )
;; (getpoint "\nSelect Point: ") )
;; '(("CLAYER")) ;; -Variables to save/restore
;; )
;;
;; This will create a function which looks like this:
;; (DEFUN C:B (/ *ERROR* *ERROR-PUSH-VARS*)
;; (DEFUN *ERROR* (MSG) (MAPCAR (QUOTE EVAL) #ERROR_LST#) (SETQ #ERROR_LST# nil))
;; (DEFUN *ERROR-PUSH-VARS* (LST / PUSH->LST)
;; (DEFUN PUSH->LST (SYM LST) (SET LST (CONS SYM (EVAL LST))))
;; (MAPCAR
;; (FUNCTION
;; (LAMBDA (X)
;; (PUSH->LST
;; (LIST (QUOTE SETVAR) (CAR X) (GETVAR (CAR X)))
;; (QUOTE #ERROR_LST#))
;; (IF (CADR X) (SETVAR (CAR X) (CADR X)))))
;; LST
;; )
;; )
;; (*ERROR-PUSH-VARS* (QUOTE (("CLAYER"))))
;; (EVAL
;; ((LAMBDA (PT)
;; (SETVAR (QUOTE CLAYER) (GETLAYERFROMPICKEDPOINT PT))
;; (COMMAND "_.line" PT))
;; (GETPOINT "\nSelect Point: ")))
;; (WHILE (EQ 1 (LOGAND 1 (GETVAR (QUOTE CMDACTIVE)))) (COMMAND PAUSE))
;; (QUIT)
;; )
(list (list '
/ '
*error* '
*error
-push
-vars
*)) 'sym
'lst)))) ;end defun push->lst
'lst)
))
)
) ; end setq
) ; end if
)
) ; end setq
)