乐筑天下

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

[编程交流] 动态块,属性名称

[复制链接]

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 18:09:51 | 显示全部楼层 |阅读模式
大家好,我正在开发一些经过大量修改的lisp例程(源于Lee Mac),我正在尝试用lisp为有效的块名和许多属性名及其值设置引号。
我知道有LM的子函数来获取属性,它返回assoc列表,其中包含:
  1. ((<Tag> . <Value>) ... )

如果有人能给我举个例子,告诉我如何为每个标签和值设置报价,我会更喜欢这个。例如,如果我选择一个动态块以获得其有效名称的提示,以及一个如下列表:
“ATTname N”的值为“ATTvalue N”
 
无论如何,以下是我失败的尝试:
  1. ;Trying to obtain effective blockname, a attribute name and its attribute value
  2. ;I am going to use "foreach" function, and different conditions, based on that attribute value
  3. (defun c:test ( / i o s )
  4. (setq MyBlockName (getstring T "\nType the name of the Block to look for:"))
  5. (setq MyAttributeName1 (getstring T "\nType the name of the Attribute1 to look for:"))
  6. (setq MyAttributeName2 (getstring T "\nType the name of the Attribute2 to look for:"))
  7.    (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "`*U*,MyBlockName"))))
  8.        (repeat (setq i (sslength s))
  9.            (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
  10.            (if (and (vlax-property-available-p o 'effectivename)
  11.                     (= MyBlockName (strcase (vla-get-effectivename o) t))
  12.                )
  13.                (progn
  14.                    (princ (strcat "\nFound " MyBlockName " block "" (vla-get-handle o) ""."))
  15.                    (if (setq MyAttributeValue1 (LM:vl-getattributevalue o MyAttributeName1))
  16.                        (progn
  17.                           (princ (strcat "\nFound the block named " MyBlockName " !"))
  18.                           (princ (strcat "\nFound the attribute named " MyAttributeName1 " !"))
  19.                           (princ (strcat "\nThe value of that attribute is " MyAttributeValue1 " !"))
  20.                        );progn
  21.                        (princ "\n"MyAttributeName1" attribute not found in "MyBlockName" block.")
  22.                    );if
  23.                    (if (setq MyAttributeValue2 (LM:vl-getattributevalue o MyAttributeName2))
  24.                        (progn
  25.                           (princ (strcat "\nFound the block named " MyBlockName " !"))
  26.                           (princ (strcat "\nFound the attribute named " MyAttributeName2 " !"))
  27.                           (princ (strcat "\nThe value of that attribute is " MyAttributeValue2 " !"))
  28.                        );progn
  29.                        (princ "\n"MyAttributeName2" attribute not found in "MyBlockName" block.")
  30.                    );if
  31.                )
  32.            )
  33.        )
  34.        (princ "\nNo attributed " MyBlockName " blocks found in the drawing.")
  35.    )
  36.    (princ)
  37. )
  38. (vl-load-com) (princ)
  39. ;; Get Attribute Value  -  Lee Mac
  40. ;; Returns the value held by the specified tag within the supplied block, if present.
  41. ;; blk - [vla] VLA Block Reference Object
  42. ;; tag - [str] Attribute TagString
  43. ;; Returns: [str] Attribute value, else nil if tag is not found.
  44. (defun LM:vl-getattributevalue ( blk tag )
  45.    (setq tag (strcase tag))
  46.    (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att)))
  47.        (vlax-invoke blk 'getattributes)
  48.    )
  49. )

对于每个属性,它都应该返回:
  1. (princ (strcat "\nFound the block named " MyBlockName " !"))
  2. (princ (strcat "\nFound the attribute named " MyAttributeName2 " !"))
  3. (princ (strcat "\nThe value of that attribute is " MyAttributeValue2 " !"))

