Author Topic: Find & Replace Script - Quick Question  (Read 16983 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find & Replace Script - Quick Question
« Reply #15 on: January 29, 2007, 05:41:49 PM »
Mike,
Did the routine work for you or blow you computer up.
I do hope it went OK. I revised the code to work with Paper Space and/or Model Space.

<code removed, see previous post>
« Last Edit: February 19, 2007, 03:33:32 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Find & Replace Script - Quick Question
« Reply #16 on: January 29, 2007, 05:59:18 PM »
Here is one I did for someone on the Adesk Ng.  You can use/ingnore/change it all you want.  Right now it only works in the current drawing, but that can easly be changed.  It will look through text, mtext, tables, blocks, dimensions, and attribute definitions.
Code: [Select]
(defun c:ReplaceAllStrings (/ ActDoc DtextList MtextList)

(defun ReplaceAllStrings (Doc MtextReplcList DtextReplcList / tempObjType ColCnt RowCnt)

(defun ReplaceString (String ReplaceList MtextObj / strTest strReplc Pos IsFormat FormatList strTemp)

(foreach pair ReplaceList
 (setq strTest (car pair))
 (setq strReplc (cdr pair))
 (setq Pos -1)
 (while
  (and
   (< Pos (strlen String))
   (setq Pos (vl-string-search strTest String (setq Pos (1+ Pos))))
  )
  (if (equal Pos 0)
   (setq String
    (strcat
     strReplc
     (if (<= (1+ (+ Pos (strlen strTest))) (strlen String))
      (substr String (1+ (+ Pos (strlen strTest))))
      ""
     )
    )
   )
   (setq String
    (strcat
     (substr String 1 Pos)
     strReplc
     (if (<= (1+ (+ Pos (strlen strTest))) (strlen String))
      (substr String (1+ (+ Pos (strlen strTest))))
      ""
     )
    )
   )
  )
  (setq Pos (+ Pos (strlen strReplc)))
 )
)
(if MtextObj
 (progn
  (setq Pos 1)
  (setq FormatList '("A" "Q" "T" "S" "H" "F" "C"))
  (setq IsFormat 0)
  (while (<= Pos (strlen String))
   (setq strTemp (substr String 1 1))
   (cond
    ((= strTemp "\\")
     (if (vl-position (substr String (1+ Pos) 1) FormatList)
      (setq IsFormat (1+ IsFormat))
     )
     (setq Pos (1+ Pos))
    )
    ((= strTemp ";")
     (if (equal IsFormat 0)
      (progn
       (if (equal Pos 1)
        (setq String
         (strcat
          "\\U+00B1"
          (if (<= 2 (strlen String))
           (substr String 2)
           ""
          )
         )
        )
        (setq String
         (strcat
          (substr String 1 (1- Pos))
          "\\U+00B1"
          (if (<= (1+ Pos) (strlen String))
           (substr String (1+ Pos))
           ""
          )
         )
        )
       )
       (setq Pos (+ Pos 7))
      )
      (progn
       (setq IsFormat (1- IsFormat))
       (setq Pos (1+ Pos))
      )
     )
    )
    (T (setq Pos (1+ Pos)))
   )
  )
 )
)
String
)
;---------------------------------------------------------------------------------------
(setq BlkCol (vla-get-Blocks Doc))
(vlax-for Lo (vla-get-Layouts Doc)
 (vlax-for Obj (vla-get-Block Lo)
  (setq tempObjType (vla-get-ObjectName Obj))
  (cond
   ((vl-position tempObjType '("AcDbText" "AcDbAttributeDefinition"))
    (vla-put-TextString Obj (ReplaceString (vla-get-TextString Obj) DtextReplcList nil))
   )
   ((= tempObjType "AcDbMText")
    (vla-put-TextString Obj (ReplaceString (vla-get-TextString Obj) MtextReplcList T))
   )
   ((wcmatch tempObjType "AcDb*Dimension")
    (vlax-for tempObj (vla-Item BlkCol (cdr (assoc 2 (entget (vlax-vla-object->ename Obj)))))
     (if (= (vla-get-ObjectName tempObj) "AcDbMText")
      (vla-put-TextString tempObj (ReplaceString (vla-get-TextString tempObj) MtextReplcList T))
     )
    )
   )
   ((= tempObjType "AcDbBlockReference")
    (foreach Att (vlax-invoke Obj 'GetAttributes)
     (vla-put-TextString Att (ReplaceString (vla-get-TextString Att) DtextReplcList nil))
    )
    (foreach Att (vlax-invoke Obj 'GetAttributes)
     (vla-put-TextString Att (ReplaceString (vla-get-TextString Att) DtextReplcList nil))
    )
   )
   ((= tempObjType "AcDbTable")
    (setq ColCnt 0)
    (repeat (vla-get-Columns Obj)
     (setq RowCnt 0)
     (repeat (vla-get-Rows Obj)
      (vla-SetText Obj (ReplaceString (vla-GetText Obj RowCnt ColCnt) DtextReplcList nil))
      (setq RowCnt (1+ RowCnt))
     )
     (setq ColCnt (1+ ColCnt))
    )
   )
  )
 )
)
)
;------------------------------------------------------------------------
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq DtextList
 (list
  (cons "^" "\\U+00B0")
  (cons ";" "\\U+00B1")
  (cons "_" "\\U+06F8") ;; Doesn't like new string
  (cons "|" "\\U+00BC")
  (cons "{" "\\U+215C")
  (cons "\\" "\\U+00BD")
  (cons "}" "\\U+215D")
  (cons "[" "\\U+00BE")
  (cons "]" "\\U+215E")
  (cons "~" "%%C")
  (cons "<" "\\U+2104") ;; Doesn't like new string
  (cons ">" "\\U+214A") ;; Doesn't like new string
 )
)
(setq MtextList
 (list
  (cons "^" "\\U+00B0")
  (cons "_" "\\U+06F8") ;; Doesn't like new string
  (cons "|" "\\U+00BC")
  (cons "\\{" "\\U+215C")
  (cons "\\\\" "\\U+00BD")
  (cons "\\}" "\\U+215D")
  (cons "[" "\\U+00BE")
  (cons "]" "\\U+215E")
  (cons "~" "%%C")
  (cons "<" "\\U+2104") ;; Doesn't like new string
  (cons ">" "\\U+214A") ;; Doesn't like new string
 )
)
(ReplaceAllStrings ActDoc MtextList DtextList)
(princ)
)

Edit:  Updated code.  I knew I had a better version, just coudn't find it before.
« Last Edit: January 30, 2007, 11:16:47 AM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find & Replace Script - Quick Question
« Reply #17 on: January 29, 2007, 06:58:08 PM »
Great Tim, thanks.
Waiting to see how Mike did before I go any further.
Work is pressing me. :-(
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

M-dub

  • Guest
Re: Find & Replace Script - Quick Question
« Reply #18 on: January 30, 2007, 01:42:41 PM »
I'm just getting into it now!   :x

Man, I hate it when work gets in the way of work... and other things.  :)

M-dub

  • Guest
Re: Find & Replace Script - Quick Question
« Reply #19 on: January 30, 2007, 01:49:36 PM »
I'm just getting into it now!   :x

Man, I hate it when work gets in the way of work... and other things.  :)

Scratch that... Work just got in the way again!!!

whdjr

  • Guest
Re: Find & Replace Script - Quick Question
« Reply #20 on: January 31, 2007, 09:54:18 AM »
I have a lisp from Will Deloach that does that for all files in a directory using ObjectDBX. (Very Fast)
It would have to be modified to accommodate all the text you want to change as it was set up
to change only one text string. I tried to find the old code in the swamp but have had no luck
linking you to it.


I think this is the link you were talking about.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find & Replace Script - Quick Question
« Reply #21 on: January 31, 2007, 09:58:33 AM »
Yes, that's it. Thanks Will. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find & Replace Script - Quick Question
« Reply #22 on: February 05, 2007, 11:30:00 AM »
Mike, did this ever happen? Or still pending?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

M-dub

  • Guest
Re: Find & Replace Script - Quick Question
« Reply #23 on: February 05, 2007, 11:43:31 AM »
:oops: :cry:

Still pending.  I just have to wait until that boss comes in and tells me that his job takes precident over everyone else's work.  Just know that your work was not done in vain.  I WILL be getting to it.  It's just that these construction packages are more important to get out than that As Built package.

At the time I started this thread, I was in fact, on that job, but then things came up and well... I'm sure you've been in similar situations in the past...

:roll:

M-dub

  • Guest
Re: Find & Replace Script - Quick Question
« Reply #24 on: February 19, 2007, 11:31:11 AM »
Ok, I am FINALLY getting to this, but it's for a job other than the one that prompted this thread.  (if that made any sense... ? )

The error I get is "Error: Automation Error. Problem in loading application"

I run TEXTREPLACE, go select my (testing) folder and click on Save and that's what I get.  Suggestions?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find & Replace Script - Quick Question
« Reply #25 on: February 19, 2007, 12:18:55 PM »
Do you mean you run TextReplaceDBX
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

M-dub

  • Guest
Re: Find & Replace Script - Quick Question
« Reply #26 on: February 19, 2007, 12:26:43 PM »
:oops:

Nope.  I mean, I loaded and ran TextReplace.lsp and received that error.

(bear in mind that I'm a coding idiot)

What was my mistake?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Find & Replace Script - Quick Question
« Reply #27 on: February 19, 2007, 12:29:53 PM »
Sorry for the confusion I created.
Enter this at the command line once it is loaded:
TextReplaceDBX
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

M-dub

  • Guest
Re: Find & Replace Script - Quick Question
« Reply #28 on: February 19, 2007, 12:33:30 PM »
Sorry for the confusion I created.
Enter this at the command line once it is loaded:
TextReplaceDBX
Once TextReplace.LSP is loaded, right?

(Just want to make sure)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Find & Replace Script - Quick Question
« Reply #29 on: February 19, 2007, 12:35:27 PM »
Sorry for the confusion I created.
Enter this at the command line once it is loaded:
TextReplaceDBX
Once TextReplace.LSP is loaded, right?

(Just want to make sure)
Yes.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.