TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jaydee on August 12, 2011, 01:10:44 AM
-
Hi.
Appologise to Lee that i ask question here regarding the functions publish on your site.
Anyone are wellcome to comment.
LM attribute function link http://lee-mac.com/attributefunctions.html (http://lee-mac.com/attributefunctions.html)
Regarding the LM:GetAttributeValue attribute functions
Im using these function extensively, but the way im using it is to have one pair of these functions (LM:GetAttributeValue + calling function) for each attribute TAG checking ie (setq IsTag1 ..) and i have 13 pairs of these function to check 13 different TAGS. I use these routine to check if a TAG exist, i know the purpose of these routine is to get the attribute value.
My question is either how to combine the main and calling function into one or even better to have multiple TAG checking into one function.
ie
(if (eq tag (strcase (vla-get-Tagstring attrib)))
(setq IsTag1 (vla-get-TextString attrib))
(setq IsTag2 (vla-get-TextString attrib))
(setq IsTag3 (vla-get-TextString attrib))
etc.
calling function
(LM:GetAttributeValue
(vlax-ename->vla-object (ssname ss 0))
"TAG1"
"TAG2"
"TAG3"
etc.
I mod the the code so no user input require and provide a variable so icould use later.
(vla-get-TextString attrib)
replace with
(setq IsTag1 (vla-get-TextString attrib))
(vlax-ename->vla-object (ssname ss 0)) (getstring "\nSpecify Tag String: ")
replace with
(vlax-ename->vla-object (ssname ss 0)) "TAG1"
-
Use the LM:GetAttributes function (found on the same page) to return an association list of attribute tags/values, then use the assoc function to test tags against this list.
i.e.
(setq lst (LM:GetAttributes <block entity/object>))
==> (("TAG1" . "Value 1") ("TAG2" . "Value2") ... ("TAGn" . "ValueN"))
Then the test becomes:
(if (assoc "TAG1" lst)
...
Or to test them all:
(if (vl-every '(lambda ( tag ) (assoc tag lst)) '("TAG1" "TAG2" "TAG3" ... ))
...
-
Thankyou Lee
This is a much simpler way of testing for attribute TAGs
Cheers
-
You're welcome jaydee :-)
-
Hi
Im working with different version of blocks and the naming of attrib TAGs varies slightly
and only one of those is true, therefor how to extract the value from the tag.
(cdr (assoc "???" lst))
(if (or (assoc "DRG-TITLE1" lst) (assoc "DRG_TITLE1" lst) (assoc "DWG-TITLE1" lst))
(setq TT1 (cdr (assoc "???" lst)))
)
Thankyou
-
Two ways that come to mind:
(setq value
(cdr
(cond
( (assoc "DRG-TITLE1" lst) )
( (assoc "DRG_TITLE1" lst) )
( (assoc "DWG-TITLE1" lst) )
)
)
)
(vl-some
'(lambda ( tag ) (setq value (cdr (assoc tag lst))))
'("DRG-TITLE1" "DRG_TITLE1" "DWG-TITLE1")
)
(if value
...
-
Thankyou verymuch Lee. This is brilliant.
-
You're welcome jaydee 8-)