Author Topic: Beginner: Help with Lee's Attribute Functions needed  (Read 302 times)

0 Members and 1 Guest are viewing this topic.

sorry4mylisp

  • Mosquito
  • Posts: 5
Beginner: Help with Lee's Attribute Functions needed
« on: June 12, 2022, 10:11:48 AM »
Hi Guys,

I'm talking about these: http://www.lee-mac.com/attributefunctions.html#alsetattributevaluerc
Is there a working demo anywhere or a link/thread that explains how you can make these actually work?
I'm a little lost on how exactly i need to feed those (looking at vanilla version) the required args.

If i somehow get past:
Quote
; error : too few / too many arguments at [LM:GETATTRIBUTEVALUE]
i run into:
Quote
; error : bad argument type <NIL> ; expected ENTITYNAME at [entnext]

Any help would be greatly appreciated!!!





Lee Mac

  • Seagull
  • Posts: 12696
  • London, England
Re: Beginner: Help with Lee's Attribute Functions needed
« Reply #1 on: June 12, 2022, 11:30:38 AM »
Hi, what arguments are you currently supplying to the function?

sorry4mylisp

  • Mosquito
  • Posts: 5
Re: Beginner: Help with Lee's Attribute Functions needed
« Reply #2 on: June 12, 2022, 12:38:47 PM »
Hey thanks for getting back so quickly!

To be honest i'm stabbing in the dark here. I wouldn't mind beeing spoonfed but i'm afraid to say what i tried hahaha.

http://www.lee-mac.com/simpleblockcounter.html I just found this and i have some hope that this might help me understand how to feed a selection into the functions. I'll come back with what i have, or a specific question in a few hours!


Lee Mac

  • Seagull
  • Posts: 12696
  • London, England
Re: Beginner: Help with Lee's Attribute Functions needed
« Reply #3 on: June 12, 2022, 01:58:14 PM »
To be honest i'm stabbing in the dark here. I wouldn't mind beeing spoonfed but i'm afraid to say what i tried hahaha.

Here's a very simple example to get you started:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / ent enx tag val )
  2.     (cond
  3.         (   (not (setq ent (car (entsel "\nSelect an attributed block: "))))
  4.             (princ "\nYou didn't select anything.")
  5.         )
  6.         (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
  7.             (princ "\nYou didn't select a block.")
  8.         )
  9.         (   (/= 1 (cdr (assoc 66 enx)))
  10.             (princ "\nThe block you selected is not attributed.")
  11.         )
  12.         (   (= "" (setq tag (getstring "\nSpecify an attribute tag to obtain the value: ")))
  13.             (princ "\nYou didn't specify a tag.")
  14.         )
  15.         (   (= "" (setq val (LM:getattributevalue ent tag)))
  16.             (princ "\nThe attribute is blank.")
  17.         )
  18.         (   (princ (strcat "\nThe value of the attribute with tag \"" tag "\" is \"" val "\".")))
  19.     )
  20.     (princ)
  21. )
  22.  
  23. ;; Get Attribute Value  -  Lee Mac
  24. ;; Returns the value held by the specified tag within the supplied block, if present.
  25. ;; blk - [ent] Block (Insert) Entity Name
  26. ;; tag - [str] Attribute TagString
  27. ;; Returns: [str] Attribute value, else nil if tag is not found.
  28.  
  29. (defun LM:getattributevalue ( blk tag / enx )
  30.     (if (and (setq blk (entnext blk)) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk))))))
  31.         (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
  32.             (cdr (assoc 1 (reverse enx)))
  33.             (LM:getattributevalue blk tag)
  34.         )
  35.     )
  36. )
  37.  

sorry4mylisp

  • Mosquito
  • Posts: 5
Re: Beginner: Help with Lee's Attribute Functions needed
« Reply #4 on: June 12, 2022, 05:26:05 PM »
Thanks a lot! thats a bit more 'step by step'. Different but i see the similarities. I think i'm getting there.

sorry4mylisp

  • Mosquito
  • Posts: 5
Re: Beginner: Help with Lee's Attribute Functions needed
« Reply #5 on: June 20, 2022, 04:06:43 AM »
Hey again, still meditating on this. Am i correct that 'entity name' is a specific type and that my problem was that i tried to manually setq the 'ent' arg? in the beginning i tried stuff like:

Code: [Select]
(setq ent "386be970")
and it didn't work. So is there a way to define an entity name manually or should look to rely on autolisp to do the typing work?

dexus

  • Newt
  • Posts: 75
Re: Beginner: Help with Lee's Attribute Functions needed
« Reply #6 on: June 20, 2022, 04:14:56 AM »
Yes, entity names have their own type, so you want to use a different method of selecting the items like ssget or entsel.

Code - Auto/Visual Lisp: [Select]
  1. (setq ent "386be970")
  2. (type ent)
  3. > STR
  4.  
  5. (setq ent (car (entsel)))
  6. (type ent)
  7. > ENAME

sorry4mylisp

  • Mosquito
  • Posts: 5
Re: Beginner: Help with Lee's Attribute Functions needed
« Reply #7 on: June 20, 2022, 05:58:34 AM »
cool thanks! It was kinda obvious at this point but i'm not always sure if what i'm thinking is actually correct  :wink: