;查找命令
;1、输入关键字
;2、选择被查找文本
;3、定位至查找到的文本
(defun c:fd()
    (setq s nil)
    (setq wd "")
    (while (= wd "")
        (setq wd(getstring "\n请输入关键字:"))
    )
    (setq wd(strcat "*" (strcase wd) "*")) ;加入通配符
    (while (= s nil)
        (princ "\n请选择被查找文本:")
        (setq s (ssget (list (cons 0  "text"))));text为单行文本,mtext为多行文本
     )
    (princ "\n")
    (setq sl (sslength s))
    (setq st 0)
    (setq i 0)
    (setq lt(list))
    (while (< st sl)
        (setq e(ssname s st))
        (setq st(1+ st))
        (setq txt(cdr (assoc 1 (entget e)))) ;获取文本
        (if (wcmatch (strcase txt) wd) ;比较
            (progn
                (setq pos(cdr (assoc 10 (entget e)))) ;获取三维坐标
                (setq h (cdr (assoc 40 (entget e)))) ;获取字体高度
                (setq lt (cons (list txt pos h) lt))
                (setq i (1+ i))
                (princ (strcat (itoa i) "、" txt "\n"))
            )
        )
    )
    (if (= lt nil)
        (progn
            (princ "\n未找到相关项\n")
            (setq ret nil)
        )
        (progn
            (setq lt (reverse lt)) ;反转列表
            (setq msg (strcat "\n请选择项(1-" (itoa i) ")/退出(0): "))
            (setq j (getint msg))
            (while (> j 0)
                (setq e1 (nth (- j 1) lt))
                (myZoom (cadr e1) (caddr e1))
                (setq j (getint msg))
            )
        )
    )
)

;CAD窗口定位
;@p0:坐标
;@h: 文字高度
(defun myZoom(p0 h)
    (setq m (* h 10))
    (setq n (* h 15))
    (setq x1 (- (car p0) m))
    (setq y1 (- (cadr p0) m))
    (setq x2 (+ (car p0) n))
    (setq y2 (+ (cadr p0) n))
    (setq z (caddr p0))
    (setq p1 (list x1 y1 z)) ;左下标
    (setq p2 (list x2 y2 z)) ;右上标
    (command "zoom" "w" p1 p2 )
)