获取动态块属性b
你好有人能帮我解决以下问题吗。
我有一个具有多个可见性状态的动态块。(例如Vis1到Vis5)
在每一个可视性中,我都有两个独特的属性。
因此,在Vis1中有两个attibute标记,称为Length1和Width1
........Vis2有两个attibute标签,称为Length2&Width2
......
我想获得当前可见性状态下属性的值,并将其保存为变量Var1和Var2。
搜索中唯一的乐趣是我在李的网站上找到的东西,但我一直无法在他的代码上取得任何进展。(见下文)
谢谢你在这方面的帮助
Get Attribute Value
Select all ;;----------------=={ Get Attribute Value
}==-----------------;;
;;
;;
;;Returns the attribute value associated with the specified
;;
;;tag, within the supplied block, if
present.
;;
;;------------------------------------------------------------;;
;;
Author: Lee Mac, Copyright © 2010 - www.lee-mac.com
;;
;;------------------------------------------------------------;;
;;
Arguments:
;;
;;block - VLA Block Reference
Object
;;
;;tag - Attribute
TagString
;;
;;------------------------------------------------------------;;
;;
Returns:Attribute TextString, else
nil
;;
;;------------------------------------------------------------;;
(defun LM:vl-GetAttributeValue ( block tag )
(setq tag
(strcase tag))
(vl-some
(function
(lambda ( attrib
)
(if (eq tag (strcase (vla-get-Tagstring
attrib)))
(vla-get-TextString
attrib)
)
)
)
(vlax-invoke block
'GetAttributes)
)
)
(defun c:test ( / ss )
(if (setq ss (ssget
"_+.:E:S" '((0 . "INSERT") (66 .
1))))
(princ
(LM:vl-GetAttributeValue
(vlax-ename->vla-object (ssname ss
0))
(getstring "\nSpecify Tag String:
")
)
)
)
(princ)
)
(vl-load-com)
;;----------------=={ Get Visibility State
}==----------------;;
;;
;;
;;Returns the value of the Visibility Parameter of
a ;;
;;Dynamic Block (if
present)
;;
;;------------------------------------------------------------;;
;;
Author: Lee Mac, Copyright © 2011 - www.lee-mac.com
;;
;;------------------------------------------------------------;;
;;
Arguments:
;;
;;block-VLA (Dynamic) Block Reference
Object
;;
;;------------------------------------------------------------;;
;;
Returns:Value of Visibility Parameter, else
nil
;;
;;------------------------------------------------------------;;
(defun LM:GetVisibilityState ( block )
(
(lambda ( name
)
(vl-some
(function
(lambda ( prop
)
(if (eq name (vla-get-propertyname
prop))
(vlax-get prop
'value)
)
)
)
(vlax-invoke block
'getdynamicblockproperties)
)
)
(LM:GetVisibilityParameterName
block)
)
)
由于每个可见性的标记都不同,因此可以像通常一样检索属性,并使用标记名来标识要分配给变量Var1和Var2的文本字符串值。 你好
谢谢
理想情况下,我可以找到包含部分标记名的标记的属性值,即当前可见性状态下的长度和宽度。
对于实际可见状态
(setq var 1(获取包含字符串“length”的标记的属性值)
(setq var 2(获取包含字符串“width”的标记的属性值)
但我不知道该怎么做,也不知道这是否可行。
这是可能的
这很容易。由于您是自己的动态块的作者,并且正如我之前提到的,在每个可见性中,您都有一个特定的标记后缀,因此您可以确定当前的可见性,并且使用列表可以针对特定的标记。
(setq lst '(("Vis1" . ("LENGTH1" "WIDTH1"))("Vis2" . ("LENGTH2" "WIDTH2"))("Vis3" . ("LENGTH3" "WIDTH3"))))
使用Lee Mac的子LM:GETVISIBILITYSTATE/LM:GetVisibilityParameterName,您可以轻松确定当前状态:
假设当前可见性名称为“Vis2”
(setq targetTags (assoc "Vis2" lst))
如果你不介意张贴你的帖子,我可以为你指出正确的方向。
页:
[1]