How can extract attribute information ( Tag prompt value ) ?
Hi, I have attribute block in title sheet have so many attribute block each drawing want to extract attribute value or ( attribute dxf code) change through lisp ?
Help me. Thanks for advance.
shanskvm
Solved! Go to Solution.
Solved by scottbolton. Go to Solution.
Shanks,
I was in the process of replying to this message last week when Autodesk turned the site off for the upgrade. Here you go. You manually select the titleblock, or do it with code and remove the (setq EXTRACT_e (car (entsel))) line.
S
(defun ATTRIB_EXTRACT ( / EXTRACT_e EXTRACT_c EXTRACT_list )
(setq EXTRACT_e (car (entsel)))
;;; Loop through all the entities and...
(while (and EXTRACT_e (/= "SEQEND" (cdr (assoc 0 (entget EXTRACT_e)))))
(setq EXTRACT_c (entget EXTRACT_e))
;;; ...extract the ATTRIB information required
(if (= (cdr (assoc 0 EXTRACT_c)) "ATTRIB")
(setq EXTRACT_list (cons
(list
(cdr (assoc 2 EXTRACT_c)); attribute tag name ;
(cdr (assoc 1 EXTRACT_c)); attribute value ;
)
EXTRACT_list
)
)
)
(setq EXTRACT_e (entnext EXTRACT_e))
)
EXTRACT_list
)
Thanks for your reply ..
I have title block.but so many drawings. Through lisp I need to change ( example : date , revision ). I want ato assign and old attribute value and new attribute value? How can do that. I am a beginner lisp
Thanks
shanskvm
If you handle your stuff as vla-objects, handling attribute values is relatively easy:
(defun get-attribute (obj tag / value) ;; returns the value of the textstring property of the attribute reference (foreach a (vlax-invoke obj 'getattributes) (if (= (vlax-get a 'TagString) tag) (setq value (vlax-get a 'textString)))) value) (defun set-attribute (obj tag value) ;; sets the value of the textstring with given tag (foreach a (vlax-invoke obj 'getattributes) (if (= (vlax-get a 'TagString) tag) (vlax-put a 'textstring value)))) (defun get-attribute-values (obj / value) ;; returns a list of textstring values as (tag . value) pairs (foreach a (vlax-invoke obj 'getattributes) (setq value (cons (cons (vlax-get a 'TagString) (vlax-get a 'textString)) value))) (reverse value)) (defun show-attrs (obj) (foreach o (get-attribute-values obj) (print o)))
See also vlax-ename->vla-object if you use entsel or similar for picking objects.
--
If you need to get proms , tags and values try this quick example
No error checking
(vl-load-com) (defun C:demo (/ blockdata blockdef blockname blockref en ent tmp) (if (setq ent (entsel "\n >> Select a block instance >>")) (progn (setq en (car ent) blockref (vlax-ename->vla-object en) blockname (vla-get-effectivename blockref) blockdef (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blockname) ) (if (equal :vlax-true (vla-get-hasattributes blockref)) (progn (foreach attrib (vlax-invoke blockref 'GetAttributes) (vlax-for item blockdef (if (equal (vla-get-objectname item) "AcDbAttributeDefinition") (progn (if (equal (vla-get-tagstring attrib) (vla-get-tagstring item)) (progn (setq tmp (list (vla-get-promptstring item) (vla-get-tagstring attrib) (vla-get-textstring attrib))) (setq blockdata (cons tmp blockdata)) ) ) ) ) ) ) (setq blockdata(reverse blockdata) ) (foreach lst blockdata (princ (strcat "\n Prompt: " (car lst) " *** Tag: " (cadr lst) " *** Value: " (last lst))) ) ) ) ) (princ "\n >> Nothing selected. Try again...") ) (princ) ) (prompt "\n >> Type DEMO to execute..." ) (prin1)
~'J'~