Jump to content

question about batch, lisp, script files


Recommended Posts

Posted

I have a compilation of .bat, .lsp, and .scr files to purge multiple drawings at one time. The problem that I have is that when it runs it opens autocad runs the routines and then closes. It then opens autocad again and does the process to the next drawing. Is there a way to perform these operations with autocad only opening once and going through all the drawings in the designated folder?

  • Replies 68
  • Created
  • Last Reply

Top Posters In This Topic

  • todouble22

    25

  • Lee Mac

    19

  • dbroada

    10

  • BIGAL

    4

Posted

another quick question.. #2 I've ran into problems when calling the .bat file or .lsp, or .scr from another file directory than that which the drawings are placed in. Do these all need to be in the same folder so that they run correctly?

Posted

I wrote our department a script generator that opens each drawing (path included in name) and adds the listed actions followed by a QSAVE and open the next drawing. Before that we created the file using the DOS DIR *.dwg /b > list.scr syntax and by carefully using FIND|REPLACE within excel.

 

Obviously, this doesn't answer either of your questions and is only posted to show how clever I am.

 

 

 

Oh, or could be used to think of other ways around what you are doing.

Posted
I wrote our department a script generator that opens each drawing (path included in name) and adds the listed actions followed by a QSAVE and open the next drawing. Before that we created the file using the DOS DIR *.dwg /b > list.scr syntax and by carefully using FIND|REPLACE within excel.

 

Obviously, this doesn't answer either of your questions and is only posted to show how clever I am.

 

 

 

Oh, or could be used to think of other ways around what you are doing.

clever indeed.. the wheels are turning..

Posted

Are you using MDI mode?

 

Also check your script for close or exit. You want to close the drawing not exit autocad.

Posted

oh yes, forgot to say I prefer to work in SDI mode. Some of my scripts create 1500 drawing files. I don't like the idea of having that files open in one go.

Posted
Are you using MDI mode?

 

Also check your script for close or exit. You want to close the drawing not exit autocad.

I have SDI = 0 ; which i'm pretty sure allows for opening of multiple drawings. Here is what I've done starting with the batch file calling the script which purges and then loads the lisp that updates the drawing to an "update" folder.

batch file:

MD C:\PURGED

for %%f in (P:\"ACTIVE PROJECTS"\"10573 - EE - NYSE - DATACENTER SUBSTATION"\DRAWINGS\"Working Drawings"\*.dwg) do start /wait C:\"Program Files"\Autodesk\"Acade 2008"\acad.exe "%%f" /b "P:\DOCUMENTS\purge.scr"

script file:

zoom

e

-purge

a

*

n

;THIS LOADS THE TBUPDATE LISP TO SAVE THE NEW DRAWINGS IN THE DESIGNATED UPDATE FOLDER AND UNCHANGING THE ORIGINAL

(load "C:\\TBUPDATE.LSP")

TBUPDATE

QUIT

Y

lisp file:

(defun C:TBUPDATE(/ dn pa panbdn)

(setq dn (getvar "dwgname"))

(setq pa (getvar "dwgprefix"))

(setq panbdn (strcat pa "PURGED\\" dn))

(command "SAVE" panbdn)

)

Posted
I have SDI = 0 ; which i'm pretty sure allows for opening of multiple drawings. Here is what I've done starting with the batch file calling the script which purges and then loads the lisp that updates the drawing to an "update" folder.

batch file:

MD C:\PURGED

for %%f in (P:\"ACTIVE PROJECTS"\"10573 - EE - NYSE - DATACENTER SUBSTATION"\DRAWINGS\"Working Drawings"\*.dwg) do start /wait C:\"Program Files"\Autodesk\"Acade 2008"\acad.exe "%%f" /b "P:\DOCUMENTS\purge.scr"

script file:

zoom

e

-purge

a

*

n

;THIS LOADS THE TBUPDATE LISP TO SAVE THE NEW DRAWINGS IN THE DESIGNATED UPDATE FOLDER AND UNCHANGING THE ORIGINAL

(load "C:\\TBUPDATE.LSP")

TBUPDATE

QUIT

Y

lisp file:

(defun C:TBUPDATE(/ dn pa panbdn)

(setq dn (getvar "dwgname"))

(setq pa (getvar "dwgprefix"))

(setq panbdn (strcat pa "PURGED\\" dn))

(command "SAVE" panbdn)

)

 

I think you want to change this to be CLOSE instead.

Posted
I think you want to change this to be CLOSE instead.

When I change it to close it runs and saves the updated folder but then it doesnt continue to the next drawings in the folder, is there a repeat command or something that I need to add into the batch file maybe? the way i had it before did it and left the originals unchanged and updated the drawings but opened autocad everytime. I'm just tryin to figure out if there is a way around that happening? The book that I'm referencing says that the quit command in a script results in a different prompt than it does when in autocad directly. the prompt for script version is REALLY want to discard all changes to drawing? , which requires the response y to quit without saving. I appreciate all your help Tim

Posted

I got caught by the swapping of the responses - have a search through this forum and you will find I have highlighted it several times.

 

I don't know if it would help you here but I end my scripts with RESUME. This is the command you can use to continue an interupted script. If you have a at the end of a script it repeats the last completed command, sometimes with unexpected results. Ending RESUME gets around this by looking for the next command. If the next command is a series of spaces it will keep resuming until all spaces are exhausted.

 

