明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 625|回复: 4

[提问] 在ssget中如何添加设置功能

[复制链接]
发表于 2023-10-31 17:21 | 显示全部楼层 |阅读模式
想写一个后缀函数,思路是这样的,先选择一个文字,选择中添加一个设置功能,用来设置步长。然后通过正则表达式提取后缀数字部分,将文字分离成前部字符串和后缀字符串两部分,每点选一次其他文字,后缀字符串+1个步长,然后和前部字符串合并,通过组码替换掉点选文字的内容。

现在问题是initget关键字对ssget无效,设置这个步骤无法完成。请大神们帮我看看,这个要怎么搞。

  1. ;[功能]更改图元、图元表、选择集DXF组码以修改实体属性
  2. ;[用法](xyp-SubUpd 实体名 DXF码 新值)
  3. (defun xyp-SubUpd (ename code val / ent x y i s1)
  4.   (cond ((= (type ename) 'ENAME)
  5.   (setq ent (entget ename))
  6.   (if (and (= (type code) 'LIST) (= (type val) 'LIST))
  7.     (mapcar '(lambda (x y) (xyp-SubUpd ename x y)) code val)
  8.     (progn
  9.       (if (= (xyp-get-dxf code ename) nil)
  10.         (entmod (append ent (list (cons code val))))
  11.         (entmod (subst (cons code val) (assoc code ent) ent))
  12.       )
  13.       (entupd ename)
  14.     )
  15.   )
  16. )
  17. ((= (type ename) 'PICKSET)
  18.   (setq i -1)
  19.   (while (setq s1 (ssname ename (setq i (1+ i))))
  20.     (xyp-SubUpd s1 code val)
  21.   )
  22. )
  23. ((= (type ename) 'LIST)
  24.   (foreach s1 ename (xyp-SubUpd s1 code val))
  25. )
  26.   )
  27.   ename
  28. )
  29. ;[功能]根据DXF组码表、图元名,对应点对列表
  30. ;[用法](xyp-get-DXF DXF码 图元名)
  31. (defun xyp-get-DXF (code ename / ent lst a)
  32.   (if (= (type code) 'LIST)
  33.     (progn
  34.       (setq ent        (entget ename)
  35.             lst        '()
  36.       )
  37.       (foreach a code
  38.         (setq lst (cons (list a (cdr (assoc a ent))) lst))
  39.       )
  40.       (reverse lst)
  41.     )
  42.     (if        (= code -3)
  43.       (cdr (assoc code (entget ename '("*"))))
  44.       (cdr (assoc code (entget ename)))
  45.     )
  46.   )
  47. )
  48. ;[功能]提取字符串尾部数字
  49. ;[用法](wbstr String),String为字符串
  50. (defun wbstr (String / regex S tmp str1)
  51. (setq regex (vlax-create-object "Vbscript.RegExp")) ;引用正则表达式控件
  52. (vlax-put-property regex "IgnoreCase" 0) ;不忽略大小写
  53. (vlax-put-property regex "Global" 1) ;匹配方式,全文字匹配
  54. (vlax-put-property regex "Multiline" 1) ;多行模式
  55. (vlax-put-property regex "Pattern" "[0-9]+(?=[^0-9]*$)")
  56. (setq s (vlax-invoke-method regex "Execute" String))
  57.   ;;将规则运用到STR字符,得到提取出的文字内容
  58.   (setq ent (VLAX-FOR tmp s (vlax-get-property tmp "value")))
  59.   (vlax-release-object regex)
  60.   (setq ent (atoi ent))
  61.   ent
  62. )
  63. ;;后缀主函数
  64. (defun c:hz(/ SS DZ EN TXT N2 TXT-WB N-WB TXT1 EN_XG TXT2)
  65.   (if (null *dz*) (setq *dz* 1))
  66.   (while
  67.     (progn
  68.       (initget 2 "S")
  69.       (setq ss (ssget ":E:S" (car (list '((0 . "*text")) (princ (strcat "\n参照文本或:[设置步长(S)_" (rtos *dz* 2 2)"]"))))));;参照文本或设置步长
  70.       (cond
  71.       ((and (eq (type ss) 'STR)(eq (strcase ss) "S"))
  72.                 (initget (+ 2 4));非零非负
  73.                 (setq *dz* (cond ((getint (strcat "\n输入步长<" (rtos *dz* 2 2) ">:"))) (*dz*)))
  74.         T;;继续循环
  75.              )
  76.       ((and ss (eq (type ss) 'PICKSET))
  77.         (setq en (ssname ss 0))
  78.         (setq txt (xyp-get-DXF 1 en))
  79.         (setq n2 (strlen txt))
  80.         (setq txt-wb (wbstr txt));;获得尾部数字,整形
  81.         (setq n-wb (strlen (itoa txt-wb)))
  82.         (setq txt1 (substr txt 1 (- n2 n-wb)));;获得尾部数字前的字符串
  83.         (while (setq en_xg (car(entsel"\n选择修改文本")))
  84.           (setq txt-wb (itoa(+ txt-wb *dz*)));尾部数字+步长
  85.           (setq txt2 (strcat txt1 txt-wb))
  86.           (xyp-SubUpd en_xg 1 txt2)
  87.           (setq txt-wb (atoi txt-wb))
  88.         )
  89.       nil;;结束循环
  90.       )
  91.     )))
  92.   (princ)
  93. )


发表于 2023-10-31 18:15 | 显示全部楼层
 楼主| 发表于 2023-10-31 18:42 | 显示全部楼层
本帖最后由 hubeiwdlue 于 2023-10-31 18:48 编辑

谢谢飞雪神光,也谢谢飞诗大神。关于(Fsxm-ssget msg kwd fil)的应用,fil这个参数填写'((0 . "*text"))之类的都没问题,前面控制鼠标的部分,比如":E:S",是否能写进去,如果能,应该怎么写进去呢。
发表于 2023-10-31 19:44 | 显示全部楼层
 楼主| 发表于 2023-10-31 20:09 | 显示全部楼层
飞雪神光 发表于 2023-10-31 19:44
这有个优化过的http://bbs.mjtd.com/forum.php?mod=viewthread&tid=185377&highlight=ssget

谢谢拉。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-6-3 08:40 , Processed in 0.145102 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表