Jump to content

Replace multiple text


mrdd

Recommended Posts

Hello

Here's my problem. I ve got hundreds of texts contain letters and numbers like this 'TT01 23+566.66' 'TT02 22+364.64' 'TT03 28+556.89'. So i need the first part of the text which is TT'number' to be removed. I cant do that with the basic find and replace tool because numbers are different. Is there any lisp you know to handle this?

Link to comment
Share on other sites

You can also use this :

(defun STRFIND (SRC SRCH / 
               CNT
               RET
               )
  (setq CNT 1)
 (while (<= CNT (strlen SRC))
    (if
       (= (substr SRC CNT (strlen SRCH)) SRCH)
           (setq RET (list
                       (substr SRC 1 (1- CNT))
                       (substr SRC (+ CNT (strlen SRCH)))) CNT (1+ (strlen SRC))
                 )
      
           (setq CNT (1+ CNT))))
 (if (null RET) (list SRC nil) RET))



(defun c:test (/ STR)
 (setq STR (getstring "\nType in a string: "))
 (while
   (/=
     (and
       (setq SSTR (car (entsel "\nSelect a string to change: ")))
       (if
         (= (type (cdr (assoc 1 (entget SSTR)))) 'STR)
         (progn
           (setq RES (strfind (cdr (assoc 1 (entget SSTR))) STR))
           (entmod
             (subst
               (cons 1 (strcat (car RES) (cadr RES)))
               (assoc 1 (entget SSTR))
               (entget SSTR)
               )
             )
           )
         )
       )
     )
   )
 (princ)
 )

Edited by cadplayer
Link to comment
Share on other sites

As pBe correctly suggests, the substr function is the key for this task:

 

(defun c:txtupd ( / e i s x )
   (if (setq s (ssget "_:L" '((0 . "TEXT") (1 . "TT## *"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 x (assoc 1 e)
           )
           (entmod (subst (cons 1 (substr (cdr x) 6)) x e))
       )
   )
   (princ)
)

Link to comment
Share on other sites

  • 2 weeks later...

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