乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 100|回复: 4

[编程交流] 查找/替换属性块

[复制链接]

1

主题

1

帖子

0

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 23:56:16 | 显示全部楼层 |阅读模式
你好我开始写一些代码,但我的时间不多了,我需要在本周完成。我想做的是用一个窗口创建一个带有块的选择集。搜索这些块内的属性值,如果它与旧值匹配,则替换为新值。
(defun C:TEST()(setq STOLPNR\u OLD“06169”)(setq STOLPNR\u NEW“TEST050”)(setq ss1(ssget))(setq Att1“#STOLPNR”);attribute tag i stolpe(foreach att(vlax invoke(vlax ename->vla object(ssname SS1 0))'getattributes)(if(=Att1(strcase(vla get tagstring att))(if(=STOLPNR\u OLD(strcase(vla get textstring att)))(vla put textstring att STOLPNR\u NEW));如果结束);如果结束);结束foreach);结束defun
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 00:12:08 | 显示全部楼层
欢迎来到cadTutor。
 
您希望用另一个值替换的旧值是什么?当然,新的价值是什么?
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 00:35:52 | 显示全部楼层
我在第一篇文章中没有阅读你的代码,所以我想这应该是直截了当的。
 
试试看,让我知道。。。
 
  1. (defun c:Test (/ ss)
  2. ;;    Tharwat 27.11.2013    ;;
  3. (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
  4.    ((lambda (u / sn e)
  5.       (while (setq sn (ssname ss (setq u (1+ u))))
  6.         (while (and (setq sn (entnext sn)) (/= (cdr (assoc 0 (setq e (entget sn)))) "SEQEND"))
  7.           (if (and (eq (cdr (assoc 1 e)) "06169") (eq (strcase (cdr (assoc 2 e))) "#STOLPNR"))
  8.             (entmod (subst (cons 1 "TEST050") (assoc 1 e) e))
  9.           )
  10.         )
  11.       )
  12.     )
  13.      -1
  14.    )
  15. )
  16. (princ)
  17. )
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-6 00:54:34 | 显示全部楼层
请阅读代码发布指南并编辑您的帖子,将您的代码包含在代码标签中。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 01:09:01 | 显示全部楼层
这是一个工作VL版本更改2块
 
  1. ; changes to issued for construction
  2. : thanks to lee mac for original code
  3. (vl-load-com)
  4. ; 1.  Get current date in mm/dd/yy format.
  5. (defun ddmmyy (/ x today)
  6.     (setvar "cmdecho" 0)
  7.     (setq x (getvar "CDATE"))                 ; get current date
  8.     (setq today ( rtos x 2 4))                    ; convert to a string
  9.     (setq date (strcat (substr today 7 2) "."    (substr today 5 2) "." (substr today 3 2) ))
  10. )
  11. (setq oldtag1 "DRAWING_STATUS") ;attribute tag name
  12. (setq newstr1 "ISSUED FOR CONSTRUCTION")
  13. (setq oldtag2 "REV_NO")  ;attribute tag name
  14. (setq newstr2 "0")
  15. (setq ss1 (ssget "x"  '((0 . "INSERT") (2 . "DA1DRTXT"))))
  16. (setq inc (sslength ss1))
  17. (repeat inc      
  18. (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (setq inc (1- inc)) )) 'getattributes)
  19. (if (= oldtag1 (strcase (vla-get-tagstring att)))
  20. (vla-put-textstring att newstr1)
  21. ) ; end if
  22. (if (= oldtag2 (strcase (vla-get-tagstring att)))
  23. (vla-put-textstring att newstr2)
  24. ) ; end if
  25. ) ; end for
  26. ) ;end repeat
  27. (setq oldtag1 "REV-NO")
  28. (setq newstr1 "0")
  29. (ddmmyy)
  30. (setq oldtag2 "DATE")
  31. (setq newstr2 date)
  32. (setq oldtag3 "AMENDMENT")
  33. (setq newstr3 "ISSUED FOR CONSTRUCTION")
  34. (setq ss2 (ssget "x"  '((0 . "INSERT") (2 . "REVTABLE"))))
  35. (setq inc (sslength ss2))
  36. (repeat inc
  37. (foreach att (vlax-invoke (vlax-ename->vla-object (ssname ss2 (setq inc (1- inc)))) 'getattributes)
  38. (if (= oldtag1 (strcase (vla-get-tagstring att)))
  39. (vla-put-textstring att newstr1)
  40. )
  41. (if (= oldtag2 (strcase (vla-get-tagstring att)))
  42. (vla-put-textstring att newstr2)
  43. )
  44. (if (= oldtag3 (strcase (vla-get-tagstring att)))
  45. (vla-put-textstring att newstr3)
  46. )
  47. )
  48. )
  49. (setq ss1 nil)
  50. ; (setq ss2 nil)
  51. (princ)
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 21:24 , Processed in 0.553009 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表