本帖最后由 zhangrunze 于 2025-3-8 08:32 编辑
网上找了一段,统计文本中英文数量切换;

- (vl-load-com)
- ; 修改为你的AganInp.dll路径(注意路径为双斜杠)
- (vl-cmdf "netload" "D:\\Support\\AganInp.dll")
- ; 快捷键定义
- (defun c:pz() (vl-cmdf "agpz")(princ)) ; 打开设置
- (defun c:gbs() (vl-cmdf "GC:UnloadInp")(princ)) ; 手动关闭输入法自动切换
- (defun c:dks() (vl-cmdf "GC:loadInp")(princ)) ; 手动打开输入法自动切换
- ; 文字内容
- (defun text-char-count (text / en-count zh-count char)
- (setq en-count 0 zh-count 0)
- (foreach char (explode text)
- (if (wcmatch char "[a-zA-Z]")
- (setq en-count (+ en-count 1))
- (if (wcmatch char "[\\一-\\龥]")
- (setq zh-count (+ zh-count 1))
- )
- )
- )
- (list en-count zh-count)
- )
- ; 鼠标双击事件处理器
- (defun double_click (a b / en end entype text en-count zh-count)
- (if (setq en (nentselp (trans (car b) 0 1)))
- (progn
- (setq end (entget (car en)))
- (setq entype (cdr (assoc 0 end)))
- (if (wcmatch entype "*TEXT")
- (progn
- (setq text (cdr (assoc 1 end)))
- (if (= entype "MTEXT")
- (setq text (DK:mtext2text text))
- )
- ; 统计中英文字符
- (setq (values en-count zh-count) (text-char-count text))
- (if (> en-count zh-count)
- (GC:cmdend "EN") ; 切换为英文
- (GC:cmdstart "中文") ; 切换为中文
- )
- )
- )
- )
- )
- (princ)
- )
没有成功......
|