PDA

View Full Version : Batch/Script automation of Autocad



jason.145418
2007-08-18, 01:31 AM
Here is the scenario...
I have a directory with many drawings. Autocad dwg files are being updated and added to this directory all the time. I would like to completely automate the following task: open all files one at a time, run the command "overkill" on each, save then exit. I would like the entire task to run unattended at night. I also do not want to select the drawings in the directory manually.

I have created a batch command that will open each drawing within the directory one at at time but I do not know how to run overkill command once a drawing has been opened.

I have also created a working script file that runs overkill, saves then exits but I do not know how to run this script from the batch file or send the command to Autocad after the drawing has been opened.

Does anyone have any thoughts?

Thanks,

Jason

rkmcswain
2007-08-18, 02:32 AM
There are many scripting programs out there.

Autodesk has a free one called ScriptPro
http://www.autodesk.com/migrationtools

Not sure about getting this to just up and run by itself in the middle of the night. It may need a human to kick it off. Let us know what you find....

devitg.89838
2007-08-20, 04:55 AM
Here is the scenario...
I have a directory with many drawings. Autocad dwg files are being updated and added to this directory all the time. I would like to completely automate the following task: open all files one at a time, run the command "overkill" on each, save then exit. I would like the entire task to run unattended at night. I also do not want to select the drawings in the directory manually.

I have created a batch command that will open each drawing within the directory one at at time but I do not know how to run overkill command once a drawing has been opened.

I have also created a working script file that runs overkill, saves then exits but I do not know how to run this script from the batch file or send the command to Autocad after the drawing has been opened.

Does anyone have any thoughts?

Thanks,

Jason


Give this a try , you will need to check and add the OVERKILL options .

jason.145418
2007-08-20, 02:52 PM
rkmcswain: Thanks for the suggestions so far...
I did try scriptpro and it does most of what I would like to accomplish but as you mentioned, needs some maual input. It requries me to add drawings that I would like to perform my actions on. I would like this list of drawings to update automatically.

devitg.89838: Thanks for the lisp routine. I had a quick look at the code and I must say that it is a bit over my head, being a newbie. I assume the command is manually innitiated within autocad, will open each file and perform an overkill task.

Do you know a way to initiate this lisp routine after an autocad file has been opened from an external command and not within the autocad interface? (ie so that it does not require manual user input) Ideally I would want to "send" the command from a batch file, telling autocad that now that it has a drawing open to perform an overkill.


Thanks,

Jason

devitg.89838
2007-08-20, 04:22 PM
Do you know a way to initiate this lisp routine after an autocad file has been opened from an external command and not within the autocad interface? (ie so that it does not require manual user input) Ideally I would want to "send" the command from a batch file, telling autocad that now that it has a drawing open to perform an overkill.


Thanks,

Jason

This lisp will do a batch by it self.
Hi Jackson, did you have the overkill options set to your´s need ?

Why do you want to SEND a command from a batch file , are you working from the DOS command ?

A lisp will run from a acad dwg , this one could run from a new empty dwg.

A way to get the lisp to be autoload is to add it to the acad200xdoc.lsp ,

jason.145418
2007-08-21, 05:35 PM
I would like Autocad to run without any user input from a scheduled routine. I have a *.bat file that starts autocad and open files in a folder...

chdir c:\ptc\ilinktrail
dir /B /S *.dwg > list_dwg.txt

for /f "delims=" %%f in (list_dwg.txt) do (
%startw% "C:\PTC\Ilinktrail\run_acad" "%%f"
)

Once autocad is open I want ot run the following *.scr file

ZOOM
Extents
overkill
all
scr-saveas-2000
scr-quit

I do not want to have to manually start Autocad or have manual inputs once autocad opens a file.

Is there a way to get the acaddoc.lsp to open a script file once a drawing file has been opened?

Thanks

jason

kennet.sjoberg
2007-08-21, 06:26 PM
You can use this LINK (http://forums.augi.com/showthread.php?t=14243#post88722) to make a script file and batch run everything in a directory.

: ) Happy Computing !

kennet

devitg.89838
2007-08-21, 08:36 PM
Only acad200xdoc.lsp will run a lisp , yes it is possible to autorun a lisp from acad200xdoc.lsp
In such lisp you have to state where the dwg are .

What acad you will use to run it.??

RobertB
2007-08-21, 09:22 PM
Only acad200xdoc.lsp ...DON'T modify/use Acad200xDoc.lsp. That is for Autodesk's use only. AcadDoc.lsp is for user modification. If the file doesn't exist in your search path, simple create it. DO NOT modify Acad200x.lsp or Acad200xDoc.lsp.

jason.145418
2007-08-22, 12:53 PM
Using the acaddoc.lsp works, I will use this file to atuload a lsp routine on drawing startup.

Kennet: I have tried to run your lsp but it stalls on the open file name. Perhaps it has something to do with acad2007?

Does anyone have a lisp routine that will run the "run script" command? So that when I start a document it will call up my script file.

