Author Topic: how can i get the value of an atttribute?  (Read 2578 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
how can i get the value of an atttribute?
« 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
« Last Edit: October 21, 2011, 06:14:05 PM by CAB »

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: how can i get the value of an atttribute?
« Reply #1 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.


David Bethel

  • Swamp Rat
  • Posts: 656
Re: how can i get the value of an atttribute?
« Reply #2 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
R12 Dos - A2K

andrew_nao

  • Guest
Re: how can i get the value of an atttribute?
« Reply #3 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?

pBe

  • Bull Frog
  • Posts: 402
Re: how can i get the value of an atttribute?
« Reply #4 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)
)
« Last Edit: October 22, 2011, 04:43:38 AM by pBe »

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: how can i get the value of an atttribute?
« Reply #5 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?  :?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: how can i get the value of an atttribute?
« Reply #6 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)))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

pBe

  • Bull Frog
  • Posts: 402
Re: how can i get the value of an atttribute?
« Reply #7 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  :-)


Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: how can i get the value of an atttribute?
« Reply #8 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.

pBe

  • Bull Frog
  • Posts: 402
Re: how can i get the value of an atttribute?
« Reply #9 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

andrew_nao

  • Guest
Re: how can i get the value of an atttribute?
« Reply #10 on: October 24, 2011, 11:47:35 AM »
thanks CAB, that helped alot

and thanks everyone that posted, i learned something new today