Jump to content

Recommended Posts

Posted

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

 

image.png.252792cf59b47764b77e8edb0931bacf.png

 

image.png.b82368839f813ec437ddee13393f3703.pngnew block.dwg

 

Posted

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.

Posted
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

  • Like 1
Posted

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)
)

 

  • Like 1
Posted
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 😍

Posted

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)
)

 

Posted (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 by Isaac26a

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...