jason.145418
2007-08-22, 04:26 PM
The long way I guess!!!


Batch File - to gather all dwg files in C:\PTC\Ilinktrail\ and open acad for each file.
CHDIR C:\PTC\Ilinktrail\
dir /B /S *.dwg > list_dwg.txt
for /f "delims=" %%f in (list_dwg.txt) do (%startw% "C:\Program Files\AutoCAD 2007\acad.exe" "%%f")

set sytstem variable: ACADLSPASDOC = 1

added entry to acad.lsp: (load "aiolosoverkill" '("batchoverkill"))

which calls up my aiolosoverkill.lsp file containing:
defun c:batchoverkill
Command: (Command "script" "aiolosoverkill.scr")

which runs my aiolosoverkill.scr containing:
ZOOM
Extents
overkill
all
qsave
quit

Note: the script file is the only file located in C:\PTC\Ilinktrail\ the rest are in the support dir of Autocad2007

Thanks to everyone for their help,

Jason

RobertB
2007-08-22, 05:04 PM
set sytstem variable: ACADLSPASDOC = 1
DON'T! Use AcadDoc.lsp to store code that needs to execute for each drawing. Leave Acad.lsp to store code that only needs to load when AutoCAD first starts. AcadLspAsDoc is a legacy item for people too lazy to copy Acad.lsp to AcadDoc.lsp.

rkmcswain
2007-08-22, 05:04 PM
set sytstem variable: ACADLSPASDOC = 1
added entry to acad.lsp:


Did I miss something...?

Why use "acad.lsp" and set ACADLSPASDOC to 1 instead of just using "acaddoc.lsp"?

Terry Cadd
2007-08-22, 11:51 PM
Here's a Script Creator that runs your script on a drawing or drawings in a folder.
You edit it on the fly as required, and may also just test it in the current drawing,
before you run it on a folder of drawings.

http://web2.airmail.net/terrycad/Other/Scrs.jpg

jason.145418
2007-08-24, 12:05 AM
Strangely enough I tried to put my code into the acaddoc.lsp and it did not work! In the end I kept it where it ran the commands. However, I do appreciate the concern and will try again to get acaddoc.lsp to work.

Terry Cadd: Nice utility, I am gonna give it a try...wish you posted a week ago! Though I did learn some neat tricks from other forum contributors.

Cheers

rkmcswain
2007-08-24, 01:56 AM
Strangely enough I tried to put my code into the acaddoc.lsp and it did not work! In the end I kept it where it ran the commands. However, I do appreciate the concern and will try again to get acaddoc.lsp to work.

Check these things out:

1. In AutoCAD, type in (findfile "acaddoc.lsp") and see if it returns the same file that you created/edited.

2. If #1 checks out OK, then type this in (load "acaddoc"). Do you get errors?

3. If you are not sure about #2, then open this file and at the very bottom of the file add the following (princ "\nMy special acaddoc.lsp loaded")(princ)

4. Repeat step 2 and make sure the message "My special acaddoc.lsp loaded" gets echoed to the command line when you load "acaddoc.lsp"

Let us know the results.

devitg.89838
2007-08-24, 10:41 AM
Hi Robert , I had used acad200x.lsp forever , what is the cons of do it?
jason here it is a part of a lisp that automake a script and run it , the author is Fatty



(progn
(setq DwgList (vl-directory-files DirPath "*.dwg" 1))
(setq ScrFile (strcat DirPath "batchrename.scr"))
(setq Ofil (open ScrFile "W"))
(write-line "SDI 0" Ofil); Force Multi-Document mode
(write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 0)") Ofil)
(write-line (strcat "(setvar " (chr 34) "CMDECHO" (chr 34) " 0)") Ofil)
(foreach Dwg DwgList
(setq FullPath (strcat DirPath Dwg))
(write-line (strcat "_.open " (chr 34) FullPath (chr 34)) Ofil)
(write-line (strcat "(load " (chr 34) my_lisp_file (chr 34) ")") Ofil)
(write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)") Ofil)
(write-line "_.qsave" Ofil)
(write-line "_.close" Ofil)
(write-line "_Y" Ofil)
); foreach
(write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)") Ofil)
(write-line (strcat "(setvar " (chr 34) "CMDECHO" (chr 34) " 1)") Ofil)
(close Ofil)
(command "_.script" ScrFile)
); progn

rkmcswain
2007-08-24, 12:29 PM
Hi Robert , I had used acad200x.lsp forever , what is the cons of do it?

* It's "owned" by AutoCAD, so it's subject to being overwritten while running a repair or reinstall.
* It's contents are not migrated when upgrading.

devitg.89838
2007-08-24, 01:21 PM
Hi RK , I did what you say , tear off all my lisp from acad2006.lsp , and add to new acaddoc.lsp

It work nice , for the moment.

RobertB
2007-08-27, 05:55 PM
Hi Robert , I had used acad200x.lsp forever , what is the cons of do it?Please see TS21336 (http://usa.autodesk.com/adsk/servlet/ps/item?siteID=123112&id=2897258&linkID=9240617) on Autodesk's website.

devitg.89838
2007-08-27, 06:40 PM
Please see TS21336 (http://usa.autodesk.com/adsk/servlet/ps/item?siteID=123112&id=2897258&linkID=9240617) on Autodesk's website.

Thanks I just understand .

tedg
2011-07-25, 06:55 PM
Here's a Script Creator that runs your script on a drawing or drawings in a folder.
You edit it on the fly as required, and may also just test it in the current drawing,
before you run it on a folder of drawings.
.....

That's pretty sweet Terry!
I just did a bat/scr/lsp method on a bunch of drawings to clean up, purge and e-transmit, but your program doesn't require starting AutoCAD everytime.

Here's what mine looked like:
RECORD.BAT

FOR %%f in (T:\5053301\Sheets\"BUILDING"\*.dwg) do start /wait C:\"Program Files"\Autodesk\"AutoCAD Structural Detailing 2011"\acad.exe "%%f" /b "C:\lisp\RECORD\RECORD.scr"
RECORD.SCR

(load "C:\\lisp\\record\\record.lsp")
deleterev
adupurge
-etransmit
choose
RECORD
C
A
quit
y
And RECORD.LSP

;;deletes the layer G-ANNO-REVN and everything on it!
(defun c:deleterev (/ lr1)
(command "layer" "s" "0" "")
(setq lr1 (tblsearch "layer" "G-ANNO-REVN"))
(setq lr2 (tblsearch "layer" "G-ANNO-REVS"))
(if (= lr1 nil)
(command "layer" "s" "0" "")
(command "-laydel" "name" "G-ANNO-REVN" "" "y"))
(if (= lr2 nil)
(command "layer" "s" "0" "")
(command "-laydel" "name" "G-ANNO-REVS" "" "y"))
(princ)
)
;;purge routine
(defun c:adupurge ()
(setq ce (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "layer" "s" "0" "")
(command "zoom" "e" "zoom" ".9x" )
(repeat 3
(command "._purge" "_A" "*" "_N")
(command "purge" "regapps" "" "n"))
(setvar "cmdecho" ce)
(command "_qsave")
(princ)
)

But all I needed to do was apply the script commands on your program and it took care of them all wile AutoCAD remained open...much faster!

Thanks.
:beer::beer::beer:

irneb
2011-07-26, 03:22 PM
Ted, just as a suggestion: You don't need to quote each foldername individually. You can quote the entire path in one go: "C:\Program Files\Autodesk\AutoCAD Structural Detailing 2011\acad.exe"

Oh! Edit ... that's what was generated?

tedg
2011-07-26, 04:58 PM
Ted, just as a suggestion: You don't need to quote each foldername individually. You can quote the entire path in one go: "C:\Program Files\Autodesk\AutoCAD Structural Detailing 2011\acad.exe"

Oh! Edit ... that's what was generated?
No I didn't know that, I will give it a try.
I can't remember why I needed to do that, maybe because the folder names with spaces?

Thanks I'll look into your suggestion.

mihsan
2013-02-13, 03:13 PM
I would like Autocad to run without any user input from a scheduled routine. I have a *.bat file that starts autocad and open files in a folder...

chdir c:\ptc\ilinktrail
dir /B /S *.dwg > list_dwg.txt

for /f "delims=" %%f in (list_dwg.txt) do (
%startw% "C:\PTC\Ilinktrail\run_acad" "%%f"
)

Once autocad is open I want ot run the following *.scr file

ZOOM
Extents
overkill
all
scr-saveas-2000
scr-quit

I do not want to have to manually start Autocad or have manual inputs once autocad opens a file.

Is there a way to get the acaddoc.lsp to open a script file once a drawing file has been opened?

Thanks

jason

Dear Jason,

Try this in your *.scr file

hope it will help.

regen
zoom
extents
-overkill
al


qsave
quit



Thank you,


Regards,


Asad

lowend15852362
2014-05-26, 07:23 PM
That's pretty sweet Terry!
I just did a bat/scr/lsp method on a bunch of drawings to clean up, purge and e-transmit, but your program doesn't require starting AutoCAD everytime.

Here's what mine looked like:
RECORD.BAT

FOR %%f in (T:\5053301\Sheets\"BUILDING"\*.dwg) do start /wait C:\"Program Files"\Autodesk\"AutoCAD Structural Detailing 2011"\acad.exe "%%f" /b "C:\lisp\RECORD\RECORD.scr"
RECORD.SCR

(load "C:\\lisp\\record\\record.lsp")
deleterev
adupurge
-etransmit
choose
RECORD
C
A
quit
y


Unless AutoCAD has changed from pre-2012 to 2012, I don't see how "y" accomplishes anything. Basically, by selecting "y" you are saying "quit without saving, yes". Am I missing something?

I had to use a "n" and it worked.