我得到了这个错误,不知道为什么:
  1. Type the name of the Block to look for:VLD_Column
  2. Type the name of the Attribute1 to look for:L1
  3. Type the name of the Attribute2 to look for:L2
  4. Error: bad argument type: FILE "VLD_Column"
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:25:11 | 显示全部楼层
一些更正:
  1. ;Trying to obtain effective blockname, a attribute name and its attribute value
  2. ;I am going to use "foreach" function, and different conditions, based on that attribute value
  3. (defun c:test ( / i o s MyBlockName MyAttributeName1 MyAttributeName2 )
  4.    (setq MyBlockName (getstring T "\nType the name of the Block to look for:"))
  5.    (setq MyAttributeName1 (getstring T "\nType the name of the Attribute1 to look for:"))
  6.    (setq MyAttributeName2 (getstring T "\nType the name of the Attribute2 to look for:"))
  7.    (if (setq s (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 (strcat "`*U*," MyBlockName)))))
  8.        (repeat (setq i (sslength s))
  9.            (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
  10.            (if (and (vlax-property-available-p o 'effectivename)
  11.                     (= (strcase MyBlockName) (strcase (vla-get-effectivename o) t))
  12.                )
  13.                (progn
  14.                    (princ (strcat "\nFound " MyBlockName " block "" (vla-get-handle o) ""."))
  15.                    (if (setq MyAttributeValue1 (LM:vl-getattributevalue o MyAttributeName1))
  16.                        (progn
  17.                           (princ (strcat "\nFound the block named " MyBlockName " !"))
  18.                           (princ (strcat "\nFound the attribute named " MyAttributeName1 " !"))
  19.                           (princ (strcat "\nThe value of that attribute is " MyAttributeValue1 " !"))
  20.                        );progn
  21.                        (princ (strcat "\n"" MyAttributeName1 "" attribute not found in "" MyBlockName "" block."))
  22.                    );if
  23.                    (if (setq MyAttributeValue2 (LM:vl-getattributevalue o MyAttributeName2))
  24.                        (progn
  25.                           (princ (strcat "\nFound the block named " MyBlockName " !"))
  26.                           (princ (strcat "\nFound the attribute named " MyAttributeName2 " !"))
  27.                           (princ (strcat "\nThe value of that attribute is " MyAttributeValue2 " !"))
  28.                        );progn
  29.                        (princ (strcat "\n"" MyAttributeName2 "" attribute not found in "" MyBlockName "" block."))
  30.                    );if
  31.                )
  32.            )
  33.        )
  34.        (princ (strcat "\nNo attributed " MyBlockName " blocks found in the drawing."))
  35.    )
  36.    (princ)
  37. )
  38. (vl-load-com) (princ)
  39. ;; Get Attribute Value  -  Lee Mac
  40. ;; Returns the value held by the specified tag within the supplied block, if present.
  41. ;; blk - [vla] VLA Block Reference Object
  42. ;; tag - [str] Attribute TagString
  43. ;; Returns: [str] Attribute value, else nil if tag is not found.
  44. (defun LM:vl-getattributevalue ( blk tag )
  45.    (setq tag (strcase tag))
  46.    (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att)))
  47.        (vlax-invoke blk 'getattributes)
  48.    )
  49. )
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 18:32:52 | 显示全部楼层
谢谢你,李,很快就注意到了!
我可能把括号弄错了,因为我得到:
  1. No attributed VLD_Column blocks found in the drawing.

但如果没有预期的结果,我不能确定它是否会完全发挥作用。
 
我希望您不介意给出一个示例,说明如何在单独的“setq”的有效bname、attname和attvalue中返回
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:35:46 | 显示全部楼层
这不是错误,但意味着选择集为空;您是否使用图形中的相关属性动态块测试程序?
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 18:44:56 | 显示全部楼层
李,
当然,我的图形中有当前的动态块。
也许我误解了“属性”的定义,我寻找的属性L1和L2实际上是块的“动作参数”。
 
我有一个小问题,因为我仍然无法自己解决(很明显,你是互联网上知道答案的人数较少的人之一):
选择动态块时,在“快捷特性”菜单中列出其所有“参数”
但它们都算作属性吗?(例如:块表、可见性状态、翻转状态)或属性是ATTDEF唯一调用的?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:56:29 | 显示全部楼层
您描述的项目不是属性,而是动态块参数。
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 19:06:42 | 显示全部楼层
李,
谢谢你帮我澄清这件事!
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 19:18:18 | 显示全部楼层
成功
 
190957a3e5s6opjejbsfi3.jpg
 
现在,只要我可以窗口选择所有具有该名称的块,并获得每个单独的参数。(我知道“foreach”和“LM:effectivename”函数,但我不知道如何使用它们)
  1. ;Returns Parameter
  2. (defun c:test ( / ent idx sel paramval MyParameterName )
  3.    (setq MyParameterName (getstring T "\nType the name of the Parameter to look for:"))
  4.    (prompt "\nSelect dynamic block")
  5.    (if (setq sel (ssget "_+.:E:S" '((0 . "INSERT"))))
  6.        (repeat (setq idx (sslength sel))
  7.            (setq ent (ssname sel (setq idx (1- idx))))
  8.            (if (setq paramval (LM:getdynpropvalue (vlax-ename->vla-object ent) MyParameterName))
  9.                (princ (strcat "\nBname:" (cdr (assoc 2 (entget ent))) "    ParamName:" MyParameterName "    ParamValue:" paramval ))
  10.                (princ (strcat "\nParameter " MyParameterName " not found in block " (cdr (assoc 2 (entget ent)))))
  11.            )
  12.        )
  13.    )
  14.    (princ)
  15. )
  16. ;; Get Dynamic Block Property Value  -  Lee Mac
  17. ;; Returns the value of a Dynamic Block property (if present)
  18. ;; blk - [vla] VLA Dynamic Block Reference object
  19. ;; prp - [str] Dynamic Block property name (case-insensitive)
  20. (defun LM:getdynpropvalue ( blk prp )
  21.    (setq prp (strcase prp))
  22.    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
  23.        (vlax-invoke blk 'getdynamicblockproperties)
  24.    )
  25. )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 20:13 , Processed in 1.033683 second(s), 70 queries .

© 2020-2025 乐筑天下

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