TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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)
(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
-
Quick example:
(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)
-
Or if you want be a little less elegant:
(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
-
thanks for the reply Lee
is there any other way of doing it without having to use another function?
-
Not sure what you mean by another function though:
SSGET ":N" / ssnamex ?
(Defun c:test (/ ss)
(setq ss (ssget ":N:S" '((0 . "INSERT") (66 . 1))))
(princ (cdr (assoc 1 (entget (cadar (ssnamex ss))))))
(princ)
)
-
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? :?
-
Andrew
Perhaps the will bring you closer to your goal.
(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)))
-
Beware of the ":N" mode string, it can be very unreliable :wink:
Why so Lee? please enlighten me :-)
-
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.
-
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
-
thanks CAB, that helped alot
and thanks everyone that posted, i learned something new today