乐筑天下

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

[编程交流] 匹配最新属性v

[复制链接]

6

主题

47

帖子

41

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 16:15:04 | 显示全部楼层 |阅读模式
Commandobill不久前写了一些代码。我需要调整一下。下面的蓝色代码需要更改,我正在绞尽脑汁。我需要REV块中最高REV属性的值进入“REV”属性,而不是手动替换属性值。代码当前查找最高的REV属性,但随后用手动文本替换。
 
为了取代蓝色,我需要一些类似的东西:
(cb:replaceAttributeValue“REV”(最高REV的属性值,例如:5表示REV5)(vlax ename->vla object x))
 
大部分代码已经在这里了,它只是让cb:replaceAttributeValue函数将“REV”的属性值与revblock中最高REV的属性值匹配(例如,属性REV 5为5)。
 
(vl load com)
(defun c:test11(/blockSS blockList attName attNumber)
(如果
(setq blockSS(ssget“X”(列表(cons 0“插入”)(cons-4“”))
(程序
(setq区块列表(mapcar’cadr(ssnamex blockSS)))
(setq attName(vla get tagstring(car(cb:matchAtts“REV”“REV”(vlax ename->vla object(car blockList)ϞϞ))))
(setq attNumber(substr attName(strlen attName)1))
(mapcar’(λ(x))
(cb:replaceAttributeValue(strcat“DATE”attNumber)“15年6月29日”(vlax ename->vla object x))
(cb:replaceAttributeValue(strcat“DESC”attNumber)“基线更新-101/111翻新”(vlax ename->vla object x)))
区块列表)
))
(普林斯)
 
)
 
(defun cb:matchAtts(baseAttName attPrefix Blk/)
(setq baseAtt(car(vl remove if not’(lambda(x)(=baseAttName(vla get tagstring x))))(cb:variantToList(vla getattributes Blk ()))))
(如果不是,则vl移除’(λ(x)
(和
(wcmatch(vla get tagstring x)(strcat attPrefix“*”)
(非(eq(vla get tagstring x)baseAttName))
(等式(vla get textstring x)(vla get textstring baseAtt))
))
(cb:variantToList(vla getattributes Blk)))
)
 
(defun cb:variantToList(theVariant/)
(如果(='变体(键入变体))
(vlax safearray->列表(vlax variant value theVariant))

)
)
 
;;;;;替换属性值;;;;;;;;;
;;;;;签字人:CommandoBill;;;;;;;;;;;;;;;;;
;;;;;01/24/15;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;向该函数发送一个块,其中包含要用新值替换的属性
;;;;attName=要替换其值的属性的名称
;;;;attNewVal=属性中需要的新值
;;;;Blk=属性所在块的vla对象验证
 
(defun cb:replaceAttributeValue(attName attNewVal Blk/)
(mapcar’(λ(x)(if(=attName(vla get tagstring x))
(vla put textstring x attNewVal))(cb:variantToList(vla getattributes Blk)))
(普林斯)
)
回复

使用道具 举报

6

主题

47

帖子

41

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 16:20:23 | 显示全部楼层
  1. (cb:replaceAttributeValue (strcat "DATE" attNumber) "29-JUN-15" (vlax-ename->vla-object x)) [code]<p> </p><p>The above code replaces the attribute value (strcat "DATE" attNumber), which could be an attribute with the tag DATE1, or DATE2, or DATE3, ect. depending on which line in the revision block has the most current revision.</p><p> </p><p>What I want to do is replace attribute REV with the attribute value in (strcat "REV" attNumber). For this particular title block, let's say this attribute is REV5 and the value is 12. I need to pass the value of REV5 (12) to REV so they both say 12. Currently the value of REV is most likely X by default because the routine I use to swap title blocks doesn't know what REV should be.</p>
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 16:23:59 | 显示全部楼层
发布dwg,两块标题栏和修订栏?
回复

使用道具 举报

6

主题

47

帖子

41

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 16:26:47 | 显示全部楼层
大阿尔,
 
谢谢你善良的先生。我目前没有访问实际文件的权限,但我重新创建了一个快速的临时标题栏,它应该足以证明概念。
 
右下角有一个REV属性,显示当前图形的REV。
 
上面有REV块。它可以容纳6个版本。每个属性都被命名为REV1、REV2到REV6。目前,我将图形设置为第5版,并在REV5属性中添加了值5。事实上,这个值可以是任何值,因为只有6个可能的修订版本,例如,图纸可以在REV5位置达到修订版100,但我只是保持简单。
 
也就是说,我需要获得最新版本或最新版本属性值的代码(在本例中,REV5为5),并在右下角的REV属性中设置相同的值。我确实有成千上万的图纸,其中旧标题栏在右下角没有REV属性。
 
我在本线程开头发布的代码中的cb:matchAtts子函数似乎可以找到最新版本。我认为需要调整的是cb:replaceAttributeValue子函数。目前,它将REV处的值替换为REV5,即标记名,在本例中,它需要是属性(5)的实际值。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 16:30:19 | 显示全部楼层
从零开始要容易得多。作为测试,它只执行一个布局,但可以很容易地修改以检查所有布局。只有一个错误检查您没有超过1个块。
 
  1. ; daballz lisp
  2. ; by Alan H june 2017
  3. ; hard coded for the block
  4. (defun c:daballz  ( / blockss x y atts obj tagname lookfor revtemp)
  5. (setq blockSS (ssget "X" (list (cons 0 "INSERT") (cons -4 "<xor") (cons 2 "Drawing_Sheet_22x34") (cons 2 "Drawing_Sheet_22x34-H") (cons -4 "xor>"))))
  6. (if (> 1 (setq x (sslength blockss))) ; make sure only one title block
  7. (progn
  8. (Alert "You have more than 1 title block on this page\n\nprogram will exit")
  9. (exit) ; hard coded exit not vey gracefull
  10. )
  11. (princ "ok") ; dummy statement
  12. )
  13. (setq obj (vlax-ename->vla-object (ssname blockss 0))) ; get the 1st obj inside the selection set
  14. (setq atts (reverse  (vlax-invoke obj  'getattributes))) ; get all the attributes and convert to a list
  15. (setq x 1)
  16. (repeat (setq y (length atts )) ; loop for all attributes
  17. (setq lookfor (strcat "REV" (rtos x 2 0))) ; add a number as a string to "REV"
  18. (setq tagname (vla-get-tagstring (nth  (setq y (- y 1))  atts))) ; get attribute 1 at a time
  19. (if (= tagname  lookfor) ; check for match tag names
  20. (setq revtemp (vla-get-textstring (nth  y  atts))) ; if true set temp value repeat for highest number
  21. )
  22. (if  (and (/=  revtemp "" )(< x 7)) ; double check for a blank field and no more than 6 revisions
  23. (progn
  24. (setq revval revtemp)
  25. (setq x (+ x 1))
  26. (setq revtemp "") ; needed to make sure resets inside loop
  27. )
  28. )
  29. )
  30. (setq lookfor  "REV" ) ; destination tag name
  31. (repeat  (setq y (length atts )) ; loop through the attributes
  32. (setq tagname (vla-get-tagstring (nth  (setq y (- y 1))  atts))) ; get tagstring of a attribute
  33. (if (= tagname lookfor) ; test for match
  34. (vla-put-textstring (nth  y  atts) revval) ; if match change value
  35. )
  36. )
  37. )
  38. (c:daballz)
回复

使用道具 举报

6

主题

47

帖子

41

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 16:34:40 | 显示全部楼层
我的朋友,真是了不起的作品。它现在正在工作。我不得不调整一下,但在日常生活中,大部分的逻辑是我一直在努力解决的。再次感谢。
回复

使用道具 举报

6

主题

47

帖子

41

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 16:36:57 | 显示全部楼层
现在,我在AutoCAD 2014中的实际标题栏上运行此操作,并得到以下错误:
 
命令:REVMATCH
好啊错误:ActiveX服务器返回错误:参数不是可选的
 
我将代码放在(defun c:REVMATCH(/)中,并添加了一个(vl load com),但仍然出现了这个错误。
 
有什么想法吗?它正在AutoCAD 2015上使用具有完全相同的块名和属性标记名的模拟块。。。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 16:41:46 | 显示全部楼层
我已经编辑了上面的代码,以匹配您的REVMATCH,并对照您的示例dwg进行了检查。
回复

使用道具 举报

6

主题

47

帖子

41

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 16:45:04 | 显示全部楼层
块名称和属性名称相同,但块是否具有样例图形中未包含的其他特性和其他属性,这有关系吗?我一有机会就会给你发送真正的标题栏。
回复

使用道具 举报

6

主题

47

帖子

41

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 16:50:16 | 显示全部楼层
这是工作标题栏。我的vcom可能有问题。dll,现在正在工作。如果你在这台上运行它,它会工作。。。让我知道。此外,我正在运行AutoCAD 2014。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 16:36 , Processed in 0.969623 second(s), 72 queries .

© 2020-2025 乐筑天下

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