+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19
  1. #1
    Junior Member
    Discipline
    Architectural
    y49sides's Discipline Details
    Occupation
    PM
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Jan 2008
    Posts
    10

    Default Find and replace text without a dialog box

    Registered forum members do not see this ad.

    I looking for a way to automate the find and replace. I have a large amount of drawings with a specific text notation " D.F." needs to be changed to "DF". I want to automate it for my users by creating an lisp and an icon on a toolbar.
    I tried writing it in the macro on an toolbar icon but I do not know how to get it past the dialog box.
    Can anyone point me in the right direction or have a lisp that will do that?
    Thanks in advance

  2. #2
    Forum Deity
    Using
    not specified
    Join Date
    Jul 2004
    Location
    Anchorage, Alaska
    Posts
    2,074

    Default

    Did you look at the similar threads in this forum, as shown at the bottom of this page? This topic has come up a few times.

  3. #3
    Junior Member
    Discipline
    Architectural
    y49sides's Discipline Details
    Occupation
    PM
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Jan 2008
    Posts
    10

    Default

    yes, that is why I decided to post this question. I was looking for something a bit more specific.
    Thanks

  4. #4
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Try this but very quick and dirty

    Code:
    (defun C:RT (/ acapp acsp adoc adocs fn fold full_name_list)
      (or (vl-load-com))
      (setq	fn	       (getfiled "Select *ANY .DWG FILE* in a desired folder : "
    				 ""
    				 "dwg"
    				 4
    		       )
    	fold	       (vl-filename-directory fn)
    	full_name_list (vl-directory-files fold "*.dwg" 1)
    	full_name_list (mapcar (function (lambda (x)
    					   (strcat fold "\\" x)
    					 )
    			       )
    			       full_name_list
    		       )
      )
      (setq	acapp (vlax-get-acad-object)
    	adocs (vla-get-documents acapp)
      )
      (foreach fl full_name_list
        (setq adoc (vla-open adocs fl :vlax-false))
        (setq acsp (vla-get-modelspace adoc))
        (vlax-for lt (vla-get-layouts adoc)
          (vlax-for	obj (vla-get-block lt)
    	(if (eq "AcDbText" (vla-get-objectname obj))
    	  (if (eq "D.F." (vla-get-textstring obj))
    	    (vla-put-textstring obj "DF")
    	  )
    	)
          )
        )
        (vla-save adoc)
        (vla-close adoc)
      )
    )
    (princ "\n\t***\tStart command with RT\t***")
    (princ)
    ~'J'~
    Last edited by fixo; 11th Jan 2008 at 11:27 pm. Reason: spelling

  5. #5
    Junior Member
    Discipline
    Architectural
    y49sides's Discipline Details
    Occupation
    PM
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Jan 2008
    Posts
    10

    Default

    Thank you very much. I got it all set up but it's not switching the text out. The "D.F." is in a string with other text. Could it be that this lisp will only look for a text string with only "D.F." in it?

  6. #6
    Super Member CAB's Avatar
    Using
    AutoCAD 2000
    Join Date
    May 2004
    Location
    Tampa, Florida
    Posts
    805

    Default

    That's exactly why.
    Replace this:
    Code:
    	  (if (eq "D.F." (vla-get-textstring obj))
    	    (vla-put-textstring obj "DF")
    	  )
    with this:
    Code:
    	  (if (wcmatch (vla-get-textstring obj) "*D.F.*")
    	    (vla-put-textstring obj
                  (vl-string-subst "DF" "D.F."(vla-get-textstring obj)))
    	  )

  7. #7
    Junior Member
    Discipline
    Architectural
    y49sides's Discipline Details
    Occupation
    PM
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Jan 2008
    Posts
    10

    Default

    Cab,
    Thank you very much for all the help.
    Can this code be written for just one drawing at a time.
    It seems this code asks me to pick a .dwg file but it goes through all .dwg in that specific folder.
    Thanks again.

  8. #8
    Super Member CAB's Avatar
    Using
    AutoCAD 2000
    Join Date
    May 2004
    Location
    Tampa, Florida
    Posts
    805

    Default

    Sure, try this:
    Code:
    ;;  Code by Fatty Mod by CAB
    (defun C:RT (/ acapp acsp adoc adocs fn)
      (vl-load-com)
      (if (setq fn (getfiled "Select .DWG FILE to replace text : " "" "dwg" 4))
        (progn
          (setq acapp (vlax-get-acad-object)
                adocs (vla-get-documents acapp)
          )
          (setq adoc (vla-open adocs fn :vlax-false))
          (setq acsp (vla-get-modelspace adoc))
          (vlax-for lt (vla-get-layouts adoc)
            (vlax-for obj (vla-get-block lt)
              (if (eq "AcDbText" (vla-get-objectname obj))
                (if (wcmatch (vla-get-textstring obj) "*D.F.*")
                  (vla-put-textstring obj
                    (vl-string-subst "DF" "D.F." (vla-get-textstring obj))
                  )
                )
              )
            )
          )
          (vla-save adoc)
          (vla-close adoc)
        )
      )
      (princ)
    )

  9. #9
    Junior Member
    Discipline
    Architectural
    y49sides's Discipline Details
    Occupation
    PM
    Discipline
    Architectural
    Using
    AutoCAD 2015
    Join Date
    Jan 2008
    Posts
    10

    Default

    Cab,
    Thanks, I'll try that tomorrow. This code looks like it's not for the .dwg that I will currently be in. it looks like the user will still have to manually pick a .dwg. I was looking for it to change the text in the drawing i was in.
    i'm sorry if I sound like a pest. I really do appreciate all of the above info.
    Thanks again

  10. #10
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Thanks God, I'm far enough from Hitleropa
    Posts
    1,697

    Default

    Registered forum members do not see this ad.

    Here is edited version, sorry for belating

    Code:
    (defun C:RT (/ acapp acsp adoc adocs fn fold full_name_list st)
    ;; local defun  
    ;; by Michael Puckett
    (defun Replace ( oldText newText text / i )
     (if (/= oldText newText)
     (while (setq i (vl-string-search oldText text))
     (setq text
     (vl-string-subst
     newText
     oldText
     text
     i
     )
     )
     )
     )
     text
    )
      (or (vl-load-com))
      (setq	fn	       (getfiled "Select *ANY .DWG FILE* in a desired folder : "
    				 ""
    				 "dwg"
    				 4
    		       )
    	fold	       (vl-filename-directory fn)
    	full_name_list (vl-directory-files fold "*.dwg" 1)
    	full_name_list (mapcar (function (lambda (x)
    					   (strcat fold "\\" x)
    					 )
    			       )
    			       full_name_list
    		       )
      )
      (setq	acapp (vlax-get-acad-object)
    	adocs (vla-get-documents acapp)
      )
      (foreach fl full_name_list
        (setq adoc (vla-open adocs fl :vlax-false))
        (setq acsp (vla-get-modelSpace adoc))
        (vlax-for lt (vla-get-layouts adoc)
          (vlax-for	obj (vla-get-block lt)
    	(if (eq "AcDbText" (vla-get-objectname obj))
    	  (if (wcmatch (setq st (vla-get-textstring obj)) "*D.F.*")
    	    (vla-put-textstring obj (Replace "DF" "D.F." st))
    	  )
    	)
          )
        )
        (vla-save adoc)
        (vla-close adoc)
      )
    )
    (princ "\n\t***\tStart command with RT\t***")
    (princ)

Similar Threads

  1. Find & Replace Text
    By drewd1508 in forum AutoLISP, Visual LISP & DCL
    Replies: 25
    Last Post: 19th Mar 2010, 09:57 pm
  2. Replace Text
    By viriato79 in forum AutoCAD General
    Replies: 5
    Last Post: 5th Aug 2009, 07:20 pm
  3. Script for find and replace
    By tim_allen81 in forum AutoCAD General
    Replies: 6
    Last Post: 27th Mar 2008, 02:49 am
  4. Find/Replace text?
    By Ste1978 in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 16th Nov 2007, 03:28 pm
  5. Find/Replace in AutoCAD 2007
    By Aries7 in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 16th Oct 2007, 05:53 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts