djeetn069 Posted May 31, 2014 Posted May 31, 2014 I'm trying to find a lisp routine that searches the current drawing for a certain string and replaces that with the string of a variable already defined by the user (in this case the text to look for is "****" and the variable is called "offerte"). Not only in the Text, Mtext but also in the Blocks, Dynamic blocks, attributes and fields... Following code gets the job done but only for normal Text and Mtext. (defun tekstreplace (/ tss tdata) (setq tss (ssget "X" (list (cons 1 "****")))) (repeat (sslength tss) (setq tdata (entget (ssname tss 0)) tdata (subst (cons 1 offerte) (assoc 1 tdata) tdata) ) (entmod tdata) (ssdel (ssname tss 0) tss) ) ) Thanx in advance for any comments! Quote
lamensterms Posted June 1, 2014 Posted June 1, 2014 Lee Mac has a great find & replace tool. http://www.lee-mac.com/bfind.html It should suit your needs. Quote
djeetn069 Posted June 1, 2014 Author Posted June 1, 2014 Well, i would really want it to be automated so the user isn't bothered with to much dialog boxes. I did already perform a search on the site of Lee Mac, but without result for this specific issue. I'm actually not sure if this is possible at all. As I've searched the Web, but didn't find any solution. That's why I need some help from much more experienced lisp users than myself. Again, any help or suggestions would be much appreciated! Quote
fixo Posted June 1, 2014 Posted June 1, 2014 found this one old lisp in my code library, try it on your end, change old and new text values, block name to your suit (vl-load-com) (defun c:RTO (/ ablocks acapp adoc blkdef blklist blkobj en i newtext oldtext sset) (setq acapp (vlax-get-acad-object) adoc (vla-get-activedocument acapp) ablocks (vla-get-blocks adoc)) (setq oldtext "ahha" newtext "new text");change to suit (if (setq sset (ssget "_X" (list (cons 0 "INSERT")(cons 66 1)(cons 2 "`*U*,DynBlock"))));DynBlock is name for your interest (progn (setq i (sslength sset)) (while (setq en (ssname sset (setq i (1- i)))) (setq blkobj (vlax-ename->vla-object en)) (if (not (member "DynBlock" blklist)); use DynBlock only (setq blklist (cons (vla-get-effectivename blkobj) blklist))) (ssdel en sset)) (repeat (length blklist) (if (not (vl-catch-all-error-p (setq blkdef (vl-catch-all-apply 'vla-item (list ablocks (nth 0 blklist)))))) (progn (vlax-for a blkdef (if (eq "ACDBTEXT" (strcase (vla-get-objectname a))) (if (eq oldtext (vla-get-textstring a)) (vla-put-textstring a newtext))) (if (eq "ACDBMTEXT" (strcase (vla-get-objectname a))) (if (eq oldtext (vla-get-textstring a)) (vla-put-textstring a newtext)))) )) (setq blklist (cdr blklist))) (command "_attsync" "_N" "*") (command "_regenall") ) ) (princ) ) Quote
djeetn069 Posted June 3, 2014 Author Posted June 3, 2014 Thanks for your post fixo. I've implemented it into my code, but it didn't work out. Maybe if you could specify what i should place instead of Dynblock. I've already tried ceveral blocknames that has been inserted into the drawing, but again no result. I've also noticed that the searched string in a regular Mtext isn't changed as well. Could i be doing something wrong here? Thanks in advanced for your much needed help! Quote
BIGAL Posted June 4, 2014 Posted June 4, 2014 Not sure but what did FIND do it certainaly changes attribute values in blocks. Quote
djeetn069 Posted June 4, 2014 Author Posted June 4, 2014 I've tried every option available again, but still can't get above code to work??? @ BIGAL: You mean you do? 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.