Jump to content

Text add or replace


j_spawn_h

Recommended Posts

Tharwat wrote the add text at the bottom. Which works great. Thank you!

I wanted to add dialog box to add text or replace text in different places of existing text. I got it to work but I can't seem to write how not to add the text if it is already there.

Example: if I had the suffix then add the suffix again it will add it not change it.

I have more than one choice for suffixs and prxs. But 2 suffixs can't be in the same text string.

Also I do I loop this so after I make my pick in the box I can go around and touch as many as I want to change.

 

(defun c:Test (/ ss l sset str e
        suffixs prxs)
 (setq  lstprxs '("CANT" "NOTHING") 
        lstsuffixs '("FRB" "UWA" "UCA" "NOTHING"));end setq

 (or prxs (setq prxs (car lstprxs)))
 (or suffixs (setq suffixs (car lstsuffixs)))

(setq dcl_id (load_dialog "textest.dcl"))                      
(if (not (new_dialog "textest" dcl_id)) (exit))                        
   (progn
       (set_tile prxs "1")
       (set_tile suffixs "1")
       (action_tile "prxs" "(setq prxs $value)")
       (action_tile "suffixs" "(setq suffixs $value)"));end progn

       (start_dialog)
       (unload_dialog dcl_id)

 (if
   (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
    (repeat
      (setq l (sslength ss))
       (setq sset (ssname ss (setq l (1- l))))
       (setq str (cdr (assoc 1 (setq e (entget sset)))))
       (entupd
         (cdr
           (assoc
             -1
             (setq rr(entmod (subst (cons 1 (strcat prxs str suffixs )) (assoc 1 e) e)))
           )
         )
       )
    )
    (princ)
 )
 (princ)
)

Edited by j_spawn_h
Add some text,changed title
Link to comment
Share on other sites

A couple of ways you can use a Vl-string-search to see if it exists, check the correct number of characters as prefix or suffix use (substr string start end) (substr "abcdfghk" 1 3) = abc, if this is wrong wcmatch also.

Link to comment
Share on other sites

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