Jump to content

Lsp For find and replace the text with Excel (Or .txt file) input file


suryatry26

Recommended Posts

Have any idea about find and replace the text with Excel (Or .txt file) input file Please see below.

 

Am using Autocad 2014.

 

I have clear data for Existing Text & Replacing text content. Please see below.

 

1000Amp (Existing Text in Cad File) Need to Change As 750Amp

500Amp (Existing Text in Cad File) Need to Change As 200Amp

2500Amp (Existing Text in Cad File) Need to Change As 150Amp

 

Like this i have nearly 100 text need to change.

 

So each time find and replacement its taking more time. So if i have this option with excel or txt file means its too easy for more text updating.

Link to comment
Share on other sites

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • Tharwat

    12

  • suryatry26

    10

  • BIGAL

    3

  • djkenmm

    3

I have the input file with excel format..

 

Here I try to upload.. But I cant able to upload the Excel (Txt file also). Its continually processing while try to upload... File size just 200KB.

 

Have 2 Columns in Excel File

 

One is Actual Text

 

Another One is Need to Change As..

 

This Changes need to be in Cad File .

Link to comment
Share on other sites

The first column obtain the text string that to be searched for and the second column would obtain the new replaced text string ?

 

Upload a snapshot as long as you can't upload the file itself .

 

I need to see a few lines starts from the top of the file to write a routine in one shot .

Link to comment
Share on other sites

I tried to upload snapshot... But No Use..

 

The first column obtain the text string that to be searched for and the second column would obtain the new replaced text string ?

 

Yes You are right. If First Column 1000Amp mentioned means its should find 1000Amp and need to replace this data with Column 2 (Ex :250Amp) Text Content..

Link to comment
Share on other sites

Try this program that I honestly did not test it , so let me know how you get on with it .

 

NOTE: Your Excel file should be with the extension of CSV to be able to select the file .

 

(defun c:Test (/ *error* fl on _parse:strings st l sel i sn e f)
;;;    Author: Tharwat . 24.02.2015    ;;;
;;;    ----------------------------    ;;;
 (defun *error* (msg)
   (if on
     (close on)
   )
   (if (not
         (and msg (wcmatch (strcase msg) "*CANCEL*,*EXIT*,*BREAK*"))
       )
     (princ "\n** Error Found :" msg " !! **")
   )
   (princ)
 )
 (if (and (setq fl (getfiled "Select Excel file :"
                             (getvar 'dwgprefix)
                             "csv"
                             16
                   )
          )
          (setq on (open fl "r"))
     )
   (progn
     (defun _parse:strings (string delimiter / pos lst)
;;; Parse a string to a list of strings    ;;;
;;; as per the delimiter        ;;;
       (while (setq pos (vl-string-search delimiter string 0))
         (progn (setq lst (cons (substr string 1 pos) lst))
                (setq string (substr string (+ pos 2) (strlen string)))
         )
       )
       (if (and string (/= string ""))
         (setq lst (cons string lst))
       )
       (setq lst (reverse lst))
     )
     (while (setq st (read-line on))
       (setq l (cons (_parse:strings st ";") l))
     )
     (if (setq sel
                (ssget
                  "_X"
                  (list '(0 . "TEXT")
                        (cons 1
                              (apply 'strcat
                                     (mapcar '(lambda (s) (strcat s ","))
                                             (mapcar 'car l)
                                     )
                              )
                        )
                  )
                )
         )
       (repeat (setq i (sslength sel))
         (setq sn (ssname sel (setq i (1- i)))
               e  (entget sn)
         )
         (if (and (setq f (assoc (cdr (assoc 1 e)) l))
                  (vlax-write-enabled-p (vlax-ename->vla-object sn))
             )
           (entmod (subst (cons 1 (cadr f)) (assoc 1 e) e))
         )
       )
     )
     (close on)
   )
 )
 (princ)
)(vl-load-com)

Link to comment
Share on other sites

Tharwat I tried but there is no action done..in Csv I have to mentione with 2 data's? 1 is Existing Text Content & another one is Which Text Content need to replace?

 

Ebrown I already tried that BFindV2-0.lsp from Lee's web site . Using that one we cant upload the excel data's.

Link to comment
Share on other sites

I think BFindV2-0.lsp from Lee's web site would do the trick.

 

Thank you for the recommendation! :)

 

Ebrown I already tried that BFindV2-0.lsp from Lee's web site . Using that one we cant upload the excel data's.

 

There is a workaround for importing find/replace items, described here:

 

http://www.cadtutor.net/forum/showthread.php?46135-Batch-Find-amp-Replace-Text&p=537625&viewfull=1#post537625

Link to comment
Share on other sites

Tharwat Please see below. After load Lsp Simply I loaded this Csv. But there is no Action.

 

A Column-B Column

1000Amp - 750Amp

500Amp - 200Amp

250Amp - 150Amp

1500Amp - 275Amp

Link to comment
Share on other sites

Tharwat Please see below. After load Lsp Simply I loaded this Csv. But there is no Action.

 

*- Were you able to select the Excel file with the extension CSV ?

*- You after to replace a SINGLE text objects or MTEXT text objects ?

*- Are there any of these text strings is a part of long text or separate objects to be replaced ?

Link to comment
Share on other sites

Were you able to select the Excel file with the extension CSV ?

I have the input with excel file.. then i save as to Csv Format. Then i have loaded while its asking load the Csv file.

 

You after to replace a SINGLE text objects or MTEXT text objects ?

I tried with Mtext and Text both.

 

Are there any of these text strings is a part of long text or separate objects to be replaced ?

Its a Separate Text (& Mtext)

 

After run the Lsp there is no Action on Cad File.

Link to comment
Share on other sites

Its Working Superb. Thanks a Lot..It Wont Work With MTEXT??? Possible to Include MTEXT?

 

Finally you got it working ! good for you ;)

You can add the Mtext objects , just add the following part as shown in red color .

 

'(0 . "TEXT[color=red],MTEXT[/color]")

Link to comment
Share on other sites

Its working fine now...Thanks a lot. Its not considering Space Text Like "BATTERY BANK".

 

BATTERY BANK-01 Need To Change As BATTERY BANK-02 means what can I do?

Link to comment
Share on other sites

Its not considering Space Text Like "BATTERY BANK".

 

BATTERY BANK-01 Need To Change As BATTERY BANK-02 means what can I do?

 

Nothing special in the program , just add as much as you want in the excel file (first column obtain the text string to search for then the second column obtain the text string to be replace )

 

But if you want to increment the value , that is NOT possible with this program . That's it .

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