davidson_cesar Posted March 23, 2011 Share Posted March 23, 2011 (edited) Hello! This lisp below is a lisp to change words in Autocad drawing (in text and mtext). I'd like to know how to modificate this lisp in order to change blocks and/or dimensions as well. Is it possible? (vl-load-com) (setq *QuickFR:Words* '(("milk" . "coffee") ("water" . "wine") ("juice" . "beer")) ) (defun str-search (pat str / p) (if (setq p (vl-string-search (strcase pat) (strcase str))) (substr str (1+ p) (strlen pat)) ) ) (defun QuickFR (ss / obj item str found changed) (vlax-for obj (vla-get-ActiveSelectionSet (vla-get-activedocument (vlax-get-acad-object))) (setq str (vla-get-TextString obj) found nil) (foreach item *QuickFR:Words* (while (setq found (str-search (car item) str)) (setq str (vl-string-subst (cdr item) found str) changed t) ) ) (if changed(vla-put-TextString obj str)) ) ) (defun c:QuickFR (/ ss) (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) (QuickFR ss) ) (princ) ) (defun c:QuickFR_All (/ ss) (if (setq ss (ssget "_X" '((0 . "TEXT,MTEXT")))) (QuickFR ss) ) (princ) ) Edited March 25, 2011 by SLW210 Put CODE in BOX Quote Link to comment Share on other sites More sharing options...
pBe Posted March 23, 2011 Share Posted March 23, 2011 Try this http://www.cadtutor.net/forum/showthread.php?46135-Batch-Find-amp-Replace-Text&highlight=batch+find.html Quote Link to comment Share on other sites More sharing options...
davidson_cesar Posted March 24, 2011 Author Share Posted March 24, 2011 Thanks for replying Pb. But I'd like to improve that lisp that I put above. How can I improve that routine? Quote Link to comment Share on other sites More sharing options...
pBe Posted March 25, 2011 Share Posted March 25, 2011 (edited) Thanks for replying Pb. But I'd like to improve that lisp that I put above. How can I improve that routine? I never really did look at the code. my reply was based on the title of the thread , sorry about that you know what they say, "dont try to re-invent the wheel" I guess it can be improved (that is if there's anything to improve at all), but I understand what you mean :wink: First glance: An option to look Find "Whole Words Only" would be nice (QuickFR ss T); I'll have a look/see later Edited March 25, 2011 by pBe Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 25, 2011 Share Posted March 25, 2011 Davidson, please use code tags when posting code: (Without the spaces in the tags) Link to original code: http://www.cadtutor.net/forum/showthread.php?57399-Lisp-to-change-words-in-an-Autocad-drawing&p=389220&viewfull=1#post389220 Quote Link to comment Share on other sites More sharing options...
SLW210 Posted March 25, 2011 Share Posted March 25, 2011 Davidson, please use code tags when posting code: (Without the spaces in the tags) Link to original code: http://www.cadtutor.net/forum/showthread.php?57399-Lisp-to-change-words-in-an-Autocad-drawing&p=389220&viewfull=1#post389220 I took care of the Code Tags. Lets not make this a habit davidson-cesar. Quote Link to comment Share on other sites More sharing options...
davidson_cesar Posted March 26, 2011 Author Share Posted March 26, 2011 Thanks!!! Quote Link to comment Share on other sites More sharing options...
pBe Posted March 26, 2011 Share Posted March 26, 2011 (edited) So going back to your code to include text on blocks is not that hard, but the question is would you want to include Attributes as well? I would think including dimension text would be a tough one though, unless its an override, retriving the value would be a cinch. > help!!! My suggestion: (questions really) I noticed that you iterate thru the list (*QuickFR:Words*) for every text/mtext selected, I would make something like a 2 phase string match. 1st phase: if nil dont bother going thru the list 2nd phase: if T then do it I would do it this way, before the main routine (a one time thingy), assuming values for *QuickFR:Words* are from a sub routine (setq phase1 "") (foreach v *QuickFR:Words* (setq phase1 (strcat phase1 "*" (car v) "*,") )) from your example it will give you "*milk*,*water*,*juice*," before running ...(foreach item *QuickFR:Words* (while (setq foun..... Run Phase 1 test (wcmatch "beer on the bottle" phase1);<< -- value of [b]str[/b] Nil: process next object (wcmatch "milk on the bottle" phase1);<<-- value of [b]str[/b] T: process the object and go thru list its a bit faster (jsut a tad really) especially when you use the ALL option but thats just me Edited March 26, 2011 by pBe Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 26, 2011 Share Posted March 26, 2011 > help!!! Two ways I can think of... 1) Digging through the Anonymous block definition for the Dimension: (defun LM:GetDimensionString ( dim / dl db ds ) (if (and (wcmatch (cdr (assoc 0 (setq dl (entget dim)))) "*DIMENSION") (setq db (tblobjname "BLOCK" (cdr (assoc 2 dl)))) ) (while (and (setq db (entnext db)) (not ds)) (if (eq "MTEXT" (cdr (assoc 0 (setq dl (entget db))))) (setq ds (cdr (assoc 1 dl))) ) ) ) ds ) 2) Grabbing the MText Entity using a nested selection (unreliable if objects overlap the Dimension MText though): (defun LM:GetDimensionString ( dim / dl mt ) (if (and (wcmatch (cdr (assoc 0 (setq dl (entget dim)))) "*DIMENSION") (setq mt (car (nentselp (trans (cdr (assoc 11 dl)) dim 1)))) ) (cdr (assoc 1 (entget mt))) ) ) Lee Quote Link to comment Share on other sites More sharing options...
pBe Posted March 26, 2011 Share Posted March 26, 2011 Two ways I can think of... 1) Digging through the Anonymous block definition for the Dimension: (defun LM:GetDimensionString ( dim / dl db ds ) (if (and (wcmatch (cdr (assoc 0 (setq dl (entget dim)))) "*DIMENSION") (setq db (tblobjname "BLOCK" (cdr (assoc 2 dl)))) ) (while (and (setq db (entnext db)) (not ds)) (if (eq "MTEXT" (cdr (assoc 0 (setq dl (entget db))))) (setq ds (cdr (assoc 1 dl))) ) ) ) ds ) Lee Fantastic! I like it. thanks Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 26, 2011 Share Posted March 26, 2011 Fantastic! I like it. thanks Lee You're welcome Quote Link to comment Share on other sites More sharing options...
davidson_cesar Posted March 31, 2011 Author Share Posted March 31, 2011 Sorry Lee, but I'm a starter abt lisp. I tried to put the first option -" Digging through the Anonymous block definition for the Dimension"-in the lisp, but it haven't worked. Could you help me to put it in order? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 31, 2011 Share Posted March 31, 2011 Sorry Lee, but I'm a starter abt lisp. I tried to put the first option -" Digging through the Anonymous block definition for the Dimension"-in the lisp, but it haven't worked. Sorry Davidson, that was just answering pBe's question regarding the method of obtaining the Dimension string as displayed. With regard to your program, I spent a lot of time on my 'BFind' program to account for the problems entailed with replacing text in MText with MText formatting codes, and also to enable the user to find and replace multiple text strings in a multitude of objects - I'd rather not re-invent the wheel on this one. Quote Link to comment Share on other sites More sharing options...
pBe Posted March 31, 2011 Share Posted March 31, 2011 - I'd rather not re-invent the wheel on this one. Funny, thats exactly what i've said on the early part of this thread Quote Link to comment Share on other sites More sharing options...
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.