Jump to content

Lisp to replace words


lupita6

Recommended Posts

Very good to the community and congratulations on your success,

 

needed a little help to create a simple lisp routine. This is a lisp that allows me to change the words of a drawing: "Escala" for "Scale" and "Parte" for "Piece" no more. Only a change of words in the file, without having to select objects or anything.

 

I know the Find and Replace Command, (its great), but I need this routine to apply it to 200 DWGS with EZscript-Pro.

 

I do not mind changing the words of the routine every time I apply.

 

Thank you very much and live all the experts in CAD

Link to comment
Share on other sites

Be careful to have all strings not on locked layers :)

 

(defun c:TesT (/ ss i sn)
 (if (setq ss (ssget "_x" '((0 . "*TEXT") (1 . "Escala,Parte"))))
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (cond
       ((eq (cdr (assoc 1 (entget sn))) "Escala")
        (entmod
          (subst (cons 1 "Scale") (assoc 1 (entget sn)) (entget sn))
        )
       )
       (t
        (entmod
          (subst (cons 1 "Piece") (assoc 1 (entget sn)) (entget sn))
        )
       )
     )
   )
   (princ)
 )
 (princ)
)

Link to comment
Share on other sites

Or if you don't want to use Lee's and the words are only part of the text (instead of the whole text). Also if string case should be ignored:

(vl-load-com)

(defun c:TextRepl (/ pat str ss s p)
 (if (and (setq pat (getstring t "\nEnter string to search for: "))
          (setq str (getstring t "Enter replacement: "))
          (ssget (list '(0 . "TEXT,MTEXT")
                       (cons 1 (setq pat (strcat "*"
                                                 (apply 'strcat (mapcar '(lambda (c)
                                                                           (strcat "[" (strcase c) (strcase c t) "]"))
                                                                        (mapcar 'chr (vl-string->list pat))))
                                                 "*")))))
          (setq ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object)))))
   (progn
     (vlax-for eo ss
       (setq s (vla-get-TextString eo) p "")
       (while (wcmatch s pat)
         (while (not (wcmatch s (substr pat 2)))
           (setq p (strcat p (substr s 1 1)) s (substr s 2)))
         (setq p (strcat p str) s (substr s (1+ (/ (- (strlen pat) 2) 4)))))
       (if (not (eq s "")) (setq p (strcat p s)))
       (vla-put-TextString eo p))
     (vla-Delete ss)))
 (princ))

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