when type r12,it will make a c:r12 command like this
(defun c:r12()
(command "fillet" "r" 12 "")
(command "fillet")
)
when type r102,it will make a c:r102 command like this
(defun c:r102()
(command "fillet" "r" 102 "")
(command "fillet")
)
I collect some code may help to do this
code1:
============================================================
(or commandReactor
(setq commandReactor (vlr-command-reactor nil
'((:vlr-unknownCommand . Test))
)
)
)
(defun Test (a b)
(if
(and
(Setq x (read (car b)))
(= (type x) 'INT)
(< -1 x 251)
)
(princ (itoa x))
)
)
cold2:
============================================================
;反应器回调函数 用于判断和生成defun函数定义
(defun non_AutoMakeVbaFunc2(a b)
(setq b (car b)
c (non_string_to_list b ".")
d (substr (car c) 2 (- (strlen (car c)) (if (> (length c) 1) 1 2)))
e (substr b 2 (- (strlen b) 2))
f "fillet"
g "r"
h (cadr (non_string_to_list b "."))
h (substr h 1 (1- (strlen h)))
)
(if (or (= "APP" (strcase d))(= "THISDRAWING2" (strcase d))(= "app2" (strcase d))(= "r" (strcase d)))
(eval (read (strcat
"(defun "
d
"()"
"(command "
(vl-princ-to-string (vl-prin1-to-string f))
" "
(vl-princ-to-string (vl-prin1-to-string g))
;"1"
h
")"
"(command "
(vl-princ-to-string (vl-prin1-to-string f))
")"
")"
")"
)))
)
)
;===========================================
;字符串转表
(defun non_string_to_list(str del / lst)
(while (/= str (setq str (vl-string-subst "@" del str))))
(while (setq del (vl-string-position (ascii "@") str))
(setq del (substr str 1 del))
(setq str (vl-string-left-trim (strcat del) str))
(setq lst (append lst (list del)))
(setq str (substr str 2 (strlen str)))
)
(append lst (list str))
)
;===========================================
;定义反应器用于判断当前发出的Lisp
(if (not AutoMakeVbaFunc_reactor2)
(setq AutoMakeVbaFunc_reactor2 (vlr-lisp-reactor nil '((:vlr-lispWillStart . non_AutoMakeVbaFunc2))))
)
(princ)
attach is code from nonsmall