建筑新时代论坛's Archiver

【热门搜索】建材Autocad膜结构钢结构加固招聘工程机械测绘建筑材料工程造价建筑施工图

brainstorm 发表于 2008-9-7 11:18

选择中文或英文

有时候业主要求中文英文图层要分开,写了下面一段小程序,选择中文或者英文,与大家分享,首发于老虎空间
(defun c:test (/ zgx-wholestr-if-letter ss ss1 en text n key ss_english
   ss_chn
       )
  (defun zgx-substr (str m n / mm nn teststr kk str1)
    (if (= m 0)
      (setq str1 str)
      (progn
(setq mm 0
       nn 0
)
(repeat (- m 1)
   (if (and
  str
  (/= "" str)
       )
     (progn
       (setq teststr (substr str 1 1))
       (if (zgx-singlestr-if-letter teststr)
  (setq kk 1)
  (setq kk 2)
       )
       (setq mm (+ mm kk))
       (setq str (substr str (1+ kk)))
     )
   )
)
(setq str1 str)
(repeat n
   (if (and
  str
  (/= "" str)
       )
     (progn
       (setq teststr (substr str 1 1))
       (if (zgx-singlestr-if-letter teststr)
  (setq kk 1)
  (setq kk 2)
       )
       (setq nn (+ nn kk))
       (setq str (substr str (1+ kk)))
     )
   )
)
(if (>= n 0)
   (substr str1 1 nn)
   (substr str1 1)
)
      )
    )
  )
  (defun zgx-strlen (str / m n)
    (setq m 0)
    (while (/= str "")
      (if (zgx-singlestr-if-letter (substr str 1 1))
(setq n 1)
(setq n 2)
      )
      (setq str (substr str (+ 1 n)))
      (setq m (1+ m))
    )
    m
  )
  (defun zgx-singlestr-if-letter (str)
    (if (wcmatch str (strcat "`" str "*"))
      t
      nil
    )
  )
  (defun zgx-get-dxf (code entname kk)
    (if (= kk 2)
      (assoc code (entget entname))
      (cdr (assoc code (entget entname)))
    )
  )
  (defun zgx-wholestr-if-letter (str / yes)
    (setq yes t)
    (while (and
      (/= "" str)
      yes
    )
      (if (zgx-singlestr-if-letter (substr str 1 1))
(setq str (substr str 2))
(setq yes nil)
      )
    )
    yes
  )
  (defun str->list (str / rtnlst n)
    (setq n 0)
    (repeat (zgx-strlen str)
      (setq rtnlst (append
       rtnlst
       (list (zgx-substr str (setq n (1+ n))
           1
      )
       )
     )
      )
    )
  )
  (defun wholestring_is_chn (str /)
    (vl-some '(lambda (x)
  (not (wcmatch x "#,@,.,。,”,!,,,《,》¥,……,:,;,(,),±,≥,≤,≠,≮,≯,∞,∝,∮,∑,√,∠")) ; 此处为需要作为英文字母处理的中文标点符号
       ) (str->list str)
    )
  )
  (setq n 0)
  (setq key (getstring "\n选择中文{c}/英文{e}:"))
  (setq ss_enlish (ssadd))
  (setq ss_chn (ssadd))
  (prompt "\n请选择文字:")
  (setq ss (ssget '((0 . "text"))))
  (repeat (sslength ss)
    (setq en (ssname ss n)
   text (zgx-get-dxf 1 en 1)
    )
    (if (wholestring_is_chn text)
      (setq ss_chn (ssadd en ss_chn))
      (setq ss_enlish (ssadd en ss_enlish))
    )
    (setq n (1+ n))
  )
  (if (= (strcase key) "C")
    (progn
      (setq string "\n已经选择中文!")
      (sssetfirst nil ss_chn)
    )
    (progn
      (setq string "\n已经选择英文!")
      (sssetfirst nil ss_enlish)
    )
  )
  (princ string)
  (princ)
)

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.