Jump to content

Recommended Posts

Posted

Hi There,

Would like some help on a small problem that i have. I am trying to do a batch 'Find and Replace' exercise on a batch of autocad drgs. ie i need a program of some sort that will open a drawing, find a series of text strings and replace them with another series text strings and then save and close the drg.

 

old text string could be say 537:00089 and new text string would be 537D:0032. There could be dozens/hundreds of numbers within a drg.

 

Any ideas?

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • drewd1508

    6

  • rkmcswain

    4

  • dbroada

    3

  • abzn

    3

Posted

it would be a relatively simple task for either LISP or VBA.

 

Are you saying you have a list of numbers to look for and whenever anyone of them is found it is replaced?

 

Will at least one of the numbers appear in every drawing or will it not occur in othes?

 

Will the number appear on their own or will they be part of a text string?

Posted
Hi There,

Would like some help on a small problem that i have. I am trying to do a batch 'Find and Replace' exercise on a batch of autocad drgs. ie i need a program of some sort that will open a drawing, find a series of text strings and replace them with another series text strings and then save and close the drg.

 

old text string could be say 537:00089 and new text string would be 537D:0032. There could be dozens/hundreds of numbers within a drg.

 

Any ideas?

 

ToolPac has a routine to do this. I have used it several times with success.

Posted

If you are using vb, then create a selection set of all text and/or mtext and then cycle through each one and then use the Replace method in vb.

Posted

Hi

 

I need to make it clear that it is not the same text change in 100 different drgs. it is up to 100 text changes within a single drg, ie 100 different text strings each text string being a different no. (Autocad 2007)

 

Cheers

Posted

