TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on October 21, 2011, 01:27:49 PM

Title: how can i get the value of an atttribute?
Post by: andrew_nao on October 21, 2011, 01:27:49 PM
im a bit stumped on this.

how can i get the value of an attribute within a selection set?

i know you can get it by using (entsel) instead of (ssget), but for what im trying to do i need (ssget)


Code: [Select]
(setq en (ssget))
(setq ent (ssname en 0))
(setq EN (entget ent))
(if  (= (cdr (assoc 0 en)) (strcase "insert"))
(progn
(setq TXTO (cdr (assoc 1 en))) <--- put attribute value here


as always, any help is appreciated
Title: Re: how can i get the value of an atttribute?
Post by: Lee Mac on October 21, 2011, 01:31:11 PM
Quick example:

Code: [Select]
(defun c:test ( / e i l s )
    (if (setq s (ssget '((0 . "INSERT") (66 . 1))))
        (repeat (setq i (sslength s))
            (setq e (ssname s (setq i (1- i))))
            (princ (strcat "\n" (cdr (assoc 2 (entget e)))))
            (while (eq "ATTRIB" (cdr (assoc 0 (setq l (entget (setq e (entnext e)))))))
                (princ (strcat "\nTag: " (cdr (assoc 2 l)) "\tValue: " (cdr (assoc 1 l))))
            )
        )
    )
    (princ)
)

More examples. (http://lee-mac.com/attributefunctions.html)

Title: Re: how can i get the value of an atttribute?
Post by: David Bethel on October 21, 2011, 02:38:45 PM
Or if you want be a little less elegant:

Code: [Select]

(defun c:viewatt (/ s en ed an ad tag val)
  (and (setq s (entsel "\nSelect an ATTRIButed INSERT:   "))
       (setq en (car s)
             ed (entget en))
       (= "INSERT" (cdr (assoc 0 ed)))
       (= 1 (cdr (assoc 66 ed)))
       (setq an (entnext en)
             ad (entget an))
       (while (= "ATTRIB" (cdr (assoc 0 ad)))
              (setq val (cdr (assoc 1 ad))
                    tag (cdr (assoc 2 ad)))
              (princ (strcat "\n" tag " = " val))
              (getstring "\nPress Enter To Continue...")
              (setq an (entnext an)
                    ad (entget an))))
  (prin1))

-David
Title: Re: how can i get the value of an atttribute?
Post by: andrew_nao on October 21, 2011, 02:41:59 PM
thanks for the reply Lee

is there any other way of doing it without having to use another function?
Title: Re: how can i get the value of an atttribute?
Post by: pBe on October 22, 2011, 04:00:59 AM
Not sure what you mean by another function though:

SSGET ":N" / ssnamex ?

Code: [Select]
(Defun c:test (/ ss)
  (setq ss (ssget ":N:S" '((0 . "INSERT") (66 . 1))))
  (princ (cdr (assoc 1 (entget (cadar (ssnamex ss))))))
  (princ)
)
Title: Re: how can i get the value of an atttribute?
Post by: Lee Mac on October 22, 2011, 08:00:24 AM
SSGET ":N" / ssnamex ?

Beware of the ":N" mode string, it can be very unreliable  :wink:

is there any other way of doing it without having to use another function?

Huh?  :?
Title: Re: how can i get the value of an atttribute?
Post by: CAB on October 22, 2011, 06:12:25 PM
Andrew
Perhaps the will bring you closer to your goal.
Code: [Select]
(setq ss (ssget '((0 . "INSERT") (66 . 1))))
(setq en (ssname ss 0))
(setq l (entget (setq en (entnext en))))
(setq txto (cdr (assoc 1 l)))
Title: Re: how can i get the value of an atttribute?
Post by: pBe on October 24, 2011, 07:18:02 AM
Beware of the ":N" mode string, it can be very unreliable  :wink:

Why so Lee? please enlighten me  :-)

Title: Re: how can i get the value of an atttribute?
Post by: Lee Mac on October 24, 2011, 07:29:49 AM
Beware of the ":N" mode string, it can be very unreliable  :wink:

Why so Lee? please enlighten me  :-)

In past applications, I've found that it will sometime omit some nested entities from the selection, and so would opt to use nentsel instead.
Title: Re: how can i get the value of an atttribute?
Post by: pBe on October 24, 2011, 09:32:29 AM
Beware of the ":N" mode string, it can be very unreliable  :wink:

Why so Lee? please enlighten me  :-)

In past applications, I've found that it will sometime omit some nested entities from the selection, and so would opt to use nentsel instead.

Can't argue with experience   :-D

Thanks Lee
Title: Re: how can i get the value of an atttribute?
Post by: andrew_nao on October 24, 2011, 11:47:35 AM
thanks CAB, that helped alot

and thanks everyone that posted, i learned something new today