Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can extract attribute information ( Tag,prompt and value ) ?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Shanskvm
3405 Views, 4 Replies

How can extract attribute information ( Tag,prompt and value ) ?

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

4 REPLIES 4
Message 2 of 5
scottbolton
in reply to: Shanskvm

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
  )

Message 3 of 5
Shanskvm
in reply to: scottbolton

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

Message 4 of 5
martti.halminen
in reply to: 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.

 

--

 

Message 5 of 5
Hallex
in reply to: Shanskvm

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'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost