行空雕 发表于 2015-1-28 08:38:03

关于CAD中统计中文字个数的代码

本帖最后由 行空雕 于 2015-1-28 08:50 编辑

好友翻译CAD图纸,按字数收费,想统计中文字个数,故写了这些代码,分享给大家~
01 LISP统计函数<div class="blockcode"><blockquote>(defun c:tt()
(setvar "cmdecho" 0)
(setq ss (ssget "X" (list (cons 0 "text"))));选择图面所有文字
(setq n (sslength ss))
(setq i 0 zf 0)
(repeat n
    (setq txt (entget (ssname ss i)))
    (setq i (+ i 1))
    (setq sr1 (cdr (assoc 1 txt)))
    (setq m 0)
    (repeat (strlen sr1)
      (setq asc (vl-string-elt sr1 m))
      (if (> asc 129 )
(if (/= asc 161);以下是为了屏蔽 ,。”“
    (if (/= asc 163)
      (if (/= asc 172)
      (if (/= asc 177)
    (if (/= asc 187)
      (setq zf (+ zf 1))
      )
    )
      )
    )
   )
      )
      (setq m(+ m 1))
      )
    )
(setq zf (/ zf 2))
;(setq zf (- zf 1))
(dcl_01) ;调用显示对话框
(print)
)

(defun dcl_01()   ;调用显示对话框函数
(setq dcl_id (load_dialog "dcl_tj"))
(new_dialog "dcl_tj" dcl_id)
(set_tile "ZW_SL" (itoa zf))
(start_dialog)
)
02 对话框函数dcl_tj:dialog{
label="Blue_EP的对话框";
:concatenation{
    :text_part {label="共有中文: 【";}
    :text {width=6;key="ZW_SL";}
                :text_part{label="】";}
    }
    ok_cancel;
}

行空雕 发表于 2015-1-28 08:40:20

上述代码不能统计块中的固定中文字和属性块的中文字

newbuser 发表于 2015-1-28 15:59:29

不错,某些特定的用途会用得着。收下了。
页: [1]
查看完整版本: 关于CAD中统计中文字个数的代码