文字编辑时,可以加入文字中英文数量识别的功能吗?
当中文文字数量多的时候切换为中文输入法
当英文文字数量多的时候切换为英文输入法
网上看见的代码,也不懂搞~
 - (defun c:SmartSwitchIME (/ GetTextContent AnalyzeTextRatio)
- ;; 获取当前编辑的文本内容
- (defun GetTextContent ()
- (if (setq ent (car (entsel)))
- (vla-get-textstring (vlax-ename->vla-object ent))
- ""
- )
- )
- ;; 中英文字符比例分析
- (defun AnalyzeTextRatio (str)
- (setq chn_cnt (length (vl-remove-if-not '(lambda (x) (wcmatch (chr x) "[一-龥]")) (vl-string->list str))))
- (setq eng_cnt (- (strlen str) chn_cnt))
- (if (> chn_cnt eng_cnt) 1 0)
- )
- ;; 命令监听逻辑
- (defun OnCommandEnded (cmd)
- (if (wcmatch cmd "MTEXT*,TEXT*,DDEDIT*")
- (progn
- (setq txt (GetTextContent))
- (if (= (AnalyzeTextRatio txt) 1)
- (command "_IMESetStatus" 1) ;中文输入法‌:ml-citation{ref="5" data="citationList"}
- (command "_IMESetStatus" 0) ;英文输入法‌:ml-citation{ref="5" data="citationList"}
- )
- )
- )
- )
- (vlr-command-reactor nil '((:vlr-commandended . OnCommandEnded)))
- (princ "\n智能输入法切换已启用。")
- )
|