wimal Posted September 29, 2015 Share Posted September 29, 2015 I have written several places of my drawing following texts MDB/L7/Z1/M1/2L3 MDB/L7/Z1/M1/2L2 EMDB/L7/Z1/M1/2L3 EMDB/L7/Z1/M1/2L2 ect. I need change this L7 to L4 in next drawing. Is there a facility or lisp code to select this L7 at once inside the DDEDIT dialog box. Then I can type L4 replacing L7. Quote Link to comment Share on other sites More sharing options...
rlx Posted September 29, 2015 Share Posted September 29, 2015 I have written several places of my drawing following textsMDB/L7/Z1/M1/2L3 MDB/L7/Z1/M1/2L2 EMDB/L7/Z1/M1/2L3 EMDB/L7/Z1/M1/2L2 ect. I need change this L7 to L4 in next drawing. Is there a facility or lisp code to select this L7 at once inside the DDEDIT dialog box. Then I can type L4 replacing L7. both my vt.lsp and ct.lsp can do this and also Lee Mac has a ton of utilities to do the job. Just search this forum. gr. Rlx Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 29, 2015 Share Posted September 29, 2015 This should change the first L7 that in the selected text. (defun c:Test (/ ss sn p st e ) ;; Tharwat 29.9.2015 ;; (if (setq ss (ssget "_:L" '((0 . "TEXT")(1 . "*L7*")))) (while (setq sn (ssname ss 0)) (if (setq p (vl-string-search "L7" (setq st (cdr (assoc 1 (setq e (entget sn))))))) (entmod (subst (cons 1 (strcat (substr st 1 p) "L4" (substr st (+ 3 p)))) (assoc 1 e) e)) ) (ssdel sn ss) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
mostafa badran Posted September 29, 2015 Share Posted September 29, 2015 I need change this L7 to L4 in next drawing. Does that mean in other closed drawing or in the same drawing? Quote Link to comment Share on other sites More sharing options...
wimal Posted September 29, 2015 Author Share Posted September 29, 2015 This should change the first L7 that in the selected text. (defun c:Test (/ ss sn p st e ) ;; Tharwat 29.9.2015 ;; (if (setq ss (ssget "_:L" '((0 . "TEXT")(1 . "*L7*")))) (while (setq sn (ssname ss 0)) (if (setq p (vl-string-search "L7" (setq st (cdr (assoc 1 (setq e (entget sn))))))) (entmod (subst (cons 1 (strcat (substr st 1 p) "L4" (substr st (+ 3 p)))) (assoc 1 e) e)) ) (ssdel sn ss) ) ) (princ) ) Thanks... above code fulfilled my requirements more than I expected. Quote Link to comment Share on other sites More sharing options...
wimal Posted September 29, 2015 Author Share Posted September 29, 2015 Does that mean in other closed drawing or in the same drawing? I mean another open drawing. Quote Link to comment Share on other sites More sharing options...
mostafa badran Posted September 29, 2015 Share Posted September 29, 2015 I mean another open drawing. So I recommended you this lisp by the legend Lee Mac. http://lee-mac.com/bfind.html Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 29, 2015 Share Posted September 29, 2015 Thanks... above code fulfilled my requirements more than I expected. You're welcome. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 29, 2015 Share Posted September 29, 2015 This should change the first L7 that in the selected text. Good stuff Tharwat - though as a minor suggestion, since you are restricting the original selection, you can be guaranteed that the pattern will be present and therefore a simple vl-string-subst will suffice, e.g.: (defun c:test ( / e i s x ) (if (setq s (ssget "_:L" '((0 . "TEXT") (1 . "*L7*")))) (repeat (setq i (sslength s)) (setq e (entget (ssname s (setq i (1- i)))) x (assoc 1 e) ) (entmod (subst (cons 1 (vl-string-subst "L4" "L7" (cdr x))) x e)) ) ) (princ) ) Lee Mac has a ton of utilities to do the job. So I recommended you this lisp by the legend Lee Mac.http://lee-mac.com/bfind.html Many thanks for the recommendations guys! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 29, 2015 Share Posted September 29, 2015 Lee , yes you are right. Honestly I was aware of that when I wrote that simple codes and did not remove that check out on the pattern as long as it doesn't hurt. Thanks. Quote Link to comment Share on other sites More sharing options...
wimal Posted September 30, 2015 Author Share Posted September 30, 2015 Mr. Tharwat Why cant I used it this way (defun c:Test (/ ss sn p st e find replase) ;; Tharwat 29.9.2015 ;; (setq find (getstring "Find ")) (setq replace (getstring "Replase ")) (if (setq ss (ssget "_:L" '((0 . "TEXT")(1 . *find*)))) (while (setq sn (ssname ss 0)) (if (setq p (vl-string-search exist (setq st (cdr (assoc 1 (setq e (entget sn))))))) (entmod (subst (cons 1 (strcat (substr st 1 p) replace (substr st (+ 3 p)))) (assoc 1 e) e)) ) (ssdel sn ss) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 30, 2015 Share Posted September 30, 2015 Mr. Tharwat Why cant I used it this way (defun c:Test (/ ss sn p st e find replase) ;; Tharwat 29.9.2015 ;; (setq find (getstring "Find ")) (setq replace (getstring "Replase ")) (if (setq ss (ssget "_:L" '((0 . "TEXT")(1 . *find*)))) (while (setq sn (ssname ss 0)) (if (setq p (vl-string-search exist (setq st (cdr (assoc 1 (setq e (entget sn))))))) (entmod (subst (cons 1 (strcat (substr st 1 p) replace (substr st (+ 3 p)))) (assoc 1 e) e)) ) (ssdel sn ss) ) ) (princ) ) See the changes: (defun c:test (/ ss sn st e find replace) ;; Tharwat 29.9.2015 ;; (if (and (/= "" (setq find (getstring "\nFind :"))) (/= "" (setq replace (getstring "\nReplace :"))) (setq ss (ssget "_:L" (list '(0 . "TEXT") (cons 1 (strcat "*" find "*"))) ) ) ) (while (setq sn (ssname ss 0)) (setq e (entget sn) st (cdr (assoc 1 e)) ) (entmod (subst (cons 1 (vl-string-subst replace find st)) (assoc 1 e) e ) ) (ssdel sn ss) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
wimal Posted September 30, 2015 Author Share Posted September 30, 2015 Thanks a lot. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 30, 2015 Share Posted September 30, 2015 Thanks a lot. You're welcome. 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.