asdfgh Posted October 18, 2022 Posted October 18, 2022 Hello Everyone, I have some texts as following (the texts in blue), I want for all texts to remove the bracket "(" and any text before it, and also the bracket ")" and any text after it, so the result would be like the text in green. Any one have lisp for that ? Thanks in advance new block.dwg Quote
Steven P Posted October 18, 2022 Posted October 18, 2022 Do all the texts follow the same formats as shown, for example all ending with ")", ")Inv.") or ") Inv." and all starting with "Bn(", which would make the LISP a bit easier - there is LISP find and replace out there which will work OK if you can specify the exact text you want changing (like regular find and replace but without the dialogue box). If not will have to work out the texts to remove - which might be a shorter LISP and more versatile but I don't have that to copy and paste here. Quote
asdfgh Posted October 18, 2022 Author Posted October 18, 2022 26 minutes ago, Steven P said: Do all the texts follow the same formats as shown, for example all ending with ")", ")Inv.") or ") Inv." and all starting with "Bn(", which would make the LISP a bit easier - there is LISP find and replace out there which will work OK if you can specify the exact text you want changing (like regular find and replace but without the dialogue box). If not will have to work out the texts to remove - which might be a shorter LISP and more versatile but I don't have that to copy and paste here. Thank you for your reply, i am afraid it is not, i don't have certain format of texts each time, the things that will always be there is the "X" and the brackets 1 Quote
Isaac26a Posted October 18, 2022 Posted October 18, 2022 Hi, try this and let me know if it works for you ;;; By Isaac A 20221018 ;;; https://www.cadtutor.net/forum/topic/76182-text-modifiaction/ (vl-load-com) (defun c:remov (/ a b c d e f g h) (vl-cmdf "_undo" "_begin") (setq a (getvar 'cmdecho)) (setvar 'cmdecho 0) (prompt "\nSelect the texts to modify: ") (setq b (ssget '((0 . "*TEXT")))) (if (/= b nil) (progn (setq c 0 d (sslength b)) (while (< c d) (wcmatch (cdr (assoc 0 (setq e (entget (ssname b c))))) "TEXT,MTEXT") (setq f (cdr (setq g (assoc 1 e))) ) (if (/= nil (vl-string-search (chr 40) f)) (progn (setq h (substr f (+ (vl-string-search (chr 40) f) 2) (- (1- (vl-string-search (chr 41) f)) (vl-string-search (chr 40) f))) ) (setq e (subst (cons 1 h) g e)) (entmod e) ) ) (setq c (1+ c)) ) ) ) (setvar 'cmdecho a) (vl-cmdf "_undo" "_end") (princ) ) 1 Quote
asdfgh Posted October 18, 2022 Author Posted October 18, 2022 33 minutes ago, Isaac26a said: Hi, try this and let me know if it works for you ;;; By Isaac A 20221018 ;;; https://www.cadtutor.net/forum/topic/76182-text-modifiaction/ (vl-load-com) (defun c:remov (/ a b c d e f g h) (vl-cmdf "_undo" "_begin") (setq a (getvar 'cmdecho)) (setvar 'cmdecho 0) (prompt "\nSelect the texts to modify: ") (setq b (ssget '((0 . "*TEXT")))) (if (/= b nil) (progn (setq c 0 d (sslength b)) (while (< c d) (wcmatch (cdr (assoc 0 (setq e (entget (ssname b c))))) "TEXT,MTEXT") (setq f (cdr (setq g (assoc 1 e))) ) (if (/= nil (vl-string-search (chr 40) f)) (progn (setq h (substr f (+ (vl-string-search (chr 40) f) 2) (- (1- (vl-string-search (chr 41) f)) (vl-string-search (chr 40) f))) ) (setq e (subst (cons 1 h) g e)) (entmod e) ) ) (setq c (1+ c)) ) ) ) (setvar 'cmdecho a) (vl-cmdf "_undo" "_end") (princ) ) Thank you so much, this worked very well Quote
ronjonp Posted October 18, 2022 Posted October 18, 2022 Here's another way assuming there are no spaces within the brackets. (defun c:foo (/ o s tx) (if (setq s (ssget ":L" '((0 . "*TEXT") (1 . "*(*)*")))) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq tx (vla-get-textstring (setq o (vlax-ename->vla-object e)))) (vla-put-textstring o (vl-princ-to-string (read (substr tx (+ 2 (vl-string-search "(" tx)))))) ) ) (princ) ) Quote
Isaac26a Posted October 18, 2022 Posted October 18, 2022 (edited) 31 minutes ago, ronjonp said: Here's another way assuming there are no spaces within the brackets. (defun c:foo (/ o s tx) (if (setq s (ssget ":L" '((0 . "*TEXT") (1 . "*(*)*")))) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq tx (vla-get-textstring (setq o (vlax-ename->vla-object e)))) (vla-put-textstring o (vl-princ-to-string (read (substr tx (+ 2 (vl-string-search "(" tx)))))) ) ) (princ) ) Pretty cool way of reducing code of the selection, also your code has no need of entmod, I think there is only missing (vl-load-com) Edited October 18, 2022 by Isaac26a 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.