Author Topic: LM: Attribute function  (Read 3350 times)

0 Members and 1 Guest are viewing this topic.

jaydee

  • Guest
LM: Attribute function
« 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

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"



Lee Mac

  • Seagull
  • Posts: 12752
  • London, England
Re: LM: Attribute function
« Reply #1 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" ... ))
...

jaydee

  • Guest
Re: LM: Attribute function
« Reply #2 on: August 12, 2011, 10:45:07 PM »
Thankyou Lee
This is a much simpler way of testing for attribute TAGs

Cheers

Lee Mac

  • Seagull
  • Posts: 12752
  • London, England
Re: LM: Attribute function
« Reply #3 on: August 13, 2011, 08:01:49 AM »
You're welcome jaydee  :-)

jaydee

  • Guest
Re: LM: Attribute function
« Reply #4 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

Lee Mac

  • Seagull
  • Posts: 12752
  • London, England
Re: LM: Attribute function
« Reply #5 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
  ...

jaydee

  • Guest
Re: LM: Attribute function
« Reply #6 on: August 15, 2011, 06:25:00 PM »
Thankyou verymuch Lee. This is brilliant.

Lee Mac

  • Seagull
  • Posts: 12752
  • London, England
Re: LM: Attribute function
« Reply #7 on: August 16, 2011, 08:48:04 AM »
You're welcome jaydee  8-)