
;;;*************************************************
;支持cad单行和多行文字、TZ单行和多行文字
;查找的文字串可以使用*、？、#等特殊符号，但如果文本中本就存在此特殊符号时可能出错，主要wcmatch函数匹配特殊符号
(defun c:YJR_find ( /  old_cmd  fn           x          dclid         lin        return#              sstxt
             ssl    ct0           ct          edata         etext        txtln  subln  schct ss
             dcl_id newtext          en1         ob        entype a oldsstxt oldss 
             wqpp dhwz duohwz sxwz tzwz tzqt lightss js1 js2 vartxtlst filterlst
             ppzfc newsstxt  re   entnamelist putongtext kuaitext shuxingtext
             wxtsstr ssinsert  sstext  ssmtext  sstch_*text  sstch_drawingname
             onerow replace js1 js2 js3 jiaoju elliss screenpt n nn mm m j k e
             etext pte rv1 mycad my doc qk findlst
             xsdhk option cyczthsz gete getetext
              ssgflt wrscreept registrywrite registryread zhuangtai shiqu drawdcl  getcolordata c_img
              deleteyuan deleteyuan2 redraw4 dohdt linkhdt2jiaoju getbox zoome  do1 do2 do7 do8 do9 do91 do10 do15 do18 do19
               emakeel emakecr xiugai select getfw getnewtext  m_rev helpmsg  aygetallentinblk  getss divss  tihuan  liangxian jieguotishi
            )
;;;****************************************************************************
;;;显示主对话框
;;;****************************************************************************
  (defun xsdhk ( / replace lsdcl dclid)
    (setq lsdcl
           '("czth:dialog{label=\"查找替换 BY YJR111\";"
             ":boxed_column {label=\"查找替换\";"
                ":row{:popup_list{label=\"查找:\";key=\"18\";width=1;height=2;}"
                     ":popup_list{label=\"替换:\";key=\"19\";width=1;height=2;}}"
                ":row{:edit_box{label=\"查找:\";key=\"oldword\";width=34;height=1.2;allow_accept=true;}"
                     ":button{key=\"1\";label=\"拾取&Q>>\";width=1;height=0.8;alignment=top;}}"
                ":row{:edit_box{label=\"替换:\";key=\"newword\";width=34.5;height=1.2;allow_accept=true;}"
                     ":button{key=\"2\";label=\"拾取&W>>\";width=1;height=0.8;alignment=top;}}" 
                ":row{:text{value=\"范围:\";width=1;is_bold=true;}"
                     ":edit_box{key=\"6\";width=1;}"
                     ":button{key=\"7\";label=\"选择>\";width=1;}"
                     ":button{key=\"8\";label=\"全选&F \";width=12;}}}"
             ":image{key=\"16\";height=0.2;}"
             ":boxed_row{label=\"查找结果\";"
                 ":list_box{key=\"9\";height=18;width=36;}"
                 ":column{:button{key=\"10\";label=\"上一个&A\";width=1;height=2;}"
                         ":button{key=\"11\";label=\"下一个&S\";width=1;height=2;}"
                         ":button{key=\"12\";label=\"替  换&Z\";width=1;height=2;}"
                         ":button{key=\"3\";label=\"全部替换&Q\";width=15.5;height=2;}"
                         ":button{key=\"4\";label=\"全部亮显&D\";width=15.5;height=2;}"
                         ":button{key=\"14\";label=\"删除圆&E\";width=6;height=2;}"
                         ":button{key=\"15\";label=\"移  除&M\";width=6;height=2;}}}"
             ":text{key=\"wxts\";is_bold=true;}"
             ":row{:toggle{key=\"tongtihuan\";label=\"固定&W\";width=1;height=2;}"
                  ":edit_box{key=\"onerow\";width=34.2;height=1.4;allow_accept=true;}"
                  ":button{key=\"xiugai\";label=\"修改&X\";width=1;height=2;}}"
             ":image{key=\"17\";height=0.2;}"
             ":row{:button{key=\"5\";label=\"选项...\";width=6;height=2;}"
                  ":image_button{color=3;height=2;key=\"color\";width=4;}"
                  ":edit_box{label=\"焦距\";key=\"jiaoju\";width=1;height=1.2;}"
                  ":button{key=\"cancel\";label=\"取消&C\";is_cancel=true;width=1;height=2;}"
                  ":button{key=\"13\";label=\"帮助&H\";width=1;height=2;}}"
             ":row{label=\"焦距动态调节\";:slider{key=\"hdt\";value=10;min_value=0;max_value=1000;big_increment=10;small_increment=1;width=1;}}"
             "spacer_1;}"
            )
    ) 
    (setq dclid (mai_load_dialog lsdcl))
    (registryread) ;;;注意：读注册表要在对话框显示之前进行
    (new_dialog "czth" dclid "" screenpt)
    (or (and newch (/= newch "")) (setq newch "请输入替换字符串"))
    (or (and oldch (/= oldch "")) (setq oldch "请输入查找字符串"))
    (setq ppzfc (if (= wqpp "1") oldch (strcat "*" oldch "*")))
    (or czls (setq czls "0"))
    (or thls (setq thls "0"))
    (or drcznr (setq drcznr "0"))
    (or tcol (setq tcol 210))
    (or tongtihuan ( setq tongtihuan "0"))
    (or screenpt (setq screenpt '(-1 -1)))
    (or wxtsstr (setq wxtsstr "温馨提示:对话框可以移动至合适位置..."))
    (and findlst (setq e (nth (atoi drcznr) findlst)))
    (if (or (= re 7) (= re 8)) (setq replace "0"))
    (if (and e (= tongtihuan "0"))
          (progn
            (getetext)
            (set_tile "onerow" etext)
            (setq onerow etext)
          )
          (progn
            (set_tile "onerow" newch)
            (setq onerow newch)
          )
    )
    (cond ((= re 7) (setq fw "当前选择" drcznr "0"))
          ((= re 8) (setq fw "整个图形" drcznr "0"))
          (fw)
          ((setq fw ""))
    )
    (drawdcl "16" 11)
    (drawdcl "17" 11)
    (cyczthsz)
    (mai_filldcl_list "9" (mapcar 'caddr findlst))
    (mai_filldcl_list "18" czstrlst)
    (mai_filldcl_list "19" thstrlst)
    (zhuangtai)
    (c_img "color" tcol)
    (set_tile "18" czls)
    (set_tile "19" thls)
    (set_tile "oldword" oldch)
    (set_tile "newword" newch)
    (set_tile "jiaoju" jiaoju)
    (set_tile "tongtihuan" tongtihuan)  
    (set_tile "6" fw)
    (set_tile "9" drcznr)
    (set_tile "wxts" wxtsstr)   
    (action_tile "color" "(setq tcol (getcolordata tcol))(c_img $key tcol)")
    (action_tile "oldword" "(setq oldch $value)(do1)")
    (action_tile "newword" "(setq newch $value)(do2)")
    (action_tile "jiaoju" "(linkhdt2jiaoju)")
    (action_tile "1" "(setq screenpt(done_dialog 1))(wrscreept)")
    (action_tile "2" "(setq screenpt(done_dialog 2))(wrscreept)")
    (action_tile "3" "(setq screenpt(done_dialog 3))(do2)(wrscreept)")
    (action_tile "4" "(setq screenpt(done_dialog 4))(wrscreept)")
    (action_tile "5" "(option)")
    (action_tile "6" "(setq fw $value)(getfw)")
    (action_tile "7" "(setq screenpt(done_dialog 7))(wrscreept)")
    (action_tile "8" "(setq screenpt(done_dialog 8))(wrscreept)")
    (action_tile "9" "(setq rv1 $reason)(setq drcznr $value)(if(= rv1 1)(do91)) (if(/= rv1 1)(progn(setq screenpt(done_dialog 9))(wrscreept)))")
    (action_tile "10" "(setq up $value)(setq down \"0\")(do10)")
    (action_tile "11" "(setq down $value)(setq up \"0\")(do10)")
    (action_tile "12" "(setq replace $value)(setq up \"0\")(setq down \"1\")(tihuan findlst)(do2)")
    (action_tile "13" "(helpmsg)")
    (action_tile "14" "(done_dialog 14)")
    (action_tile "15" "(do15)")
    (action_tile "18" "(setq czls $value)(do18)")
    (action_tile "19" "(setq thls $value)(do19)")
    (action_tile "onerow" "(setq onerow $value)")
    (action_tile "xiugai" "(xiugai)")
    (action_tile "tongtihuan" "(setq tongtihuan $value)(if(= tongtihuan \"1\")(progn(setq onerow newch)(set_tile\"onerow\"newch)))")
    (action_tile "hdt" "(dohdt)")
    (action_tile "cancel" "(done_dialog 0)")
    (setq re (start_dialog))
    (cond ((= re 0) (redraw4) (sssetfirst nil nil) (deleteyuan))
          ((= re 1) (shiqu))
          ((= re 2) (shiqu))
          ((= re 3) (tihuan findlst) (xsdhk))
          ((= re 4) (liangxian findlst))
          ((= re 7) (do7))
          ((= re 8) (do1) (do8))
          ((= re 9) (do9))
          ((= re 14) (deleteyuan2) (xsdhk))
    )    
    (unload_dialog dclid)
);_ END xsdhk

;;;******************************************
;;;显示选项对话框
;;;******************************************
  (defun option ( / lsdcl dclid)
    (setq lsdcl
           '("sz:dialog{label=\"条件设置\";"
             ":boxed_row{:toggle{label=\"完全匹配    \"; key=\"wqpp\";height=1.2;allow_accept=true;}"
                        ":toggle{label=\"区分大小写\";key=\"qfdxx\";height=1.2;allow_accept=true;}}"
             ":boxed_column{"
                 ":row{:toggle{label=\"单行文字\";key=\"dhwz\";height=1.2;allow_accept=true;}"
                      ":toggle{label=\"多行文字\";key=\"duohwz\";height=1.2;allow_accept=true;}}"
                 ":row{:toggle{label=\"属性文字\";key=\"sxwz\";height=1.2;allow_accept=true;}"
                      ":toggle{label=\"天正文字\";key=\"tzwz\";height=1.2;allow_accept=true;}}"
                 ":row{:toggle{label=\"块内文字\";key=\"knwz\";height=1.2;allow_accept=true;}"
                      ":toggle{label=\"其他文字\";key=\"tzqt\";height=1.2;allow_accept=true;}}}"
             ":boxed_column{label=\"历史记录设置(字符之间以空格分隔)\";"
                 ":edit_box{label=\"常用查找\";key=\"cycz\";width=34;height=1.2;allow_accept=true;}"
                 ":edit_box{label=\"常用替换\";key=\"cyth\";width=34;height=1.2;allow_accept=true;}}"
             ":row{:toggle{label=\"清空查找结果\";key=\"qk\";}ok_cancel;}}"
            )
    ) 
    (setq dclid (mai_load_dialog lsdcl))
    (registryread)
    (new_dialog "sz" dclid )
    (set_tile "wqpp" wqpp)
    (set_tile "qfdxx" qfdxx)
    (set_tile "dhwz" dhwz)
    (set_tile "duohwz" duohwz)
    (set_tile "sxwz" sxwz)
    (set_tile "tzwz" tzwz)
    (set_tile "knwz" knwz)
    (set_tile "tzqt" tzqt)
    (set_tile "cycz"  cycz)
    (set_tile "cyth"  cyth)
    (set_tile "qk" qk)
    (action_tile "wqpp" "(setq wqpp $value)")
    (action_tile "qfdxx" "(setq qfdxx $value)")
    (action_tile "dhwz" "(setq dhwz $value)")
    (action_tile "duohwz" "(setq duohwz $value)")
    (action_tile "sxwz" "(setq sxwz $value)")
    (action_tile "tzwz" "(setq tzwz $value)")
    (action_tile "knwz" "(setq knwz $value)")
    (action_tile "tzqt" "(setq tzqt $value)")
    (action_tile "cycz" "(setq cycz $value)");;;常用查找历史记录设置
    (action_tile "cyth" "(setq cyth $value)") ;常用替换历史记录设置
    (action_tile "qk" "(setq qk $value)")
    (action_tile "accept" "(done_dialog 100)")
    (action_tile "cancel" "(done_dialog 0)")
    (setq std (start_dialog))
    (if (= std 100) (registrywrite))
    (cyczthsz)
    (unload_dialog dclid)
  )
;;;***************************************************************
;;;常用查找替换字符串设置
;;;***************************************************************
(defun cyczthsz( / x )
    (and cycz
        (/= cycz "")
        (progn
            (foreach x (mai_str2lst cycz " ") (setq czstrlst (mai_cons x czstrlst)))
            (mai_filldcl_list "18"  czstrlst)
            (set_tile "18" "0")
            (set_tile "oldword" (car czstrlst))
        )
    )
    (and cyth
         (/= cyth "")
         (progn
            (foreach x (mai_str2lst cyth " ") (setq thstrlst (mai_cons x thstrlst)))
            (mai_filldcl_list "19"  thstrlst)
            (set_tile "19" "0")
            (set_tile "newword" (car thstrlst))
         )
    )
)
;;;******************************************
;;;定义e
;;;******************************************
(defun gete () (setq e (nth (atoi drcznr) findlst)))
;;;******************************************
;;;定义etext
;;;******************************************
(defun getetext()
   (setq etext (substr (caddr e) (1+ (strlen (strcat "[" (itoa (1+ (atoi drcznr))) "] ")))))
)

; 选择集筛选函数 by firstinti
; http://bbs.mjtd.com/thread-93264-1-1.html
; ss-原始总选择集
; vartxtlst-各分类选择集变量名列表
; filterlst-各分类选择集类型
  ; (setq ss (ssget))
  ; (setq vartxtlst (list "ss1" "ss2" "ss3")
        ; filterlst (list "circle" "*line" "*text")
  ; )
  ; 用法:(ssgflt ss vartxtlst filterlst)
(defun ssgflt ( ss vartxtlst filterlst / ssgetp )

  (defun ssgetp (ss filter)
    (if ss (vl-cmdf "select" ss ""))
    (ssget "p" (list (cons 0 filter)))
  )
  
  (mapcar '(lambda (x y) (set x (ssgetp ss y)))
          (mapcar 'read vartxtlst)
          filterlst
  )
)
;;;**********************************************
;;;写注册表对话框位置
;;;**********************************************
(defun wrscreept()
  (and screenpt (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "screenpt" (vl-princ-to-string screenpt)))
)
;;;**********************************************
;;;写注册表选项配置
;;;**********************************************
(defun registrywrite()
    (and wqpp (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "wqpp" wqpp))
    (and qfdxx (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "qfdxx" qfdxx))
    (and dhwz (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "dhwz" dhwz))
    (and duohwz (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "duohwz" duohwz))
    (and sxwz (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "sxwz" sxwz))
    (and tzwz (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "tzwz" tzwz))
    (and knwz (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "knwz" knwz))
    (and tzqt (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "tzqt" tzqt))
    (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "cycz" cycz)
    (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "cyth" cyth)
    (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "qk" qk)
)
;;;**********************************************
;;;读注册表选项配置
;;;**********************************************
(defun registryread()
    (or (setq wqpp (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "wqpp")) (setq wqpp "0"))
    (or (setq qfdxx (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "qfdxx")) (setq qfdxx "0"))
    (or (setq dhwz (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "dhwz")) (setq dhwz "1"))
    (or (setq duohwz (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "duohwz")) (setq duohwz "1"))
    (or (setq sxwz (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "sxwz")) (setq sxwz "0"))
    (or (setq tzwz (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "tzwz")) (setq tzwz "0"))
    (or (setq knwz (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "knwz")) (setq knwz "0"))
    (or (setq tzqt (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "tzqt")) (setq tzqt "0"))
    (or (setq cycz (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "cycz")) (setq cycz ""))
    (or (setq cyth (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "cyth")) (setq cyth ""))
    (or (setq qk (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "qk")) (setq qk "0"))
    (or (setq jiaoju (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "jiaoju")) (setq jiaoju "10"))
    (if (setq screenpt (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "screenpt"))
        (setq screenpt (read (vl-registry-read "HKEY_CURRENT_USER\\czthoption" "screenpt")))
        (setq screenpt '(-1 -1))
    )
)
;;;**************************************************
;;;状态显示
;;;**************************************************
(defun zhuangtai( / tm )
   (setq tm (if findlst 0 1))
   (mode_tile "3" tm)
   (mode_tile "4" tm)
   (mode_tile "10" tm)
   (mode_tile "11" tm)
   (mode_tile "12" tm)
   (mode_tile "15" tm)
   (mode_tile "hdt" tm)
   (mode_tile "xiugai" tm)
   (mode_tile "14" (if (ssget "x" (list (cons 0 "ellipse") (cons 8 "findttz"))) 0 1))
   (mode_tile "6" 1)
 )

 ;;;**************************************************
;;;屏幕提取文字
;;;**************************************************
  (defun shiqu ( / ent1 txt )
    (and (setq ent1 (car (mai_entsel T "请点击文字提取:" "选择的不是文字." '((0 . "*text,attdef,attrib")) nil)))
         (setq txt (mai_clear_mtformat (mai_dxf 1 ent1)))
         (cond ((= re 1) (setq oldch txt))
               ((= re 2) (setq newch txt))
         )
    )      
    (xsdhk)
  )

;;;******************************************
;;;在DCL上画画
;;;******************************************
(defun drawdcl ( key dclcol / width  height)
    (setq width (dimx_tile key)
          height (dimy_tile key)
    )
    (start_image key)
    (vector_image 0 0  width 0 dclcol)
    (vector_image 0 0 0 height dclcol)
    (vector_image 0 height width height dclcol)
    (vector_image width height width 0 dclcol)
    (vector_image width 0 0 0 dclcol)
    (fill_image 0 0 width height dclcol)
    (end_image)
)

;;;******************************************
;;;获取cad标准颜色
;;;******************************************
(defun getcolordata ( col )
    (cond ((acad_colordlg col t)) (col))
)
;;;******************************************
;;;初始化颜色图像按钮
;;;******************************************
  (defun c_img ( key col / tm  len)
    (if col
      (progn
        (start_image key)
        (fill_image 0 0 (dimx_tile key) (dimy_tile key)col)
        (end_image)
        (setq tm (itoa col)
              len (strlen tm)
              tm (cond ((= len 1) (strcat "  " tm))
                       ((= len 2) (strcat " " tm))
                       (tm)
                 )
        )
        (set_tile "color" tm)
      )
    )
  )

  ;;;******************************************
;;;删除椭圆
;;;******************************************
(defun deleteyuan()
  (mai_entdel (ssget "x" (list (cons 0 "ellipse,circle") (cons 8 "findttz"))) nil)
)
;;;******************************************
;;;删除椭圆2
;;;******************************************
(defun deleteyuan2()
    (deleteyuan)
    (vla-ZoomScaled myacad 1 acZoomScaledRelative)
    (vla-zoomprevious myacad)
)
;;;******************************************
;;;暗显图元
;;;******************************************
(defun redraw4() (mapcar '(lambda(x) (vla-highlight (cadr x) :vlax-false)) findlst))



;;;******************************************
;;;滑动条动作函数
;;;******************************************
(defun dohdt ()
  (set_tile "jiaoju" $value)
  (setq jiaoju $value)
  (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "jiaoju" jiaoju)
  (gete)
  (getetext)
  (zoome e)
)
;;;******************************************
;;;滑动条链接焦距编辑框函数
;;;****************************************** 
(defun linkhdt2jiaoju(/ num)
    (setq num (atof $value))
    (if (>= 10000 num -10000)
        (progn
            (set_tile "hdt" (rtos num 2 1))
            (setq jiaoju (rtos num 2 1))
            (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "jiaoju" jiaoju)
        )
        (progn
           (if (< num 0)     (alert "\n请大于-10000..."))
           (if (> num 10000) (alert "\n请小于10000..."))
           (set_tile $key    (get_tile "hdt" ))
           (setq jiaoju      (atof $value))
           (vl-registry-write "HKEY_CURRENT_USER\\czthoption" "jiaoju" jiaoju)
        )
    )
)
;;;****************************************************
;;;普通文字画椭圆包围框
;;;*****************************************************
(defun getbox ( obj / inserp )
    (cond ((assoc "B" (list e))
            (setq midp (nth 3 e)
                  minp (nth 4 e)
                  maxp (nth 5 e)
            )
            (emakecr midp minp tcol etext)
          )
          ((not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'minp 'maxp))))
            (setq minp (vlax-safearray->list minp)
                  maxp (vlax-safearray->list maxp)
                  midp (polar minp (angle minp maxp) (/ (distance minp maxp) 2))
            )
            (emakeel midp minp tcol etext)
          )
    )
    (vla-highlight obj :vlax-true)
    (redraw (entlast) 3)
)

;;;******************************************
;;;聚焦对象
;;;******************************************
(defun zoome (e / tm txtang)
    (deleteyuan)
    (getetext)
    (setq txtang (last e))
    (getbox (cadr e))
    (setq objlast (vlax-ename->vla-object (entlast))
          tm (* (distof jiaoju) 100)
          tm (list tm tm)
    )
    (or (= txtang 0) (vla-rotate objlast (vlax-3d-point midp) txtang))
    (vla-highlight objlast :vlax-true)
    (vla-zoomwindow
        myacad
        (vlax-3d-point (mapcar '- minp tm))
        (vlax-3d-point (mapcar '+ maxp tm))
    )
)
;;;******************************************
;;;查找编辑框动作函数
;;;******************************************
(defun do1()
    (and (/= oldch "输入查找字符串")
         (not (member oldch czstrlst))
         (progn
            (setq czstrlst (cons oldch czstrlst))
            (mai_filldcl_list "18" czstrlst)
            (set_tile "18" "0")
         )
    )  
)
;;;******************************************
;;;替换编辑框动作函数
;;;******************************************
(defun do2()
   (and (/= newch "输入替换字符串")
        (not (member newch thstrlst))
        (progn
          (setq thstrlst (cons newch thstrlst))
          (mai_filldcl_list "19" thstrlst)
          (set_tile "19" "0")
        )
    )
)
;;;******************************************
;;;选择动作
;;;******************************************
(defun do7()
    (sssetfirst nil nil)
    (select)
    (setq findlst nil sstxt nil)
    (getss)
    (liangxian findlst)
    (xsdhk)
)  
;;;******************************************
;;;设置选择范围状态值（显示值）
;;;******************************************
(defun do8()
    (setq findlst nil sstxt nil)
    (getfw)
    (getss)
    (liangxian findlst)
    (xsdhk)
)  
;;;******************************************
;;;列表框动作程序
;;;******************************************
(defun do91()
    (gete)
    (if e
        (progn
            (getetext)
            (redraw4)
            (zoome e)
            (setq wxtsstr (strcat (itoa (1+ (atoi drcznr))) "\/" (itoa (length findlst))"   当前文本:" etext))
            (set_tile "wxts" wxtsstr)
            (if (= tongtihuan "0")
                (progn
                    (set_tile "onerow" etext)
                    (setq onerow etext)
                )
            )
        )
    )
  )
(defun do9( / a old_selectioncycling )
    (gete)
    (liangxian (list e))
    (redraw4)
    (zoome e)
    (princ "\n任意键返回对话框!!!")
	(setq old_selectioncycling (getvar "selectioncycling"))
	(if old_selectioncycling (setvar "selectioncycling" 0))
    (while (and (/= 2 (setq a (car (grread))))
                (/= a 3)
                (/= a 11)
                (/= a 25)
            )
    )
    (vla-delete (vlax-ename->vla-object (entlast)))
    (xsdhk)
)
;;;******************************************
;;;上一个缩放和下一个缩放
;;;******************************************
(defun do10 ( / tm )
    (deleteyuan)
    (setq tm (type drcznr)
          tm (cond ((= tm 'str) (atoi drcznr))
                   ((= tm 'int) drcznr)
             )
          drcznr (itoa ((if (= up "1") 1- 1+) tm))
          endnum (length findlst)
          tm (atoi drcznr)
    )
    (cond ((and (< tm 0) (= up "1")) (setq drcznr (itoa (1- endnum))))
          ((and (>= tm endnum) (= down "1")) (setq drcznr "0"))
    )
    (set_tile "9" drcznr)
    (if (and findlst (gete))
        (progn
            (getetext)
            (zoome e)
            (setq wxtsstr (strcat (itoa (1+ (atoi drcznr))) "\/" (itoa (length findlst))"   当前文本:" etext))
            (set_tile "wxts" wxtsstr)
            (if (= tongtihuan "0")
               (progn
                  (set_tile "onerow" etext)
                  (setq onerow etext)
               )
            )
        )
    )
   )
;;;******************************************
;;;移除列表框内列表项
;;;******************************************
(defun do15 ( / j endnum)
    (setq endnum (length findlst))
     (and findlst
         (> endnum 0)
         (< (atoi drcznr) endnum)
        (progn
            (setq e (nth (atoi drcznr) findlst)
                  findlst (vl-remove e findlst)
                  j 0
            )
            (getetext)
            (setq findlst (mapcar '(lambda (x)
                                      (setq j (1+ j)
                                            ex (substr (caddr x) (+ 2 (vl-string-search " " (caddr x))))
                                      )
                                      (append (list (car x) (cadr x) (strcat "[" (itoa j) "] " ex)) (cdddr x))
                                   )
                                   findlst
                          )
            )
            (mai_filldcl_list "9" (mapcar 'caddr findlst))
            (setq endnum (length findlst))
            (if (> (atoi drcznr) 0) (setq drcznr (itoa (1- (atoi drcznr)))))
            (set_tile "9" drcznr)
            (setq j (itoa (length findlst)))
            (cond ((not findlst)
                    (setq wxtsstr (strcat drcznr "\/" j "   移除文本:" etext))
                    (mode_tile "3" 1)
                    (mode_tile "4" 1)
                    (mode_tile "10" 1)
                    (mode_tile "11" 1)
                    (mode_tile "12" 1)
                    (mode_tile "15" 1)
                    (mode_tile "hdt" 1)
                    (mode_tile "xiugai" 1)
                  )
                  ((= (atoi drcznr) endnum)
                    (setq wxtsstr (strcat drcznr "\/" j "   移除文本:" etext))
                  )
                  ((setq wxtsstr (strcat (itoa (1+ (atoi drcznr))) "\/" j "   移除文本:" etext)))
            )
            (set_tile "wxts" wxtsstr)
        )
    )
)
;;;****************************************************
;;;查找历史记录列表框动作
;;;*****************************************************
(defun do18()
  (setq oldch (nth (atoi $value) czstrlst))
  (set_tile "oldword" oldch)  
)
;;;****************************************************
;;;替换历史记录列表框动作
;;;*****************************************************
(defun do19()
  (setq newch (nth (atoi $value) thstrlst))
  (set_tile "newword" newch)
)
;;;****************************************************
;;;画椭圆
;;;*****************************************************
(defun emakeel ( p11 p10 col txt)
   (entmake (list '(0 . "ellipse") '(100 . "acdbentity") '(100 . "acdbellipse") (cons 10 p11)
                 (cons 11 (list (* 1.3 (eval (cons 'max (list (- (car p11) (car p10)) (- (cadr p11) (cadr p10)))))) 0.0 0.0))
                 (cons 8 "findttz") (cons 62 col) (cons 40 (/ 1 (* 0.45 (if (> (strlen txt) 4) (strlen txt) 4)))) '(41 . 0) '(42 . 6.28319)
            )
   )
)
;;;****************************************************
;;;画圆
;;;*****************************************************
(defun emakecr (p11 p10 col txt)
   (entmake (list '(0 . "circle") '(100 . "acdbentity") (cons 10 p11)
                  (cons 40 (eval (cons 'max (list (- (car p11) (car p10)) (- (cadr p11) (cadr p10))))))
                  (cons 8 "findttz") (cons 62 col)
            )
   )
)
;;;******************************************
;;;整行修改
;;;******************************************
(defun xiugai()
  (if findlst
    (progn
      (gete)
      (setq obj (cadr e)
            j (vl-string-search " " (caddr e))
            textqz (substr (caddr e) 1 (1+ j))
      )
      (getetext)
      (zoome e)
      (if (assoc "B" (list e))
          (progn
                (divss findlst)
                (foreach knum kuaitext
                    (setq blklst (mai_cons (vla-get-name (car knum)) blklst))
                )        
                (setq mydoc (vla-get-activedocument (vlax-get-acad-object)))
                (vlax-for blk (vla-get-blocks mydoc)
                  (setq nn -1
                        blkname (vla-get-name blk)
                  )
                  (if (member blkname blklst)
                      (repeat (vla-get-count blk)
                        (setq nn (1+ nn)
                              oldobj (vla-item blk nn)
                        )
                        (and (wcmatch (vla-get-objectname oldobj) "AcDbText,AcDbMText")
                             (= (car (nth (atoi drcznr) findlst)) "B")
                             (= blkname (vla-get-name (cadr (nth (atoi drcznr) findlst))))
                             (progn
                               (vla-put-textstring oldobj onerow)
                               (vla-update oldobj)
                               (setq blkss (ssget "x" (list (cons 0 "insert") (cons 2 blkname))))
                               (mapcar '(lambda(x) (vla-update (vlax-ename->vla-object x))) (mai_ssget_2_list blkss))
                               (mapcar '(lambda(x)
                                           (and (= (car x) "B")
                                                (= (vla-get-name (cadr x)) blkname)
                                                (setq findlst (subst (vl-list* "b" (nth 1 x) (strcat textqz onerow) (cdddr x)) x findlst)
                                                      thknum (1+ thknum)
                                                )
                                           )
                                        )
                                        findlst
                               )
                               (mai_filldcl_list "9" (mapcar 'caddr  findlst))
                               (setq wxtsstr (strcat "块名:" blkname "文本" etext " 改为 " onerow "..." "共更新块参照" (itoa thknum) "个"))
                               (set_tile "wxts" wxtsstr)

                             )
                        )
                      )
                  )
                )
            )
            (progn
                (vla-put-textstring obj onerow)
                (vla-update obj);;;更新查找的字符串
                (setq findlst (subst (append (list (car e) obj (strcat textqz onerow)) (cdddr e)) e findlst))
                (mai_filldcl_list "9" (mapcar 'caddr findlst));;;更新查找结果列表
                (setq drcznr (itoa (if (< (1+ (atoi drcznr)) (length findlst)) (1+ (atoi drcznr)) 0)))
                (set_tile "9" drcznr)
                (setq wxtsstr (strcat etext "已经修改为" onerow))
            )
        )
        (set_tile "wxts" wxtsstr)
        (if (= tongtihuan "0")
            (progn
              (gete)
              (set_tile "onerow" (getetext))
              (setq onerow etext)
            )
        )
    )
  )
)
;;;*********************************************
;;;范围选择
;;;*********************************************
(defun select()
    (setq ppzfc (if (= wqpp "1") oldch (strcat "*" oldch "*"))
          js1 0
          js2 0
          js3 0
    )
    (prompt "\n选择查找替换范围:")
    (setvar 'nomutt 1)
    (if (or (= sxwz "1") (= knwz "1"))
        (setq ss (ssget (list '(-4 . "<or") (cons 0 "INSERT")
                              '(-4 . "<and")(cons 0  "TEXT,MTEXT,TCH_*TEXT,TCH_DRAWINGNAME")
                              '(-4 . "<or") (cons 1 ppzfc) (cons 1 (strcase ppzfc)) '(-4 . "or>")
                              '(-4 . "and>") '(-4 . "or>")
                        )
                 )
        )
        (setq ss (ssget (list (cons 0  "TEXT,MTEXT,TCH_*TEXT,TCH_DRAWINGNAME")
                              '(-4 . "<or") (cons 1 ppzfc) (cons 1 (strcase ppzfc)) '(-4 . "or>")
                        )
                 )
        )
    )
    (setq oldss ss)
)

;;;******************************************
;;;取得全部选择范围状态下选择集
;;;******************************************
  (defun getfw()
     (setq ppzfc (if (= wqpp "1") oldch (strcat "*" oldch "*"))
           ss (if (or (= sxwz "1") (= knwz "1"))
                  (list '(-4 . "<or")(cons 0 "INSERT")
                       '(-4 . "<and")(cons 0  "TEXT,MTEXT,TCH_*TEXT,TCH_DRAWINGNAME")
                       '(-4 . "<or")(cons 1 ppzfc)(cons 1 (strcase ppzfc))'(-4 . "or>")
                       '(-4 . "and>")
                       '(-4 . "or>")
                   )
                   (list (cons 0  "TEXT,MTEXT,TCH_*TEXT,TCH_DRAWINGNAME")
                          '(-4 . "<or")(cons 1 ppzfc)(cons 1 (strcase ppzfc))'(-4 . "or>")
                   )
               )
     )
     (if (= re 8)
         (setq ss (ssget "X" ss) oldss ss)
         (setq ss oldss)
     )
    )
;;;****************************************************
;;;;;;组成新字符串
;;;*****************************************************
  (defun getnewtext (etext)
    (setq pos (vl-string-search (if (= qfdxx "0") (strcase oldch) oldch)
                                (if (= qfdxx "0") (strcase etext) etext)
              )
          newtex (if pos (strcat (substr etext 1 pos) newch (substr etext (+ 1 pos (strlen oldch))))
                        etext
                 )
    )
  )
;;;****************************************************
;;;;;;变换矩阵
;;;****************************************************
(defun m_rev (a / n u v)
    (setq n 0)
    (repeat (length a)
      (setq u (cons (mapcar '(lambda (v) (nth n v)) a) u)
            n (1+ n)
      )
    )
    (reverse u)
  )
;;;***********************************************************
;;; 获取块内非块实体
;;;***********************************************************
(defun aygetallentinblk ( entblkname / xblkname xblkdef entname1 enttype tmx xinserp minp maxp midp tmp )
  (setq tmp (entget entblkname)
        xinserp (mai_dxf 10 tmp)  ;;;嵌套块插入点
        xblkname (mai_dxf 2 tmp)  ;;;嵌套块名
        oldobj (vlax-ename->vla-object entblkname)  ;;;嵌套块vla对象
        kuaiang (mai_dxf 50 tmp)  ;;;块的旋转角度
        xblkdef (tblobjname "block" xblkname)
  )
  (if (equal xinserp oldinserp)
      (setq tmx oldinserp)
      (setq tmx (mapcar '+ oldinserp xinserp)
            oldinserp tmx
      )
  )
  (while (setq entname1 (entnext xblkdef))
    (setq enttype (cdr (assoc 0 (entget entname1))))  ;;;子图元类型
    (setq xoldobj (vlax-ename->vla-object entname1))  ;;;子图元vla对象
    (if (= enttype "insert")
        (progn
            (aygetallentinblk entname1);;;递归
            (grtext -2 (strcat "正在搜索块内文字,请耐心等候" (nth biaojinum biaoji)))
            (setq biaojinum (rem (1+ biaojinum) 8))
        )
 
        (and (wcmatch (vla-get-objectname xoldobj) "AcDbText,AcDbMText,AcDbAttributeDefinition,AcDbAttribute")
             (setq etext (vla-get-textstring xoldobj))
             (wcmatch (if (= qfdxx "0") (strcase etext ) etext) (if (= qfdxx "0")(strcase ppzfc ) ppzfc))
             (mapcar 'set '(minp maxp midp) (mai_GetBoundingBox xoldobj))
             (progn
                (setq minp (mapcar '+ tmx (trans minp 1 0)) ;;转换(wcs)
                      maxp (mapcar '+ tmx (trans maxp 1 0))
                      midp (mapcar '+ tmx (trans midp 1 0)) ;;转换(wcs)
                      txtang(+ kuaiang (vla-get-Rotation xoldobj)) ;;;块的旋转角度+块内文字旋转角度
                      findlst (cons (list "b" oldobj etext midp minp maxp txtang) findlst)
                )
                (grtext -2 (strcat "正在搜索块内文字,请耐心等候" (nth biaojinum biaoji)))
                (setq biaojinum (rem (1+ biaojinum) 8)
                      js2 (1+ js2)
                )
             )
        )
        
    )
    (setq xBlkDef entName1)
  )
  (setq oldinserp (mai_dxf 10 oldkent))
 )
;;;***************************************************
;;;获取各类型文字选择集
;;;***************************************************
(defun getss ( / strtype sslst blklst attlst)
  (setq ppzfc (if (= wqpp "1") oldch (strcat "*" oldch "*"))
        vartxtlst (list "ssinsert" "sstext" "ssmtext" "sstch_*text" "sstch_drawingname")
        filterlst (list "insert"   "text"   "mtext"   "tch_*text"   "tch_drawingname")
  )
  (if ss ;;;如果没有选择到，则所有选择集复位
      (ssgflt ss vartxtlst filterlst)
      (setq ssinsert nil sstext nil ssmtext nil sstch_*text nil sstch_drawingname nil)
  )

  ;;;1、普通文字查找
  (if (= dhwz "0") (setq sstext nil))
  (if (= duohwz "0") (setq ssmtext nil))
  (if (= tzwz "0") (setq sstch_*text nil))
  (if (= tzqt "0") (setq sstch_drawingname nil))
  (setq sslst (vl-remove nil (list sstext ssmtext sstch_*text sstch_drawingname)))
  (or sstxt (setq sstxt (ssadd)))
  (setq h (length sslst))
  (repeat h
    (setq h (1- h))
    (command "_.select" sstxt (nth h sslst) "")
    (setq sstxt (ssget "p" (list (cons 0 "TEXT,MTEXT,TCH_*TEXT,TCH_DRAWINGNAME"))))
    ;;;若不过滤，则文字和线等成组时会连线一起选，出错

    (if sstxt
      (progn
        (setq js3 0
              newsstxt (ssadd)
              ct0 (sslength sstxt)
        )
        (repeat ct0
          (setq ct0 (1- ct0)
                en1 (ssname sstxt ct0)
                ob (vlax-ename->vla-object en1)
                edata  (entget en1)
                txtang (mai_dxf 50 edata)
                etext  (mai_dxf 1 edata)
                entype (mai_dxf 0 edata)
          )
          (if (or (wcmatch (if (= qfdxx "0") (strcase etext) etext)
                           (if (= qfdxx "0") (strcase ppzfc) ppzfc)
                  )
                  (wcmatch (if (= qfdxx "0") (strcase etext) etext)
                           (if (= qfdxx "0") (strcase oldch) oldch)
                  )
                  (= (if (= qfdxx "0") (strcase etext) etext)
                     (if (= qfdxx "0") (strcase ppzfc) ppzfc)
                  )
                  (= (if (= qfdxx "0") (strcase etext) etext)
                     (if (= qfdxx "0") (strcase oldch) oldch)
                  )
              )
              (setq findlst (cons (list "C" ob etext txtang) findlst)
                    js3 (1+ js3)
              )
          )
        )
      )
    )
  )
   ;;;3、块内文字匹配查找
   (if (= knwz "1")
     (progn
       (if ssinsert (command "_.select" ssinsert ""))
       (setq ssknwz (ssget "p" (list (cons 0 "insert") (cons 66 0)))
             js2    0
       )
       (if ssknwz
           (progn
               (setq stime (getvar "date")
                     biaoji '("|" "||" "|||" "|||||" "||||||" "|||||||" "||||||||" "|||||||||" "||||||||||" )
                     biaojinum 0
               )
               (grtext -2 (strcat "正在搜索块内文字,请耐心等候" (nth biaojinum biaoji)))
               (foreach oldkent (mai_ssget_2_list ssknwz)
                 (setq oldinserp (mai_dxf 10 oldkent))
                 (aygetallentinblk oldkent)
               )
               (setq etime (getvar "date"))
               (grtext -2 (strcat "搜索块内文字完成，耗时" (rtos (* 86400.0 (- (- etime stime) (fix (- etime stime)))) 2 2) "秒..."))
           )
       )
     )
   )
   ;;;2、属性文字匹配查找
   (if (= sxwz "1")
       (progn
           (if ssinsert (command "_.select" ssinsert ""))
           (setq sssxwz (ssget "p" (list (cons 0 "insert") (cons 66 1)))
                 js1    0
           )
           (foreach vlae (mai_ssget_2_list sssxwz)
               (setq vlae (vlax-ename->vla-object vlae)
                     attlst (vlax-safearray->list (vlax-variant-value (vla-getattributes vlae)))
               )
               (foreach attobj attlst
                 (setq etext (vlax-get-property attobj 'textstring)
                       txtang (vla-get-rotation attobj)
                 )
                 (if (wcmatch (if (= qfdxx "0") (strcase etext) etext)
                              (if (= qfdxx "0") (strcase ppzfc) ppzfc)
                     )
                     (setq findlst (cons (list "A" attobj etext txtang) findlst)
                           js1 (1+ js1)
                     )
                 )
                )
            )
        )
   )
   
   (if findlst
       (setq j 0
             findlst
               (mapcar '(lambda(x)
                            (setq j (1+ j))
                            (vl-list* (car x) (cadr x) (strcat "[" (itoa j) "] " (caddr x)) (cdddr x))
                        )
                        (vl-sort findlst '(lambda(x y) (< (caddr x) (caddr y))))
               )
       )
   )
   (zhuangtai)
  )         

;;;****************************************************
;;;将各类型文字列表分类
;;;****************************************************
(defun divss (lst)
  (if lst
      (foreach x lst
           (cond((setq gtxt (assoc "C" (list x)))
                 (setq putongtext (cons (cdr gtxt) putongtext))
                 )
                ((setq gtxt (assoc "B" (list x)))
                 (setq kuaitext (cons (cdr gtxt) kuaitext))
                 )
                ((setq gtxt (assoc "A" (list x)))
                 (setq shuxingtext (cons (cdr gtxt) shuxingtext))
                )
           )
      )
  )
  (setq putongtext (reverse putongtext)
        kuaitext (reverse kuaitext)
        shuxingtext (reverse shuxingtext)
  )
)
;;;****************************************************
;;;替换子程序
;;;*****************************************************
(defun tihuan (lst)
    (divss lst)
    (setq js1 (length putongtext)
          js2 (length shuxingtext)
          js3 (length kuaitext)
    )
    (if putongtext
       (repeat (setq n (cond ((= re 3) (length putongtext))
                             ((= replace "1") 1)
                       )
               )
          (cond ((= re 3)
                 (setq n (1- n)
                       pte (nth n putongtext)
                       ob (car pte)
                       textqz (strcat "[" (itoa (1+ (vl-position (cons "C" pte) findlst))) "] ")
                       etext (vla-get-textstring ob)
                       txtang (last pte)
                 )
                 (getbox ob)
                 (setq elle (entlast))
                 (if (/= txtang 0.0) (vla-rotate (vlax-ename->vla-object elle) (vlax-3d-point midp)txtang))
                )
                ((= replace "1")
                 (setq e (nth (atoi drcznr) findlst)
                       pte (cdr e)
                       ob (car pte)
                 )
                 (if ob
                    (progn
                        (setq textqz (strcat "[" (itoa (1+ (vl-position (cons "C" pte) findlst))) "] ")
                              etext (vla-get-textstring ob)
                        )
                        (zoome e)
                    )
                 )
                )
          )
          (if ob
              (progn
                  (setq entype (cdr (assoc 0 (entget (vlax-vla-object->ename ob))))
                        newtext (getnewtext etext)
                  )
                  (cond ((and (= entype "TEXT") (= dhwz "1")) (vlax-put-property ob 'TextString newtext))
                        ((and (= entype "TCH_MTEXT") (= tzwz "1")) (entmod (subst (cons 1 newtext) (assoc 1 edata) edata)))
                        ((and (= entype "MTEXT") (= duohwz "1")) (vlax-put-property ob 'TextString newtext))
                        ((and (= entype "TCH_TEXT") (= tzwz "1")) (vlax-put-property ob 'Text newtext))
                        ((and (= entype "TCH_DRAWINGNAME") (= tzqt "1")) (vlax-put-property ob 'NameText newtext))
                  )
                  (vla-update ob)
                  (setq findlst (subst (list "C" ob (strcat textqz newtext) txtang) (list "C" ob (cadr pte) txtang) findlst))
                  (mai_filldcl_list "9" (mapcar 'caddr  findlst))
                  (setq wxtsstr (strcat (itoa (1+ (atoi drcznr))) "\/" (itoa (length findlst)) "   当前为普通文本:" etext "改为" newtext))
                  (set_tile "wxts" wxtsstr)
              )
            )
        )
    )
    (if shuxingtext
        (mapcar
          '(lambda (x / y )
                (if (assoc (car x) shuxingtext)
                    (progn
                        (setq etext (vla-get-textstring (car x))
                              textqz (strcat "[" (itoa (1+ (vl-position (cons "A" x) findlst))) "] ")
                              txtang (last x)
                              newtext (getnewtext etext)
                              y (* (distof jiaoju) 100)
                              y (list y y)
                        )
                        (vla-put-textstring (car x) newtext)
                        (vla-update (car x))
                        (getbox (car x))
                        (or (= txtang 0.0) (vla-rotate (vlax-ename->vla-object (entlast)) (vlax-3d-point midp) txtang))
                        (or (= re 3)
                            (vla-zoomwindow
                                 myacad
                                 (vlax-3d-point (mapcar '- minp y))
                                 (vlax-3d-point (mapcar '+ maxp y))
                            )
                        )
                        (setq findlst (subst (list "A" (car x) (strcat textqz newtext) (last x))
                                             (list "A"  (car x) (cadr x) (last x))
                                             findlst
                                      )
                        )
                        (mai_filldcl_list "9" (mapcar 'caddr  findlst))
                        (setq wxtsstr (strcat
                                        (itoa (1+ (atoi drcznr)))
                                        "\/"
                                        (itoa (length findlst))
                                        "   当前为块属性文本:"
                                        etext
                                        "改为"
                                        newtext
                                        )
                        )
                        (set_tile "wxts" wxtsstr)
                    )
                )
            )
            (cond ((= re 3) shuxingtext)
                  ((= replace "1") (list (cdr (nth (atoi drcznr) findlst))))
            )
        )
    )
    (if kuaitext
        (progn
        (foreach knum kuaitext
            (setq blklst (mai_cons (vla-get-name (car knum)) blklst))
        )        
        (setq mydoc (vla-get-activedocument (vlax-get-acad-object)))
        (vlax-for blk (vla-get-blocks mydoc)
          (setq blkname (vla-get-name blk))
          (if (member blkname blklst)
              (progn
                  (setq nn -1)
                  (repeat (vla-get-count blk)
                     (setq nn (1+ nn)
                           oldobj (vla-item blk nn)
                     )
                     (and (wcmatch (vla-get-objectname oldobj) "AcDbText,AcDbMText")
                          (setq etext (vla-get-textstring oldobj))
                          (wcmatch (if (= qfdxx "0") (strcase etext) etext) (if (= qfdxx "0") (strcase ppzfc) ppzfc))
                          (or (= re 3)
                              (and (= replace "1")
                                   (= (car (nth (atoi drcznr) findlst)) "B")
                                   (= blkname (vla-get-name (cadr (nth (atoi drcznr) findlst))))
                              )
                          )
                          (progn
                               (setq newtext (getnewtext etext))
                               (vla-put-textstring oldobj newtext)
                               (vla-update oldobj)
                               (setq blkss (ssget "X" (list (cons 0 "insert") (cons 2 blkname))))
                               (if blkss
                                  (progn
                                       (setq thknum (sslength blkss))
                                       (foreach ob (mai_ssget_2_list blkss) (vla-update ob) (getbox ob))
                                  )
                                  (setq thknum 0)
                               )
                               (mapcar '(lambda(x)
                                          (and (= (car x) "B")
                                               (= (vla-get-name (cadr x)) blkname)
                                               (setq textqz (strcat "[" (itoa (1+ (vl-position x findlst))) "] ")
                                                     findlst (subst (vl-list* "B" (nth 1 x) (strcat textqz newtext) (cdddr x)) x findlst)
                                                     thknum (1+ thknum)
                                               )
                                          )
                                        )
                                        findlst
                               )
                               (mai_filldcl_list "9" (mapcar 'caDdr  findlst))
                               (setq wxtsstr (strcat "块名:" blkname "文本" etext "改为" newtext "...共更新块参照" (itoa thknum) "个"))
                               (set_tile "wxts" wxtsstr)
                          )
                        )
                    )
                )
            )
        )
      )
    )
    (setq drcznr
            (itoa 
                (cond ((and (= (type drcznr) 'str) (= up "1")) (1- (atoi drcznr)))
                      ((= (type drcznr) 'str) (1+ (atoi drcznr)))
                      ((and (= (type drcznr) 'int) (= up "1")) (1- drcznr))
                      ((= (type drcznr) (1+ drcznr)))
                )
            )
          endnum (length findlst)
    )
    (cond ((and (< (atoi drcznr) 0) (= up "1"))
           (setq drcznr (itoa (1- endnum)))
          )
          ((and (>= (atoi drcznr) endnum) (= down "1"))
           (setq drcznr "0")
          )
    )
    (set_tile "9"  drcznr)
    (if (/= replace "1")(jieguotishi))
    (setq putongtext nil shuxingtext nil kuaitext nil)
  );_ END tihuan                         
;;;********************************************************
;;;;;;全部亮显:普通文字亮显，块参照文字画椭圆亮显
;;;********************************************************
  (defun liangxian( lst / )
    (setq ptlss (ssadd) sxlss (ssadd) klss (ssadd))
    (if (= re 4)
      (progn
      (divss lst)                       
      (mapcar '(lambda(x) (ssadd (vlax-vla-object->ename x) ptlss)) (mapcar 'car putongtext))
      (mapcar '(lambda(x) (ssadd (vlax-vla-object->ename x) sxlss)) (mapcar 'car shuxingtext))
      (if kuaitext
          (progn
              (mapcar '(lambda(x)
                          (setq txt (nth 1 x)
                                midp (nth 2 x)
                                inserp (nth 3 x)
                                txtang (nth 4 x)
                          )             
                          (emakeel midp inserp tcol txt)
                          (or (= txtang 0.0) (vla-rotate (vlax-ename->vla-object (entlast)) (vlax-3d-point midp) txtang))
                       )
                       kuaitext
              )
              (setq elliss (ssget "x" (list (cons 0 "ellipse") (cons 8 "findttz"))))
          )
      )
      (cond ((and ptlss sxlss elliss) (command "_.select" ptlss sxlss elliss "") (sssetfirst nil (ssget "p")))
            ( ptlss (sssetfirst nil ptlss))
            ( sxlss (sssetfirst nil sxlss))
            ( elliss (sssetfirst nil elliss))
      )
    )
   )
   (or (= replace "1")(jieguotishi))
   (setq putongtext nil shuxingtext nil kuaitext nil)
  )
;;;**************************************************
;;;;;;查找替换结果提示
;;;**************************************************
 (defun jieguotishi()
   (cond
      ((= re 3)
       (if (> (+ (if (and (= sxwz "1") js1) js1 0)
                 (if (and (= knwz "1") js2) js2 0)
                 (if (and js3 (member "1" (list dhwz duohwz tzwz tzqt))) js3 0)
              )
              0
           )
           (progn
               (setq wxtsstr (strcat "共替换了"
                                     (itoa (+ (if js1 js1 0) (if js2 js2 0) (if js3 js3 0)))
                                     "个文本..."
                                        (if (and js3 (member "1" (list dhwz duohwz tzwz tzqt)) (> js3 0))
                                            (strcat "普通文本:" (itoa  js3) "个...")
                                            ""
                                        )
                                        (if (and (= sxwz "1") js1 (> js1 0)) (strcat "属性文本:" (itoa  js1) "个...") "")
                                        (if (and (= knwz "1") js2 (> js2 0)) (strcat "块参照文本:" (itoa  js2) "个...")"")
                             )
               )
               (set_tile "wxts" wxtsstr)
               (princ (strcat "\n"wxtsstr))       
           )
           (progn
               (cond (findlst (setq wxtsstr (strcat "共替换了" (itoa (length findlst)) " 个文本...")))
                     ((= (+ (if js1 js1 0) (if js2 js2 0) (if js3 js3 0)) 0)
                      (setq wxtsstr (strcat "未找到符合要求的包含 " oldch " 的文本..."))
                     )
               )
               (set_tile "wxts" wxtsstr)
               (princ (strcat "\n "wxtsstr))
           )
       )
      )
      ((or (= re 4) (= re 8))
       (if (> (+ (if (and (= sxwz "1") js1) js1 0)
                 (if (and (= knwz "1") js2) js2 0)
                 (if (and (member "1" (list dhwz duohwz tzwz tzqt)) js3) js3 0)
              )
              0
           )
           (progn
               (setq wxtsstr (strcat "共找到了"
                                      (itoa (+ (if js1 js1 0) (if js2 js2 0)(if js3 js3 0))) "个文本..."
                                      (if (and (member "1" (list dhwz duohwz tzwz tzqt)) js3 (> js3 0))
                                          (strcat "普通文本:" (itoa  js3) "个...")
                                          ""
                                      )
                                      (if (and (= sxwz "1") js1 (> js1 0)) (strcat "属性文本:" (itoa js1) "个...") "")
                                      (if (and (= knwz "1") js2 (> js2 0)) (strcat "块参照文本:" (itoa js2) "个...") "")
                             )
               )
               (set_tile "wxts" wxtsstr)
               (princ (strcat "\n"wxtsstr))
           )
           (progn
               (cond (findlst (setq wxtsstr (strcat "共找到了" (itoa (length findlst)) " 个文本...")))
                     ((= (+ (if js1 js1 0) (if js2 js2 0) (if js3 js3 0)) 0)
                      (setq wxtsstr (strcat "未找到符合要求的包含 " oldch " 的文本..."))
                     )
               )
               (set_tile "wxts" wxtsstr)
               (princ (strcat "\n"wxtsstr))
           )
       )
       )
      ((= re 7)
       (cond (findlst (setq wxtsstr (strcat "共找到了" (itoa (length findlst)) " 个文本...")))
             ((= (+ (if js1 js1 0) (if js2 js2 0) (if js3 js3 0)) 0)
              (setq wxtsstr(strcat "未找到符合要求的包含 " oldch " 的文本..."))
             )
       )
       (set_tile "wxts" wxtsstr)
       (princ (strcat "\n"wxtsstr))
      )      
    )
   )
;;;******************************************
;;;帮助信息
;;;******************************************
(defun helpmsg()
    (alert "文本查找替换 BY YJR111 2012-10-10
          \n 1、可支持通配符；
          \n 2、双击查找结果中的文字可以zoom该文字；
          \n 3、单击定位查找结果中的文字，可以在替换栏内自由输入替换内容进行替换；
          \n 4、上一个和下一个可以不停进行定位搜索；
          \n 5、查找结果中定位一个文字后，若替换内容相同，可不停按替换按钮进行相同替换；
          \n 6、定位时画椭圆做标记，自动删除；
          \n 7、块文字在全部亮显时是亮显椭圆标记，可以用删圆命令删除；
          \n 8、单个替换后结果框内实时显示替换结果，并可双击查看；
          \n 9、圆的颜色可以更改；
          \n 10、焦距可调节文字缩放效果，数值=0为最大放大居中；
          \n 11、除非必要，选项中块文字最好不选，否则影响速度；
          \n 12、块内文字圆标识，其他文字（包括属性）椭圆标识;
          \n 13、其他请自行测试，如有bug，请QQ告知：16570954."
   )
 )
            
            
  (mini_start nil)
  (setq myacad (vlax-get-acad-object))
  (setq mydoc (vla-get-activedocument myacad))
  (if (not (tblsearch "layer" "findttz"))
      (vla-add (vla-get-layers mydoc) "findttz")
  )
  (if (= qk "1") (setq findlst nil))
  (xsdhk)
  (mai_end)
) ;_ END defun

(princ "\n*************查找替换文本,命令:YJR_find*************** ")
(princ)

