Jump to content

Find and Replace Script


Watson

Recommended Posts

Hello,

 

The Project Managers in my company are running AutoCAD LT 2009.

 

Our company uses a generic project template with the following fields:

 

01AREA 1

01REP 1

01DEALER 1

01BY 1

01DATE 1

01PM 1

01DWG 1

 

We use the “FIND” command to replace the generic info with the project specifics, for example, we would FIND “01DATE 1” and replace that with “4/20/09”. This can be a bit tedious, so what I would like is a script to cut down on some of the clicks. Ideally it would run so that the first field would pop up, I’d fill in the appropriate info in the command line then hit the space bar, the next field would pop up, etc, etc…

 

I’ve been looking into this ever since we went to 2009 and have been unable to work something out. PLEASE KEEP IN MIND I AM RUNNING LT.

 

If anyone has a way to do this please let me know.

 

Thanks.

Link to comment
Share on other sites

  • Replies 47
  • Created
  • Last Reply

Top Posters In This Topic

  • Watson

    21

  • Lee Mac

    14

  • Freerefill

    11

  • Hardeight

    1

I don't think it's possible to run the "find" command in the command line only. Which would be what you would really need if you were using it in a script. Plus, and I am no script expert, but I don't believe you would have a way to input information while it is running. This could easily be written in Lisp, but I know the pains you are going through with running LT. You would save yourself a lot of headaches and time by looking into an LT extender of some sort.

Link to comment
Share on other sites

I don't think it's possible to run the "find" command in the command line only. Which would be what you would really need if you were using it in a script. Plus, and I am no script expert, but I don't believe you would have a way to input information while it is running. This could easily be written in Lisp, but I know the pains you are going through with running LT. You would save yourself a lot of headaches and time by looking into an LT extender of some sort.

 

That's what I was afraid of... we've been scratching our heads trying to find a work around.

 

Hmmm.... "LT extender", eh?

 

Thanks.

Link to comment
Share on other sites

A quick Find and Replace LISP - only written on the fly (case-sensitive):

 

(defun c:fnr  (/ tStr ss)

 (while (or (eq "" (setq tStr (getstring t "\nSpecify Text to Search For: ")))
            (not (setq ss (ssget "X" (list (cons 0 "*TEXT") (cons 1 tStr)))))
            (eq "" (setq rStr (getstring t "\nSpecify Replacement Text: "))))
   (princ "\n<!> No Text Specified or Nothing Found <!>"))

 (foreach eLst  (mapcar 'entget (mapcar 'cadr (ssnamex ss)))
   (entmod (subst (cons 1 rStr) (assoc 1 eLst) eLst)))
 (princ))

Link to comment
Share on other sites

A quick Find and Replace LISP - only written on the fly (case-sensitive):

 

(defun c:fnr  (/ tStr ss)

 (while (or (eq "" (setq tStr (getstring t "\nSpecify Text to Search For: ")))
            (not (setq ss (ssget "X" (list (cons 0 "*TEXT") (cons 1 tStr)))))
            (eq "" (setq rStr (getstring t "\nSpecify Replacement Text: "))))
   (princ "\n<!> No Text Specified or Nothing Found <!>"))

 (foreach eLst  (mapcar 'entget (mapcar 'cadr (ssnamex ss)))
   (entmod (subst (cons 1 rStr) (assoc 1 eLst) eLst)))
 (princ))

 

Ahhhh... if only I could run LISP :cry:

Link to comment
Share on other sites

I tried via the forum here a while ago to use Autocads find and replace passing it the variables but to no avail. The reason being that Autocad find&replace searches everywhere blocks text mtext etc

 

Re Lt extenders they work well I would questions the price v's say Intellicad which has lisp and VBA ready to go. I believe LT should have lisp in it out of the box.

Link to comment
Share on other sites

Okay, I give up. So a "Find and Replace" script won't work... how about something to do with -ATTEDIT?

 

How would I go about writing a script so the the fields from the OP would show up as defineable on the command line?

Link to comment
Share on other sites

What am I doing wrong here?

Command: -ATTEDIT
Edit attributes one at a time? [Yes/No] <Y>: N
Performing global editing of attribute values.
Edit only attributes visible on screen? [Yes/No] <Y>: N
Drawing must be regenerated afterwards.
Enter block name specification <*>: A$C49561ED3
Enter attribute tag specification <*>: AAAA
Enter attribute value specification <*>: 01AREA 1
1 attributes selected.
Enter string to change: 01AREA 1
Enter new string: \
Command: -ATTEDIT
Edit attributes one at a time? [Yes/No] <Y>: N
Performing global editing of attribute values.
Edit only attributes visible on screen? [Yes/No] <Y>: N
Drawing must be regenerated afterwards.
Enter block name specification <*>: A$C49561ED3
Enter attribute tag specification <*>: AAAA
Enter attribute value specification <*>: 01REP 1
1 attributes selected.
Enter string to change: 01REP 1
Enter new string: \

 

Instead of pausing where I have "\", it is naming my string "\". I want that field to be user definable. :(

Link to comment
Share on other sites

I'm actually testing it in an .SCR file, but yes that's the gist of it... except I'm trying to have it run to replace multiple attributes (01AREA 1 is the first of seven). The issue is that instead of pausing at the "\", CAD accepts that as the new name of the attribuite. I want it to pause so you can enter the new name, then hit enter and have it move on to the next, etc, etc...

Link to comment
Share on other sites

This is what it looks like in my .SRC file:

-ATTEDIT
N
N
A$C49561ED3
AAAA
01AREA 1
01AREA 1
\
-ATTEDIT
N
N
A$C49561ED3
AAAA
01REP 1
01REP 1
\

Link to comment
Share on other sites

No probs -

 

In my opinion, if you are doing this kind of repetitive task on a regular basis, the amount of money you spend on this task from day to day may well outweight the cost of full-blown AutoCAD or even an LT Extender.

 

Just a thought. :wink:

Link to comment
Share on other sites

A little convoluted, but hear me out.

 

.bat file.

 

Before I found a way to do it entirely using a script, I initially had LISP which created a .bat file and a .scr file. The .bat file would open a new instance of AutoCAD, opening a certain .dwg with it, and automatically run the .scr that was created.

 

Script files cannot accept user input.

LT means no LISP, which means (getstring) is out.

.bat files DO allow user input, and can write to a file.

 

Perhaps a .bat file that creates a script using user input, then runs it in a selected .dwg? I'm working on it now, but I have very little experience with .bat files.

 

*EDIT* Ok, some quick googling turned up some results.

 

Open a new text file (notepad, nothing but) and copy and paste this code. Save it as "something.bat", make SURE the filetype is set to "all files."

@echo off
set /p input1=Enter input 
echo -ATTEDIT N N A$C49561ED3 AAAA 01AREA 1 01AREA 1 %input1% > C:\SCRIPTY.SCR

 

After you save it, double-click on it. A command prompt should pop up asking you for input. Enter whatever you like, and end it by hitting "Enter." A new file will be created in your C:\ directory called "SCRIPTY.SCR".

 

So you've just created a script file with prompts for user input, at least one line. You should be able to write multiple lines and return characters.

 

Now, there is a way to open a .dwg and run a script file, but I think you want it to run in the drawing you have open. I'm not sure how to do that, but this is a start.

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