merlin_m007 Posted December 24, 2009 Posted December 24, 2009 hai all I am a University student and a part time worker Pls help me with a Auto cad lisp programme which find and replaces attribute values in autocad attributes eg if the VALUES of different attributes are CAXXXXYYYY001,CAXXXXYYYY002,CAXXXXYYYY003 etc then I would like to replace 2nd letter 'C' with letter 'D' thus it becomes CDXXXXYYYY001,CDXXXXYYYY002,CDXXXXYYYY003 etc already got one .exe programme but system security does not allow me to install the programme to my system thats y I badly need a lisp kindly help thanks in advance Merlin Menaco Quote
fixo Posted December 24, 2009 Posted December 24, 2009 hai all I am a University student and a part time worker Pls help me with a Auto cad lisp programme which find and replaces attribute values in autocad attributes eg if the VALUES of different attributes are CAXXXXYYYY001,CAXXXXYYYY002,CAXXXXYYYY003 etc then I would like to replace 2nd letter 'C' with letter 'D' thus it becomes CDXXXXYYYY001,CDXXXXYYYY002,CDXXXXYYYY003 etc already got one .exe programme but system security does not allow me to install the programme to my system thats y I badly need a lisp kindly help thanks in advance Merlin Menaco This will work just for attributes that starts with "CA" For other cases change attribute patterns inside the code ;; cav.lsp ;; change attribute values by given pattern (defun C:CAV (/ *error* adoc atts cnt layer locked newvalue oldvalue) ;; error trapping function (defun *error* (msg) (if (and msg (vl-position msg '("console break" "Function cancelled" "quit / exit abort" ) ) ) (princ (strcat "Error >>> " (princ msg))) (princ msg) ) (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)) ) ) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) ) (vla-startundomark adoc) (setq cnt 0) ;; loop through all layouts (vlax-for layout (vla-get-layouts adoc) (vlax-for obj (vla-get-block layout) (if (and (eq "AcDbBlockReference" (vla-get-objectname obj)) (eq :vlax-true (vla-get-hasattributes obj))) (progn (setq layer (vla-item (vla-get-layers adoc) (vla-get-layer obj))) (if (eq :vlax-true (vla-get-lock layer)) (progn (setq locked (cons (vla-get-layer obj) locked)) (vla-put-lock layer :vlax-false)) ;<--unlock layer if locked ) (setq atts (vlax-invoke obj 'GetAttributes)) (foreach att atts (setq oldvalue (vla-get-textstring att)) ;<--get attribute value (if (wcmatch oldvalue "CA*") ;<-- CA* is attribute pattern, change to suit (progn (setq cnt (1+ cnt)) ;<--increment counter (setq newvalue (vl-string-subst "D" "A" oldvalue)) ;<--change patterns(letters) to suit (vla-put-textstring att newvalue) ;<--set new attribute value (vla-update att) (princ (strcat "\n\t\t\t\t\>> Attribute value " (vl-princ-to-string oldvalue) " changed on: " (vl-princ-to-string newvalue))) ) ) ) (vla-update obj) ) ) ) ) ;; turn all layers state back (if locked (foreach layer locked (vla-put-lock (vla-item (vla-get-layers adoc) layer) :vlax-true)) ) (setq locked nil) (alert (strcat "Done. Processed " (itoa cnt) " attributes on all layouts")) (*error* nil) (princ) ) (prompt"\n\t\t\t\tType CAV to change attributes by pattern") (princ) (vl-load-com);_end of code ~'J'~ Quote
flowerrobot Posted December 24, 2009 Posted December 24, 2009 Dude you have posted the exscat same thing in 3 different thread...not cool Quote
fixo Posted December 24, 2009 Posted December 24, 2009 Dude you have posted the exscat same thing in 3 different thread...not cool Agreed ~'J'~ Quote
jaylo23 Posted December 30, 2009 Posted December 30, 2009 I have a simillar question to the one that merlin had. Where i differ is that i have several blocks in a model that all have the attribute tag "COMMENTS". What i would like to be able to do is have the lisp, after selecting a particular block, give the option at the command line of "LKG. NORTH, LKG. SOUTH, LKG. EAST, LKG. WEST" and then the user would hit "N" for lkg.north "S" for lkg.south, etc and change the "COMMENTS" value to that. Or just enter in whatever they wanted if they need something other than that. Also, if possible, if the "COMMENTS" tag already has a value, could it retain the value and just add the "LKG. NORTH" value to the front of the existing tag whereby "1234" would become "LKG. NORTH;1234". I apologize if this has already been posted or is asking too much, ive tried my hand at it for a few days now and have gotten nowhere as it is far out of the realm of my abilities. Thanks in advance for any help! Quote
Lee Mac Posted December 30, 2009 Posted December 30, 2009 Give this a shot: (defun c:attupd (/ i ss ent att) (vl-load-com) (or *def_com* (setq *def_com* "NORTH")) ;; First-time Default (if (and (setq i -1 ss (ssget "_:L" '((0 . "INSERT") (66 . 1)))) (not (initget "NORTH SOUTH EAST WEST")) (setq *def_com* (cond ((getkword (strcat "\nNorth/South/East/West? <" *def_com* "> : "))) (*def_com*)))) (while (setq ent (ssname ss (setq i (1+ i)))) (foreach att (vlax-invoke (vlax-ename->vla-object ent) 'GetAttributes) (and (eq "COMMENTS" (strcase (vla-get-TagString att))) (vla-put-TextString att (strcat "LKG. " *def_com* (vla-get-TextString att))))))) (princ)) Quote
jaylo23 Posted December 30, 2009 Posted December 30, 2009 Lee Mac you never cease to amaze, PERFECT!!! I definitely owe you a pint or 4. Next time im in or around London ill let ya know! Quote
Lee Mac Posted December 30, 2009 Posted December 30, 2009 Lee Mac you never cease to amaze, PERFECT!!! I definitely owe you a pint or 4. Next time im in or around London ill let ya know! You're welcome Jaylo - anytime mate Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.