动态块,属性名称
大家好,我正在开发一些经过大量修改的lisp例程(源于Lee Mac),我正在尝试用lisp为有效的块名和许多属性名及其值设置引号。我知道有LM的子函数来获取属性,它返回assoc列表,其中包含:
((<Tag> . <Value>) ... )
如果有人能给我举个例子,告诉我如何为每个标签和值设置报价,我会更喜欢这个。例如,如果我选择一个动态块以获得其有效名称的提示,以及一个如下列表:
“ATTname N”的值为“ATTvalue N”
无论如何,以下是我失败的尝试:
;Trying to obtain effective blockname, a attribute name and its attribute value
;I am going to use "foreach" function, and different conditions, based on that attribute value
(defun c:test ( / i o s )
(setq MyBlockName (getstring T "\nType the name of the Block to look for:"))
(setq MyAttributeName1 (getstring T "\nType the name of the Attribute1 to look for:"))
(setq MyAttributeName2 (getstring T "\nType the name of the Attribute2 to look for:"))
(if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "`*U*,MyBlockName"))))
(repeat (setq i (sslength s))
(setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
(if (and (vlax-property-available-p o 'effectivename)
(= MyBlockName (strcase (vla-get-effectivename o) t))
)
(progn
(princ (strcat "\nFound " MyBlockName " block "" (vla-get-handle o) "\"."))
(if (setq MyAttributeValue1 (LM:vl-getattributevalue o MyAttributeName1))
(progn
(princ (strcat "\nFound the block named " MyBlockName " !"))
(princ (strcat "\nFound the attribute named " MyAttributeName1 " !"))
(princ (strcat "\nThe value of that attribute is " MyAttributeValue1 " !"))
);progn
(princ "\n\"MyAttributeName1\" attribute not found in \"MyBlockName\" block.")
);if
(if (setq MyAttributeValue2 (LM:vl-getattributevalue o MyAttributeName2))
(progn
(princ (strcat "\nFound the block named " MyBlockName " !"))
(princ (strcat "\nFound the attribute named " MyAttributeName2 " !"))
(princ (strcat "\nThe value of that attribute is " MyAttributeValue2 " !"))
);progn
(princ "\n\"MyAttributeName2\" attribute not found in \"MyBlockName\" block.")
);if
)
)
)
(princ "\nNo attributed " MyBlockName " blocks found in the drawing.")
)
(princ)
)
(vl-load-com) (princ)
;; Get Attribute Value-Lee Mac
;; Returns the value held by the specified tag within the supplied block, if present.
;; blk - VLA Block Reference Object
;; tag - Attribute TagString
;; Returns: Attribute value, else nil if tag is not found.
(defun LM:vl-getattributevalue ( blk tag )
(setq tag (strcase tag))
(vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att)))
(vlax-invoke blk 'getattributes)
)
)
对于每个属性,它都应该返回:
(princ (strcat "\nFound the block named " MyBlockName " !"))
(princ (strcat "\nFound the attribute named " MyAttributeName2 " !"))
(princ (strcat "\nThe value of that attribute is " MyAttributeValue2 " !"))
我得到了这个错误,不知道为什么:
Type the name of the Block to look for:VLD_Column
Type the name of the Attribute1 to look for:L1
Type the name of the Attribute2 to look for:L2
Error: bad argument type: FILE "VLD_Column" 一些更正:
;Trying to obtain effective blockname, a attribute name and its attribute value
;I am going to use "foreach" function, and different conditions, based on that attribute value
(defun c:test ( / i o s MyBlockName MyAttributeName1 MyAttributeName2 )
(setq MyBlockName (getstring T "\nType the name of the Block to look for:"))
(setq MyAttributeName1 (getstring T "\nType the name of the Attribute1 to look for:"))
(setq MyAttributeName2 (getstring T "\nType the name of the Attribute2 to look for:"))
(if (setq s (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 (strcat "`*U*," MyBlockName)))))
(repeat (setq i (sslength s))
(setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
(if (and (vlax-property-available-p o 'effectivename)
(= (strcase MyBlockName) (strcase (vla-get-effectivename o) t))
)
(progn
(princ (strcat "\nFound " MyBlockName " block \"" (vla-get-handle o) "\"."))
(if (setq MyAttributeValue1 (LM:vl-getattributevalue o MyAttributeName1))
(progn
(princ (strcat "\nFound the block named " MyBlockName " !"))
(princ (strcat "\nFound the attribute named " MyAttributeName1 " !"))
(princ (strcat "\nThe value of that attribute is " MyAttributeValue1 " !"))
);progn
(princ (strcat "\n\"" MyAttributeName1 "\" attribute not found in \"" MyBlockName "\" block."))
);if
(if (setq MyAttributeValue2 (LM:vl-getattributevalue o MyAttributeName2))
(progn
(princ (strcat "\nFound the block named " MyBlockName " !"))
(princ (strcat "\nFound the attribute named " MyAttributeName2 " !"))
(princ (strcat "\nThe value of that attribute is " MyAttributeValue2 " !"))
);progn
(princ (strcat "\n\"" MyAttributeName2 "\" attribute not found in \"" MyBlockName "\" block."))
);if
)
)
)
(princ (strcat "\nNo attributed " MyBlockName " blocks found in the drawing."))
)
(princ)
)
(vl-load-com) (princ)
;; Get Attribute Value-Lee Mac
;; Returns the value held by the specified tag within the supplied block, if present.
;; blk - VLA Block Reference Object
;; tag - Attribute TagString
;; Returns: Attribute value, else nil if tag is not found.
(defun LM:vl-getattributevalue ( blk tag )
(setq tag (strcase tag))
(vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att)))
(vlax-invoke blk 'getattributes)
)
) 谢谢你,李,很快就注意到了!
我可能把括号弄错了,因为我得到:
No attributed VLD_Column blocks found in the drawing.
但如果没有预期的结果,我不能确定它是否会完全发挥作用。
我希望您不介意给出一个示例,说明如何在单独的“setq”的有效bname、attname和attvalue中返回 这不是错误,但意味着选择集为空;您是否使用图形中的相关属性动态块测试程序? 李,
当然,我的图形中有当前的动态块。
也许我误解了“属性”的定义,我寻找的属性L1和L2实际上是块的“动作参数”。
我有一个小问题,因为我仍然无法自己解决(很明显,你是互联网上知道答案的人数较少的人之一):
选择动态块时,在“快捷特性”菜单中列出其所有“参数”
但它们都算作属性吗?(例如:块表、可见性状态、翻转状态)或属性是ATTDEF唯一调用的? 您描述的项目不是属性,而是动态块参数。 李,
谢谢你帮我澄清这件事! 成功
现在,只要我可以窗口选择所有具有该名称的块,并获得每个单独的参数。(我知道“foreach”和“LM:effectivename”函数,但我不知道如何使用它们)
;Returns Parameter
(defun c:test ( / ent idx sel paramval MyParameterName )
(setq MyParameterName (getstring T "\nType the name of the Parameter to look for:"))
(prompt "\nSelect dynamic block")
(if (setq sel (ssget "_+.:E:S" '((0 . "INSERT"))))
(repeat (setq idx (sslength sel))
(setq ent (ssname sel (setq idx (1- idx))))
(if (setq paramval (LM:getdynpropvalue (vlax-ename->vla-object ent) MyParameterName))
(princ (strcat "\nBname:" (cdr (assoc 2 (entget ent))) " ParamName:" MyParameterName " ParamValue:" paramval ))
(princ (strcat "\nParameter " MyParameterName " not found in block " (cdr (assoc 2 (entget ent)))))
)
)
)
(princ)
)
;; Get Dynamic Block Property Value-Lee Mac
;; Returns the value of a Dynamic Block property (if present)
;; blk - VLA Dynamic Block Reference object
;; prp - Dynamic Block property name (case-insensitive)
(defun LM:getdynpropvalue ( blk prp )
(setq prp (strcase prp))
(vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
(vlax-invoke blk 'getdynamicblockproperties)
)
)
页:
[1]