Also try your script in both SDI=0 and SDI=1 mode. You do get different results.

Posted
I got caught by the swapping of the responses - have a search through this forum and you will find I have highlighted it several times.

 

I don't know if it would help you here but I end my scripts with RESUME. This is the command you can use to continue an interupted script. If you have a at the end of a script it repeats the last completed command, sometimes with unexpected results. Ending RESUME gets around this by looking for the next command. If the next command is a series of spaces it will keep resuming until all spaces are exhausted.

 

Also try your script in both SDI=0 and SDI=1 mode. You do get different results.

swapping of responses?? what have you highlighted several times? I posted what I am using for all the files, I have tried it with different SDI modes , I'll try it with the resume workaround and give it a go. Thanks DBroada!

Posted

the swapping of "do you want to save changes" bit. Sorry, too much rum to make sense.

Posted

I wrote a LISP for batch processes, it'll take just about all comers and won't require a batch file, plus it writes its own scripts. Check my signature for the link.

Posted

The problem guys is your overlooking the simple answer it being run by a batch file !

 

A batch file runs outside autocad from the operating system command line once you start the loop the batch file opens a session of autocad and it expects you to close it as well, hence why quit works and not close.

 

The easier way is to stay inside autocad and use a script to loop through the drawings and yes use close not quit. We have done for 100+ drawings no problems.

 

A couple of extra real help full tips after you create your dir *.dwg >mydwgs.txt file use WORD to edit it, remove the junk till you get just filenames only use "hold alt key" and use mouse for vertical selection then delete, an unknown fact is that you can find/replace the end of line with something new uselly my script commands.

 

eg

mydwg1.dwg

mydwg2.dwg etc

 

find replace g^p with g zoom e domylisp^p

 

ie

mydwg1.dwg zoom e domylisp

mydwg2.dwg zoom e domylisp

also add blank line at top ^p replace ^oopen (space after n)

 

open mydwg1.dwg zoom e domylisp

open mydwg2.dwg zoom e domylisp

 

delete blank line

save as a script

 

Hope this helps. it only takes a couple of minutes to edit the dwg txt file.

Posted
The problem guys is your overlooking the simple answer it being run by a batch file !

 

A batch file runs outside autocad from the operating system command line once you start the loop the batch file opens a session of autocad and it expects you to close it as well, hence why quit works and not close.

 

The easier way is to stay inside autocad and use a script to loop through the drawings and yes use close not quit. We have done for 100+ drawings no problems.

 

A couple of extra real help full tips after you create your dir *.dwg >mydwgs.txt file use WORD to edit it, remove the junk till you get just filenames only use "hold alt key" and use mouse for vertical selection then delete, an unknown fact is that you can find/replace the end of line with something new uselly my script commands.

 

eg

mydwg1.dwg

mydwg2.dwg etc

 

find replace g^p with g zoom e domylisp^p

 

ie

mydwg1.dwg zoom e domylisp

mydwg2.dwg zoom e domylisp

also add blank line at top ^p replace ^oopen (space after n)

 

open mydwg1.dwg zoom e domylisp

open mydwg2.dwg zoom e domylisp

 

delete blank line

save as a script

 

Hope this helps. it only takes a couple of minutes to edit the dwg txt file.

You are correct that I would like to run this outside of autocad well as I stated before I have it open Autocad but as you say with the batch file it runs externally and in the program it quits and then restarts with the next drawing in the folder. I posted the code in this thread, maybe it would be helpful if I commented it as to what I was attempting to do? and bid al thanks for your help here but I guess I got a lil lost as to what you were explaining with your script file.

Posted
I wrote a LISP for batch processes, it'll take just about all comers and won't require a batch file, plus it writes its own scripts. Check my signature for the link.

is it a portion of the final blitz package?

Posted
A couple of extra real help full tips after you create your dir *.dwg >mydwgs.txt file use WORD to edit it, remove the junk till you get just filenames only use "hold alt key" and use mouse for vertical selection then delete, an unknown fact is that you can find/replace the end of line with something new uselly my script commands.

pretty much what I was trying to say but I prefer to construct my script using excel

 

just one note, if you use dir *.dwg > mydwgs.txt /b you will NOT get any of the junk, just the filenames. :)

Posted
pretty much what I was trying to say but I prefer to construct my script using excel

 

just one note, if you use dir *.dwg > mydwgs.txt /b you will NOT get any of the junk, just the filenames. :)

I write all my scripts in notepad? what are the benefits in doing it in excel? ..ssearching google now...

Posted

I would agree with BigAl on this one - is it mandatory that you run the script from outside of AutoCAD?

 

Why not just create a script file and run it from within ACAD?

 

You could even use a LISP to write the script for you :)

Posted
I would agree with BigAl on this one - is it mandatory that you run the script from outside of AutoCAD?

 

Why not just create a script file and run it from within ACAD?

 

You could even use a LISP to write the script for you :)

No its not mandatory at all I guess I was just playing around with what I knew the most. Basically what I want to do is be able to process multiple drawings by purging them to minimize file size before transmittal or even just to reduce the file size. The way that I have it it opens autocad, opens the drawing , runs the script to purge and then the lisp to save it with the same name in an "updated" folder. The problem is that it opens autocad for every drawing in the folder performs the task shuts down and goes on to the next. I am more than interested in doing a lisp for this and I am eager to learn.

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