以下是我的代码: ;;; 判断是否加载本文件 (if (car (atoms-family 1 '("vl-load-com"))) (vl-load-com) ;;else (progn (Alert "这个程序集是为AutoCAD 2000以及更高的版本设计的,许多程序有可能在没有Visual Lisp for R14支持的AutoCAD R14上不能正确地运行。" ) (exit) ; 版本不符,退出加载。 ) ) ;;; 以下定义文件中用到的函数 ;;;---------------------------------------------------------------------------------- ;;; 取得本程序的路径 ;;; --------------------------------------------------------------------------------- (defun GetMyApplicationPath (AppID) (vl-registry-read (strcat "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" AppID "_is1" ) "Inno Setup: App Path" ) ) (defun GetsceiPath () (GetMyApplicationPath "1") ) ;;; 解析字符串为表(函数来自明经通道转载) ;;; --------------------------------------------------------------------------------- (defun strParse (Str Delimiter / SearchStr StringLen return n char) (setq SearchStr Str) (setq StringLen (strlen SearchStr)) (setq return '()) (while (> StringLen 0) (setq n 1) (setq char (substr SearchStr 1 1)) (while (and (/= char Delimiter) (/= char "")) (setq n (1+ n)) (setq char (substr SearchStr n 1)) ) ;_ end of while (setq return (cons (substr SearchStr 1 (1- n)) return)) (setq SearchStr (substr SearchStr (1+ n) StringLen)) (setq StringLen (strlen SearchStr)) ) ;_ end of while (reverse return) ) ;_ end of defun ;;; 反解析表为字符串(函数来自明经通道转载) ;;; --------------------------------------------------------------------------------- (defun StrUnParse (Lst Delimiter / return) (setq return "") (foreach str Lst (setq return (strcat return Delimiter str)) ) ;_ end of foreach (substr return 2) ) ;_ end of defun ;;; 移除支持文件搜索路径 ;;; --------------------------------------------------------------------------------- (defun RemoveSupportPath (PathToRemove / supportlist) (setq supportlist (strparse (getenv "ACAD") ";")) (setq supportlist (vl-remove "" supportlist)) (setq supportlist (vl-remove-if '(lambda (x) (= (strcase x) (strcase PathToRemove))) supportlist ) ) (setenv "ACAD" (strUnParse supportlist ";")) ) ;;; 添加支持文件搜索路径 ;;; --------------------------------------------------------------------------------- ;;; note: 第二个参数如果为真, 插最前,否则插最后 ;;; (defun AddSupportPath (PathToAdd isFirst) (if isFirst (setenv "ACAD" (strcat PathToAdd ";" (getenv "ACAD"))) (setenv "ACAD" (strcat (getenv "ACAD") ";" PathToAdd)) ) ) ;;; 根据不同的AutoCAD版本加载不同的菜单文件: (defun Load_sceiMenu (/ acadver) (setq acadver (atof (getvar "acadver"))) (cond ((and (>= acadver 15.0) (< acadver 16.0)) (command "_menuload" "scei.mnu") ) ((and (>= acadver 16.0) (<= acadver 16.1)) (command "_menuload" "all.mns") ) ((>= acadver 16.2) (command "_menuload" "scei2006.mnu")) ) ) ;;; The following code "placemenu" written by LUCAS ;;; 插入菜单条 Placemenu由LUCAS编写 ;;; --------------------------------------------------------------------------------- (defun scei_PlaceMenu (/ n) (if (menugroup "scei") (progn (setq n 1) (while (< n 24) (if (menucmd (strcat "P" (itoa n) ".1=?")) (setq n (+ n 1)) (progn (if (> n 3) (setq n (- n 2)) (setq n 3) ) ;if (menucmd (strcat "p" (itoa n) "=+scei.pop3")) (menucmd (strcat "p" (itoa n) "=+scei.pop2")) (menucmd (strcat "p" (itoa n) "=+scei.pop1")) (setq n 25) ) ;progn ) ;if ) ;while ) ;progn ) ;if (princ) ) ;;; 初始化主函数 ;;; --------------------------------------------------- (defun Init_scei () ;; 添加支持路径 (AddSupportPath (GetsceiPath) nil) (AddSupportPath (strcat (GetsceiPath) "\\1") nil) (AddSupportPath (strcat (GetsceiPath) "\\2") nil) (AddSupportPath (strcat (GetsceiPath) "\\3") nil) (AddSupportPath (strcat (GetsceiPath) "\\4") nil) ;; 如果菜单组还没有被加载,则加载之 (if (not (menugroup "scei")) (Load_sceiMenu) )
;; 安排菜单条的位置 (scei_PlaceMenu) (princ) ) ;;; 以上函数部分定义完毕 ;;; ----------------------------------------------------- ;;; 主程序: ;;; ----------------------------------------------------- (princ "\n加载scei工具集……") (setq scei_cmdecho_save (getvar "cmdecho")) (setvar "cmdecho" 0) ;;; 执行初始化 (Init_scei) (setvar "cmdecho" scei_cmdecho_save) (setq scei_cmdecho_save nil) (princ "\nscei工具集加载完毕。版本 2005.4") (princ) ;; 加载主程序 ;; 为节省内存,这里也可以以autoload函数形式定义 ;; 有几条写几条 (load "scei.lsp") (arxload "scei.arx") (princ) |