I need a lisp that will replace an existing attribute value with another

I need a lisp that will replace an existing attribute value with another

Anonymous
Not applicable
1,663 Views
6 Replies
Message 1 of 7

I need a lisp that will replace an existing attribute value with another

Anonymous
Not applicable

I have looked at a lot of code this morning and it all seems like overkill.

 

I have a title block with attributes defined.  I need to simply change one attribute from one value to another.  the attribute tag is the same in all drawings, that tag has the same value, the new value will also be the same in all drawings.  Literally, I want to open the drawing then run the lisp and have the attribute tag value change from one thing to another.   

 

Thank you for your help in advance!

0 Likes
Accepted solutions (1)
1,664 Views
6 Replies
Replies (6)
Message 2 of 7

Ranjit_Singh
Advisor
Advisor
Accepted solution

There are quite a few on the forums if you do a search. Replace the tag/tags  as needed

(defun c:somefunc  (/ etdata)
 (mapcar '(lambda (x)
           (while (/= "SEQEND" (cdr (assoc 0 (setq etdata (entget (setq x (entnext x)))))))
            (and (= (cdr (assoc 0 etdata)) "ATTRIB")
                 (mapcar '(lambda (x y)
                           (and (= x (cdr (assoc 2 etdata))) (entmod (subst (cons 1 y) (assoc 1 etdata) etdata))))
                         '("DATE_A"); pass the tag names here
                         '("17/06/09"))))); pass the new values here for each tag listed above
         (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "INSERT") (66 . 1)))))))
Message 3 of 7

Kent1Cooper
Consultant
Consultant

How about just using FIND?  You can fill in the "Find what:" and "Replace with:" values in one drawing, and when you open another drawing and call up the command, those are still filled in, so you don't have to enter them again.  Doing that would seem as easy as or easier than opening up an AutoLisp routine definition and putting them into its contents for every such change you need to make, or (setq)-ing them into variables for, or listing them as arguments to, a universal routine.  If you set "Find where:" to Entire drawing, and pick the Replace All button, it does them in Model Space and in all Paper Space layouts, at one shot.  You can even restrict it [pull-down button at lower left for Search options] to changing only Block Attribute values, and/or only whole words, if you might have other things with the same content [even partially] that you don't want changed.

Kent Cooper, AIA
Message 4 of 7

john.uhden
Mentor
Mentor

@Kent1Cooper wrote "How about just using FIND? "

 

And it works even in 2002!

John F. Uhden

0 Likes
Message 5 of 7

Anonymous
Not applicable

Sir,

 

There is a perfectly good explanation.  I have about 400 of these to do and if I have a simple lisp that I can automatically load with each drawing then I already have the ability to write a script that will open each drawing, in turn, execute the lisp, save the changes and move on to the next drawing.  I can start said script at the end of the work day and come in the next morning to 400 corrected drawings.  I know this makes little sense to someone with your superior intellect, however, I am a simple Alabama hillbilly and just trying to do the best my white trash heritage will let me do.

 

Now, Sir, you may not be able to detect the subtle sarcasm in my comments, however, like my mother used to tell me "If you can not help then do not hinder." 

 

I am learning to program my own lisp without asking for help but this particular task is past my skill level.

 

Thank you for being an A$$.  

 

Good day to you.

0 Likes
Message 6 of 7

Anonymous
Not applicable

THANK YOU!!! WORKED EXACTLY LIKE I NEEDED!!

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

...  I have about 400 of these to do and ... have the ability to write a script that will open each drawing, in turn, execute the lisp, save the changes and move on to the next drawing. ....


[For future reference, it's always best to give as much information as possible right from the beginning.  If you had described it that way at first, I would not have suggested using FIND.]

Kent Cooper, AIA
0 Likes