AutoCAD 2010/2011/2012

AutoCAD 2010/2011/2012

Reply
Contributor
caramelja
Posts: 13
Registered: ‎09-28-2005
Message 1 of 3 (624 Views)

Match Attribute Values in the Same Block

624 Views, 2 Replies
01-04-2013 08:17 AM

Does anyone know how to get attribute values to match in the same block? In my titleblock have the clients name displayed a couple of time in the block. I want to be able to change the clients name in one spot and have it change in the other. I have tried to use fields but the field will only display the default value of the attribute.

Distinguished Mentor
Moshe-A
Posts: 829
Registered: ‎09-14-2003
Message 2 of 3 (594 Views)

Re: Match Attribute Values in the Same Block

01-05-2013 03:02 AM in reply to: caramelja

Caramelja,

 

1. you are right when a field is referencing attribute value it only copy it's default value. to me it looks

   like a bug (but it's better autocad should comment on this)

 

2. you got lucky today i have wrote a lisp to answer your question

    it call ATVP (Attribute Value Populate) copy and paste this code into

    a lisp file call it ATVP.LSP

 

   in order it to work you need to modify the next two lines with your own tags name

 

   (setq source_tag "tag0")                      ; replace "tag0" with your source tag name

   (setq target_tag^ '("tag1" "tag2" "tag3")); replace ("tag1" "tag2" "tag3") with your own target tags name

 

   these two lines are locate right after this line:

   (defun c:atvp (/ source_tag ... )

 

   now save it and load it and key in ATVP command

 

cheers

moshe

 

 

(vl-load-com); load ActiveX

(defun get_attrib_value (ename tagName / sub-ename sub-elist flag attval)
 (setq sub-ename (entnext ename) sub-elist (entget sub-ename))

 (while (and (not flag)
	     (/= (cdr (assoc '0 sub-elist)) "SEQEND")
	)
  (if (eq (strcase (cdr (assoc '2 sub-elist))) tagName)
   (setq attval (cdr (assoc '1 sub-elist)) flag t)
   (setq sub-ename (entnext sub-ename) sub-elist (entget sub-ename))
  )
 ); while

 attval
)


; Attribute Value Populate

(defun c:atvp (/ source_tag target_tag^ esel ename elist source_value sub-ename sub-elist)
 (setq source_tag "tag0") 		  ; replace "tag0" with your source tag name
 (setq target_tag^ '("tag1" "tag2" "tag")); replace ("tag1" "tag2" "tag3") with your own target tags name
  
 (if (setq esel (entsel "\nSelect block: "))
  (progn
   (setq ename (car esel) elist (entget ename))
   
   (if (and (= (cdr (assoc '0 elist)) "INSERT")
	    (= (cdr (assoc '66 elist)) 1)
       )
    (progn
     ; ensure uppercase
     (setq source_tag (strcase source_tag))

     ; ensure uppercase
     (setq target_tag^ (mapcar
	      		'(lambda (tagName)
	        	  (strcase tagName)
	       	         )
	     		target_tag^
		       ); mapcar
     ); setq

     ; get source tag value
     (setq source_value (get_attrib_value ename source_tag))

     (if (or (not source_value) (/= source_value ""))
      (progn
       (setq sub-ename (entnext ename) sub-elist (entget sub-ename))
       
       (while (/= (cdr (assoc '0 sub-elist)) "SEQEND")
	(if (and (/= (strcase (cdr (assoc '2 sub-elist))) source_tag)
		 (member (strcase (cdr (assoc '2 sub-elist))) target_tag^)
	    )
	 ; populate source attribute value
         (entmod (setq sub-elist (subst (cons '1 source_value) (assoc '1 sub-elist) sub-elist)))
	); if
	(setq sub-ename (entnext sub-ename) sub-elist (entget sub-ename))
       ); while
       
      ); progn
      (progn
       (vlr-beep-reaction)
       (princ "\nsource tag is not found or it's empty value.")
      )
     ); if
     
    ); progn
    (progn
     (vlr-beep-reaction)
     (princ "\nentity selected is not a block or does not contain attributes.")
    )
   ); if
   
  ); progn
 ); if

 (princ)
)

 

 

Contributor
caramelja
Posts: 13
Registered: ‎09-28-2005
Message 3 of 3 (540 Views)

Re: Match Attribute Values in the Same Block

01-07-2013 07:15 AM in reply to: caramelja

Thanks, I will give it a shot. It has been a long time since I have used Lisp so I will need to refresh my memory.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.