乐筑天下

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

[编程交流] 全局替换每个值o

[复制链接]

1

主题

1

帖子

0

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 22:29:25 | 显示全部楼层 |阅读模式
大家好,我想在每个具有属性的块中用类似“Att\u 11”的标记替换属性的值。要替换的当前值在任何块中都可能不同。我尝试了(command-attedit“n”“n”“*”“Att_11”“*”)。但当它要求更改值时,它不接受通配符:有没有其他方法来告诉函数,我想替换存储在该属性中的每个当前值,即使我不知道哪些值是当前值?感谢您的时间和关注。fabio
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 22:39:42 | 显示全部楼层
欢迎来到CADTutor。
 
您是否根据属性的标记名更改了属性值?如果是,标记名字符串是什么?
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 22:45:58 | 显示全部楼层
下面是更改块中每个属性的示例。在这种情况下,块是布局中的标题栏,但无论在dwg中的何处,都会找到每个块。
 
  1. ; changes to project number
  2. (vl-load-com)
  3. (setq oldtag1 "your block tag name") ;attribute tag name in capitals
  4. (setq newstr1 (getstring "\nEnter project code"))
  5. (setq ss1 (ssget "x"  '((0 . "INSERT") (2 . "yourblockname"))))  
  6. (setq inc (sslength ss1))
  7. (repeat inc      
  8. (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (setq inc (1- inc)) )) 'getattributes)
  9. (if (= oldtag1 (strcase (vla-get-tagstring att)))
  10. (vla-put-textstring att newstr1)
  11. ) ; end if
  12. ) ; end for
  13. ) ;end repeat
  14. (setq ss1 nil)
  15. (princ)
回复

使用道具 举报

15

主题

315

帖子

361

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-5 22:48:01 | 显示全部楼层
这就是你需要的。
 
