×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to find and replace text strings with no dialogs?

How to find and replace text strings with no dialogs?

How to find and replace text strings with no dialogs?

(OP)
How to find and replace text strings with no dialogs? I wish to run a scipt if possible? Or does anyone know of a lsp that I can add my own find and replace values to?

RE: How to find and replace text strings with no dialogs?

(OP)
I forgot to mention that I need it to cover attributes.

RE: How to find and replace text strings with no dialogs?

FIND AND REPLACE

try www.homescript.com

can even find English text and replace with Japanese equivalent

RE: How to find and replace text strings with no dialogs?

I did not write this and claim no stars for it's posting here, but it works!

;
"CT"   Change text.  Correct spelling errors
;
(DEFUN chgterr (s)
   (if (/= s "Function cancelled")   ; If an error (such as CTRL-C) occurs
      (princ (strcat "\nError: " s)) ; while this command is active...
   )
   (setq p nil)                      ; Free selection set
   (setq *error* olderr)             ; Restore old *error* handler
   (princ)
)

;
(DEFUN C:CT (/ p l n e os as ns st s nsl osl sl si chf chm olderr) ; Correct spelling errors
   (setq olderr  *error*             ; Initialize variables
         *error* chgterr
         chm     0)
   (setq p (ssget))                  ; Select objects
   (if p (progn                      ; If any objects selected
      (while (= 0 (setq osl (strlen (setq os (getstring t "\nOld string: ")))))
            (princ "Null input invalid")
      )
      (setq nsl (strlen (setq ns (getstring t "\nNew string: "))))
      (setq l 0 n (sslength p))
      (while (< l n)                 ; For each selected object...
         (if (= "TEXT"               ; Look for TEXT entity type (group 0)
                (cdr (assoc 0 (setq e (entget (ssname p l))))))
            (progn
               (setq chf nil si 1)
               (setq s (cdr (setq as (assoc 1 e))))
               (while (= osl (setq sl (strlen
                             (setq st (substr s si osl)))))
                  (if (= st os)
                      (progn
                        (setq s (strcat (substr s 1 (1- si)) ns
                                        (substr s (+ si osl))))
                        (setq chf t) ; Found old string
                        (setq si (+ si nsl))
                      )
                      (setq si (1+ si))
                  )
               )
               (if chf (progn        ; Substitute new string for old
                  (setq e (subst (cons 1 s) as e))
                  (entmod e)         ; Modify the TEXT entity
                  (setq chm (1+ chm))
               ))
            )
         )
         (setq l (1+ l))
      )
   ))
   (princ "Changed ")                ; Print total lines changed
   (princ chm)
   (princ " text lines.")
   (terpri)
   (setq *error* olderr)             ; Restore old *error* handler
   (princ)
)

RE: How to find and replace text strings with no dialogs?

Sorry about that.
"CT" runs it.
Of course, load it first !!!
In the lisp, look for the DEFUN C: and what comes after is the command that AutoCAD would recognize.

RE: How to find and replace text strings with no dialogs?

CadDraftee, you have that replace attributes or only text?.

RE: How to find and replace text strings with no dialogs?

(OP)
I need to do both text and or attribute. I know how to do it in one drawing using the "Find and Replace" command which is fantastic - but i want to write it into a script cause I dont want to have to do 50+ drawings individully and I have about 30 items to change in each drawing. Which makes a bit of typing. ie every "a" is to now be "1" and every "b" is to now be "2" etc etc.

Does help anyone with my issue - just seems I can't explanin myself for what i really want.

RE: How to find and replace text strings with no dialogs?


  CadDraftee,

  What are your criteria for changing the
  text/attributes. Are the changes the same
  for a batch of drawings. Do you have a sample
  of the drawing showing the old/new text and/or
  attributes. You don't want dialogs, so how do
  you intend to make the changes known to the
  routine...command line inputs?? It seems that
  the info you have provided are inadequate to
  get a decent reply from this forum.  

RE: How to find and replace text strings with no dialogs?

(OP)
Ok - in my drawing I have continuation arrows with reference to the continuaing drawing. All of these are now changing. So I know that every occurance of F-123 is now going to be F0123 and all occuances of F-506 will be F0106. I can do this using search and replace in to pull down menus but I cant use it in a scipt cause you can't override the cmddia command for this particular command. So I was hoping that someone knows of a way to either override the dialog in the script routine or that someone smart enough has been able to write a program of the similar that I can use in a scipt.

RE: How to find and replace text strings with no dialogs?

Caddraftee,

"So I know that every occurance of F-123 is now going to
F0123 and all occuances of F-506 will be F0106."

Here's your routine:

 ;;;No error checking
;;;11-17-2003 CopyRight (C) 2005 L Estember
;;;Not for Resale or Mass Distribution,
;;;CopyRight (C) Material

(defun C:CHTXT ()

  (setq ss (ssget "X"
             (list '(0 . "TEXT,MTEXT")
                   '(-4 . "<AND")
                     '(-4 . "<OR")
                        (cons 1 "F-123")
                        (cons 1 "F-506")
                     '(-4 . "OR>")
                   '(-4 . "AND>")
             )
           )
  )

  (if (> (sslength ss) 1)
    (progn
      (setq i -1)
      (while (and (setq e (ssname ss (setq i (1+ i))))
                  (setq ed (entget e))
                  (setq str (cdr (assoc 1 ed)))
                  (setq newstr (cond ((= str "F-123") "F0123")
                                     ((= str "F-506") "F0106")
                               )
                  )
             )
         (entmod (setq ed (subst (cons 1 newstr) (assoc 1 ed) ed)))
         (entupd e)
      );while
    );progn
 );if          
        
 (princ)
);defun
       
   
:::Happy Mtexting or Texting....

RE: How to find and replace text strings with no dialogs?


 The routine I posted is good for 2 or more occurrences.
 If there's only 1, it won't work.

RE: How to find and replace text strings with no dialogs?

To replace long lists of text
in all drawings at once as batch process:

members.fortunecity.com/tigrek/

www.homescript.com/autocad/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources