TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jaydee on August 12, 2011, 01:10:44 AM

Title: LM: Attribute function
Post 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
Code: [Select]
(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.

Code: [Select]
(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"


Title: Re: LM: Attribute function
Post by: Lee Mac on August 12, 2011, 10:12:12 AM
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.

Code: [Select]
(setq lst (LM:GetAttributes <block entity/object>))

==>  (("TAG1" . "Value 1") ("TAG2" .  "Value2") ... ("TAGn" . "ValueN"))

Then the test becomes:

Code: [Select]
(if (assoc "TAG1" lst)
...

Or to test them all:

Code: [Select]
(if (vl-every '(lambda ( tag ) (assoc tag lst)) '("TAG1" "TAG2" "TAG3" ... ))
...
Title: Re: LM: Attribute function
Post by: jaydee on August 12, 2011, 10:45:07 PM
Thankyou Lee
This is a much simpler way of testing for attribute TAGs

Cheers
Title: Re: LM: Attribute function
Post by: Lee Mac on August 13, 2011, 08:01:49 AM
You're welcome jaydee  :-)
Title: Re: LM: Attribute function
Post by: jaydee on August 14, 2011, 02:26:32 AM
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))

Code: [Select]
(if (or (assoc "DRG-TITLE1" lst) (assoc "DRG_TITLE1" lst) (assoc "DWG-TITLE1" lst))
 (setq TT1 (cdr (assoc  "???" lst)))
)

Thankyou
Title: Re: LM: Attribute function
Post by: Lee Mac on August 14, 2011, 06:35:29 AM
Two ways that come to mind:

Code: [Select]
(setq value
  (cdr
    (cond
      ( (assoc "DRG-TITLE1" lst) )
      ( (assoc "DRG_TITLE1" lst) )
      ( (assoc "DWG-TITLE1" lst) )
    )
  )
)

Code: [Select]
(vl-some
  '(lambda ( tag ) (setq value (cdr (assoc tag lst))))
  '("DRG-TITLE1" "DRG_TITLE1" "DWG-TITLE1")
)
(if value
  ...
Title: Re: LM: Attribute function
Post by: jaydee on August 15, 2011, 06:25:00 PM
Thankyou verymuch Lee. This is brilliant.
Title: Re: LM: Attribute function
Post by: Lee Mac on August 16, 2011, 08:48:04 AM
You're welcome jaydee  8-)