命令:RB(如在读取块中);可以随意重命名底部函数
在该函数中,您可以设置模式(现在是“*”)新的价值观(现在是“你好,世界!”)
(当我将模式设置为带小大写字母的“*”,这给我带来了问题;
使用大写字母,它可以工作(对于我的dwg)
 
(顺便说一句,标签应该是大写字母,最好没有特殊字符,除了“_”,但那只是我,我在这类事情上有点过时了)
 
如果它不完全符合你的期望,请告诉我。
 
现在,星号需要在在中间的某个地方。它需要前面有东西,后面有东西。(我应该解决这个问题)
 
  1. ;; @file  : Kind of a QSELECT, where we select blocks with attributes with a certain pattern with wildcard
  2. ;; @author: Emmanuel Delay - emmanueldelay@gmail.com - september 2014
  3. ;; - First thing, we want a system for wild cards.  The pattern is ""*"", where the * is the wildcard.
  4. ;; so we want to find values like ""Att_11""
  5. ;; - We want to find all blocks in the dwg with an attribute where the tag has such a pattern.
  6. ;; - We give all those attributes a new value
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;; Read blocks with attributes, pass through wildcard, set value to attributes
  9. (defun readBlocks (pattern newValue / blocks block i)
  10. (setq
  11.    i 0
  12.    blocks (ssget "x"  '((0 . "INSERT")(66 . 1)) )
  13. )
  14. (repeat (sslength blocks)
  15.    (setq block (vlax-ename->vla-object (ssname blocks i)))
  16.    (foreach att (vlax-invoke  block 'GetAttributes)
  17.      (setq tag (vla-get-tagstring att))
  18.      (if (wildcard pattern tag)
  19.        (LM:vl-setattributevalue block tag newValue)
  20.      )
  21.    )
  22.    (setq i (+ i 1))
  23. )  
  24. )
  25. ;; Set Attribute Value  -  Lee Mac
  26. ;; Sets the value of the first attribute with the given tag found within the block, if present.
  27. ;; blk - [vla] VLA Block Reference Object
  28. ;; tag - [str] Attribute TagString
  29. ;; val - [str] Attribute Value
  30. ;; Returns: [str] Attribute value if successful, else nil.
  31. ;; @see http://www.lee-mac.com/attributefunctions.html#vlgetattributevalue
  32. (defun LM:vl-setattributevalue ( blk tag val )
  33.    (setq tag (strcase tag))
  34.    (vl-some
  35.       '(lambda ( att )
  36.            (if (= tag (strcase (vla-get-tagstring att)))
  37.                (progn (vla-put-textstring att val) val)
  38.            )
  39.        )
  40.        (vlax-invoke blk 'getattributes)
  41.    )
  42. )
  43. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  44. ;; String operations
  45. ;; Wild card.  Compares two strings: a pattern containing 1 "*" character; and a value to be evaluated.
  46. ;; Returns T if the value contains the pattern
  47. ;; examples:
  48. ;; (wildcard "AZERTYU*IOP" "AZERTYU12345IOP")   ;; returns T
  49. ;; (wildcard "AZERTYU*IOP" "AZRTYU12345IOP")    ;; returns nil
  50. (defun wildcard (pattern val / result startString endString asteriskPlace charsLeft)
  51. ;; we search for the place of the asterisk in the string.  (nil = nothing found)
  52. (setq
  53.    asteriskPlace (vl-string-search "*" pattern)
  54.    charsLeft (- (- (strlen pattern) 1) asteriskPlace)
  55.    result nil
  56. )
  57. (if (= asteriskPlace nil)
  58.    (setq result nil)  ;; no asterisk in found in the pattern
  59.    (progn
  60.      (setq startString (substring pattern 0 asteriskPlace))  
  61.      (setq endString (substring pattern (- 0 charsLeft) nil))  
  62.      (if (and    ;; so we check if the start and end of the pattern and value are equal
  63.          (= startString (substring val 0 asteriskPlace))
  64.          (= endString (substring val (- 0 charsLeft) nil))
  65.        )
  66.        (setq result T)
  67.        (setq result nil)
  68.      )
  69.    )
  70. )
  71. result
  72. )
  73. ;; I want substr to work like it does in PHP (and most languages I know).  the lisp subst is too limited
  74. ;; So I made my own substring
  75. ;; [complaint]unlike civilized languages, for some reason substr is "1-based" (first character of start is 1); who ever invented this ...[/complaint]
  76. ;; also I add negative numbers to the start parameter.
  77. ;; A start of -2 means it starts looking at the second-last character
  78. ;; set len to nil to let the lenth parameter empty
  79. ;;
  80. ;; examples:
  81. ;; (substring "AZERTYUIOP" 3 4)       returns "RTYU"      ;; start from letter 3 (0 based), give 4 letters
  82. ;; (substring "AZERTYUIOP" 4 nil)     returns "TYUIOP"    ;; start from letter 4 (0 based), give all the rest of the letters
  83. ;; (substring "AZERTYUIOP" -3 nil)    returns "IOP"       ;; start from the last 3 letters, give all the rest of the letters
  84. ;; (substring "AZERTYUIOP" -5 2)      returns "YU"        ;; start from the last 5 letters, give 2 letters
  85. (defun substring (string start len / st ln)
  86. (if (< start 0)
  87.    (setq st (+ (strlen string) (+ start 1)))
  88.    (setq st (+ start 1))
  89. )
  90. (if (= len nil)
  91.    (setq ln (strlen string))
  92.    (setq ln len)
  93. )
  94. (substr string st len)
  95. )
  96. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  97. (defun c:rb ()
  98. (readBlocks  "&QUOT;*&QUOT;" "Hello World!")
  99. (princ)
  100. )
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 22:55:26 | 显示全部楼层
你好,Emmanuel,
 
首先,感谢您遵守保留我的函数附带的代码头的礼节,我真的非常感谢您的这一小礼节。
 
下面是编写“子字符串”函数的另一种方法,供您考虑:
关于“通配符”函数,为什么不使用AutoLISP wcmatch函数?此功能的文档可在此处找到。
 
回复

使用道具 举报

15

主题

315

帖子

361

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-5 23:00:46 | 显示全部楼层
我在其他语言中也有同样的问题。如果我没有找到它,我自己写,而不是看起来更努力一点。
 
我将在周一尝试这两个功能。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 23:09:36 | 显示全部楼层
关于名字中的大写字母问题,你可以使用STRCASE强制所有大写字母,毕竟英语字母表中有52个字符。
回复

使用道具 举报

15

主题

315

帖子

361

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-5 23:16:01 | 显示全部楼层
好的,她是改进的代码。
 
感谢李和比格尔
 
看起来一切都在按照要求进行
 
  1. 3
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 23:22:06 | 显示全部楼层
@Emmanuel延迟
 
首先,在例程中包含了不需要的函数子字符串。
然后,您已经检索了两次属性,一次在函数readblocks中,另一次已经由Lee LM:vl setattributevalue函数支持
回复

使用道具 举报

15

主题

315

帖子

361

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-5 23:23:57 | 显示全部楼层
哦,是的,我不再需要子字符串了,对吗。
是的,李的函数再次读取属性;我还是喜欢用它。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 06:21 , Processed in 0.933336 second(s), 83 queries .

© 2020-2025 乐筑天下

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