It is possible. The code would just have to be written for your parameters. Still start with a selection of text, then cycle through and apply your test. What is it you want to change and how? (your if/then's)

Posted

I have series of schematic diagrams which have equipment shown on them ie valves/pumps etc. Next to each piece of equipment is a unique reference no eg '537:00989' inserted as dtext. This reference no has to be amended for each piece of equipment. I am trying to work out a quick way of identifying every ref no within a drg and then replacing each no with a new one.

Posted

are you asking for somebody to do it for you or are you looking for guidance on how to write a routine?

Posted

Im looking for guidance on how to write a routine as i have no autolisp/vba knowledge!

Posted
.. as i have no autolisp/vba knowledge!
probably leaves me out as I don't have time to do a good job.

 

Before you start coding write out what you need to do in psudo code. Something like...

 

 

create a lookup table of search text/replace text

get all text objects within drawing

step through each piece of text

if serch text is found, go to lookup table and replace

when all text has been searched save drawing

 

that can be expanded as you realise more steps are required

both VBA and LISP are suitable for this sort of task but they can't (easilly) be mixed.

Posted

Cheers Dbroada,

 

thanks for your help, the pseudo code you described is exactly the process we require. I think i have some people local to myself who are good at autolisp/vba. i will have a chat with them.

 

Cheers

  • 1 month later...
Posted

Here is a function that I wrote to be used in programs, but it can be run on the command line using the following syntax:

(FindReplaceAll "537:00089" "537D:0032")

Use it with care, because it does exactly what it's named.

Terry Cadd

;-------------------------------------------------------------------------------
; FindReplaceAll - Changes Text, Mtext, Dimensions and Attribute Block entities
; that have a Find$ string with a Replace$ string.
; Arguments: 2
;   Find$ = Phrase string to find
;   Replace$ = Phrase to replace it with
; Syntax: (FindReplaceAll "old string" "new string")
; Returns: Updates Text, Mtext, Dimension and Attribute Block entities
;-------------------------------------------------------------------------------
(defun FindReplaceAll (Find$ Replace$ / BlkEntList@ BlkEntName^ BlkEntType$ Cnt#
 DimEntList@ DimEntName^ DimEntType$ EntList@ EntName^ EntType$ FindReplace:
 Mid$ Mid2$ NewText$ Num# Replace$ SS& Text$)
 ;-----------------------------------------------------------------------------
 ; FindReplace: - Returns Str$ with Find$ changed to Replace$
 ; Arguments: 3
 ;   Str$ = Text string
 ;   Find$ = Phrase string to find
 ;   Replace$ = Phrase to replace Find$ with
 ; Returns: Returns Str$ with Find$ changed to Replace$
 ;-----------------------------------------------------------------------------
 (defun FindReplace: (Str$ Find$ Replace$ / Cnt# FindLen# Loop Mid$ NewStr$ ReplaceLen#)
   (setq Loop t Cnt# 1 NewStr$ Str$ FindLen# (strlen Find$) ReplaceLen# (strlen Replace$))
   (while Loop
     (setq Mid$ (substr NewStr$ Cnt# FindLen#))
     (if (= Mid$ Find$)
       (setq NewStr$ (strcat (substr NewStr$ 1 (1- Cnt#)) Replace$ (substr NewStr$ (+ Cnt# FindLen#)))
             Cnt# (+ Cnt# ReplaceLen#)
       );setq
       (setq Cnt# (1+ Cnt#))
     );if
     (if (= Mid$ "") (setq Loop nil))
   );while
   NewStr$
 );defun FindReplace:
 ;-----------------------------------------------------------------------------
 ; Start of Main function
 ;-----------------------------------------------------------------------------
 (if (and (= (type Find$) 'STR)(= (type Replace$) 'STR)(/= Find$ ""))
   (progn
     (if (setq SS& (ssget "x" (list '(-4 . "<AND")'(-4 . "<OR")'(0 . "TEXT")'(0 . "MTEXT")'(0 . "DIMENSION")'(0 . "INSERT")'(-4 . "OR>")(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
       (progn
         (command "UNDO" "BEGIN")
         (setq Cnt# 0)
         (repeat (sslength SS&)
           (setq EntName^ (ssname SS& Cnt#)
                 EntList@ (entget EntName^)
                 EntType$ (cdr (assoc 0 EntList@))
                 Text$ (cdr (assoc 1 EntList@))
           );setq
           (if (= EntType$ "INSERT")
             (if (assoc 66 EntList@)
               (progn
                 (while (/= (cdr (assoc 0 EntList@)) "SEQEND")
                   (setq EntList@ (entget EntName^))
                   (if (= (cdr (assoc 0 EntList@)) "ATTRIB")
                     (progn
                       (setq Text$ (cdr (assoc 1 EntList@)))
                       (if (wcmatch Text$ (strcat "*" Find$ "*"))
                         (progn
                           (setq ReplaceWith$ (FindReplace: Text$ Find$ Replace$))
                           (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                           (entupd EntName^)
                         );progn
                       );if
                     );progn
                   );if
                   (setq EntName^ (entnext EntName^))
                 );while
               );progn
             );if
             (if (wcmatch Text$ (strcat "*" Find$ "*"))
               (progn
                 (setq ReplaceWith$ (FindReplace: Text$ Find$ Replace$))
                 (entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
                 (entupd EntName^)
               );progn
             );if
           );if
           (setq Cnt# (1+ Cnt#))
         );repeat
         (command "UNDO" "END")
       );progn
     );if
   );progn
 );if
 (princ)
);defun FindReplaceAll

Posted

Hi Terry,

 

Thanks for your info, as i am not autolisp educated. How do i run this file. Do i have to copy the lisp file contents and save it somewhere in my c drive. I have tried the syntax but it does not recignize the commands on the command line.

 

Cheers Drew

  • 2 years later...
Posted

Hi! Can somebody advice how to add multiline attributes to the processing by application (it is working only with single line attribute). Thank you

Posted

 

Clicking on the link you posted produces this message:

 

paulmcz, you do not have permission to access this page. This could be due to one of several reasons:

 

1. Your user account may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?

2. If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

 

Why?

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