想写一个后缀函数,思路是这样的,先选择一个文字,选择中添加一个设置功能,用来设置步长。然后通过正则表达式提取后缀数字部分,将文字分离成前部字符串和后缀字符串两部分,每点选一次其他文字,后缀字符串+1个步长,然后和前部字符串合并,通过组码替换掉点选文字的内容。
现在问题是initget关键字对ssget无效,设置这个步骤无法完成。请大神们帮我看看,这个要怎么搞。
- ;[功能]更改图元、图元表、选择集DXF组码以修改实体属性
- ;[用法](xyp-SubUpd 实体名 DXF码 新值)
- (defun xyp-SubUpd (ename code val / ent x y i s1)
- (cond ((= (type ename) 'ENAME)
- (setq ent (entget ename))
- (if (and (= (type code) 'LIST) (= (type val) 'LIST))
- (mapcar '(lambda (x y) (xyp-SubUpd ename x y)) code val)
- (progn
- (if (= (xyp-get-dxf code ename) nil)
- (entmod (append ent (list (cons code val))))
- (entmod (subst (cons code val) (assoc code ent) ent))
- )
- (entupd ename)
- )
- )
- )
- ((= (type ename) 'PICKSET)
- (setq i -1)
- (while (setq s1 (ssname ename (setq i (1+ i))))
- (xyp-SubUpd s1 code val)
- )
- )
- ((= (type ename) 'LIST)
- (foreach s1 ename (xyp-SubUpd s1 code val))
- )
- )
- ename
- )
- ;[功能]根据DXF组码表、图元名,对应点对列表
- ;[用法](xyp-get-DXF DXF码 图元名)
- (defun xyp-get-DXF (code ename / ent lst a)
- (if (= (type code) 'LIST)
- (progn
- (setq ent (entget ename)
- lst '()
- )
- (foreach a code
- (setq lst (cons (list a (cdr (assoc a ent))) lst))
- )
- (reverse lst)
- )
- (if (= code -3)
- (cdr (assoc code (entget ename '("*"))))
- (cdr (assoc code (entget ename)))
- )
- )
- )
- ;[功能]提取字符串尾部数字
- ;[用法](wbstr String),String为字符串
- (defun wbstr (String / regex S tmp str1)
- (setq regex (vlax-create-object "Vbscript.RegExp")) ;引用正则表达式控件
- (vlax-put-property regex "IgnoreCase" 0) ;不忽略大小写
- (vlax-put-property regex "Global" 1) ;匹配方式,全文字匹配
- (vlax-put-property regex "Multiline" 1) ;多行模式
- (vlax-put-property regex "Pattern" "[0-9]+(?=[^0-9]*$)")
- (setq s (vlax-invoke-method regex "Execute" String))
- ;;将规则运用到STR字符,得到提取出的文字内容
- (setq ent (VLAX-FOR tmp s (vlax-get-property tmp "value")))
- (vlax-release-object regex)
- (setq ent (atoi ent))
- ent
- )
- ;;后缀主函数
- (defun c:hz(/ SS DZ EN TXT N2 TXT-WB N-WB TXT1 EN_XG TXT2)
- (if (null *dz*) (setq *dz* 1))
- (while
- (progn
- (initget 2 "S")
- (setq ss (ssget ":E:S" (car (list '((0 . "*text")) (princ (strcat "\n参照文本或:[设置步长(S)_" (rtos *dz* 2 2)"]"))))));;参照文本或设置步长
- (cond
- ((and (eq (type ss) 'STR)(eq (strcase ss) "S"))
- (initget (+ 2 4));非零非负
- (setq *dz* (cond ((getint (strcat "\n输入步长<" (rtos *dz* 2 2) ">:"))) (*dz*)))
- T;;继续循环
- )
- ((and ss (eq (type ss) 'PICKSET))
- (setq en (ssname ss 0))
- (setq txt (xyp-get-DXF 1 en))
- (setq n2 (strlen txt))
- (setq txt-wb (wbstr txt));;获得尾部数字,整形
- (setq n-wb (strlen (itoa txt-wb)))
- (setq txt1 (substr txt 1 (- n2 n-wb)));;获得尾部数字前的字符串
- (while (setq en_xg (car(entsel"\n选择修改文本")))
- (setq txt-wb (itoa(+ txt-wb *dz*)));尾部数字+步长
- (setq txt2 (strcat txt1 txt-wb))
- (xyp-SubUpd en_xg 1 txt2)
- (setq txt-wb (atoi txt-wb))
- )
- nil;;结束循环
- )
- )))
- (princ)
- )
|