Jump to content

Find & Replace in current layout only


clint0577

Recommended Posts

I have 2 things I'm trying to accomplish here. I need to find the the exact text to replace and only in the current layout. For example. Let's say I need to find "Date" but on the same layout I have "date", "Date" and "Date:". So it needs to be case sensitive also. I was using this but it's not case sensitive and also replaces "date" and "Date:" in all layouts. I just need "Date" in the current layout.

 

;Find And Replace
(defun C:FAR ()
(setq OldTxt (getstring T "\nEnter the old text: ")
	  NewTxt (getstring T "\nEnter the new text: "))

(setq ss (ssget "x" '((0 . "TEXT,MTEXT"))))
	
(setq i (sslength ss))

(while (not (minusp (setq i (1- i))))
	(setq oText (vlax-ename->vla-object (ssname ss i)))
	(setq Txt (vlax-get-property oText 'TextString))
	
	(if (vl-string-search OldTxt txt)
		(progn
			(setq newChg (vl-string-subst NewTxt OldTxt txt))
			(vlax-put-property oText 'TextString newchg)
			(vlax-invoke-method oText 'Update)
		)
	)
)
(princ)
)


Link to comment
Share on other sites

Hope that your texts are not Annotative ..

 

(defun c:test (/ oldTxt NewTxt ss in en)
 (if
   (and (not
          (eq (setq OldTxt (getstring T "\nEnter the old text: ")) "")
        )
        (not
          (eq (setq NewTxt (getstring T "\nEnter the new text: ")) "")
        )
   )
    (if (setq ss (ssget "x"
                        (list '(0 . "TEXT,MTEXT")
                              (cons 1 OldTxt)
                              (cons 410 (getvar 'ctab))
                        )
                 )
        )
      (repeat (setq in (sslength ss))
        (setq en (entget (ssname ss (setq in (1- in)))))
        (entmod (subst (cons 1 Newtxt) (assoc 1 en) en))
      )
    )
 )
 (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...