Print Page | Close Window

Initialize Script Using Batch File

Printed From: CAD Forum
Category: EN
Forum Name: AutoCAD
Forum Description: Discussion about AutoCAD and AutoCAD LT, viewers, DWG and DWF formats, Design Review, AutoCAD 360, add-ons
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=10467
Printed Date: 31.May.2026 at 23:19


Topic: Initialize Script Using Batch File
Posted By: mfkozlow
Subject: Initialize Script Using Batch File
Date Posted: 17.Jul.2014 at 16:59
Hello All,

Does anyone know the batch file command to open a set of drawings (several .dwg files) and run a script on each individually using a batch file. I also do not want AutoCAD Electrical to keep closing and opening. I just want one instance of the program. I found this command, but it only works on one drawing at a time.

START \WAIT C:\"Program Files"\Autodesk\"AutoCAD 2014"\ACAD.EXE XXXXX.dwg" /b clean.scr

Here xxxxx.dwg is the drawing file in the same directory as the batch file and clean.scr is the script file in the same directory as the batch file.


I have also tried:

START \WAIT C:\"Program Files"\Autodesk\"AutoCAD 2014"\ACAD.EXE XXXXX.dwg" /b clean.scr
xxxxx1.dwg /b clean.scr

The above executes the script on the first drawing, but when it opens the next file (xxxxx1.dwg) it does not run the same script.

Ideally, I want AutoCAD to open one file, run the script, close it without closing AutoCAD. Then I want it to continue onto the next drawing and do the same thing again. Should I approach this problem in the the batch file or have the script open up another file.

NOTE*
I do not want to have to input the path of the drawing to open, it should automatically open all the drawings in the directory that the batch file is running in.

Thanks for all your help!

Best Regards,
mfkozlow.



Replies:
Posted By: John Connor
Date Posted: 17.Jul.2014 at 17:30
Maybe this program by Lee Mac might prove more useful.

http://lee-mac.com/scriptwriter.html


-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>



Posted By: mfkozlow
Date Posted: 18.Jul.2014 at 17:35
Although this is a pretty neat program, I am creating an automated system that requires almost zero user input. That being said, I really need a batch command that opens a .dwg file without opening a new instance of AutoCAD and runs a script located somewhere on the user's computer. Thanks for your fast reply.


Posted By: John Connor
Date Posted: 18.Jul.2014 at 17:40
You must have a system variable that is set wrong if multiple sessions are being opened.

Educate thyself.  Read this...

http://forums.autodesk.com/t5/AutoCAD-Electrical-General/sdi-mode/td-p/2705113


-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>



Posted By: mfkozlow
Date Posted: 18.Jul.2014 at 18:01
I am aware of this variable. I have it set to 0. The problem is not with AutoCAD, but Windows. I need a way to tell Windows to open the .dwg file with the script, but without having to specify the line below.

START /WAIT C:\"Program Files"\Autodesk\"AutoCAD 2014"\ACAD.EXE

Even if the variable SDI is set to 0, AutoCAD will open as many instances as Windows tells it to. So what I want to do is write the code above and then continue adding drawings into that instance of AutoCAD. The real trick is how do I tell it to run a specific script as each drawing is opened? And more importantly, how do I tell the batch file to wait until that script is finished? Thanks for your support.



Posted By: John Connor
Date Posted: 18.Jul.2014 at 18:27
Why is it a Windows problem?  You open AutoCAD first then you run the script not the other way around.


-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>



Posted By: mfkozlow
Date Posted: 18.Jul.2014 at 19:20
Yes, but I want the script to run automatically, i.e. no user input. I need Windows to tell AutoCAD to open the .dwg file then run the script. Then open another file and run another script, all within one instance of AutoCAD. All I want the user is to double click the batch file and everything will happen automatically from there. Is this making sense or am I not clear in my explanation? Below is a representation:

1. User clicks the batch file.
2. AutoCAD opens.
3. 1st .DWG file is opened and script runs.
4. File closes.
5. 2nd .DWG file opens with a different script.
6. File closes.
7. AutoCAD closes.

Thanks again!


Posted By: mfkozlow
Date Posted: 18.Jul.2014 at 19:58
The way I have it setup now is that my batch file (.bat) temporarily creates a script file in the same directory as the batch file. Then once AutoCAD is done using it, the script gets deleted. The problem I have is, how can I open a drawing without starting a new instance of ACAD.EXE? As you can imagine, the time it takes to open AutoCAD can be extensive and doing it twice in a row is completely pointless; especially if these tasks can be done with one instance of AutoCAD. Any suggestions?


Posted By: harrissjt
Date Posted: 28.Jan.2015 at 12:08
I have hundreds of Autocad 2012 drawings that I have to modify, each with the same minor changes.
The intention is to create Script files to automate each task, and a .BAT file to run the Scripts across multiple files in a given folder.
I created a Script file to ZOOM E, and then modify certain attributes within the drawing title block, which appears to work fine when run from within an open Autocad file at the command line.  However when trying to run it on multiple files using the .BAT file, it hangs with the following error;
"c."ACAD" Invalid file name.
 
Given that the Script runs fine, I assume that there must be an error in my .BAT file.
 
Please see both .BAT file and SCR below;
.BAT
FOR %%f in (c:\"ACAD Batch"\Drgs\*.dwg) do start /wait c:\"Program Files"\Autodesk\"AutoCAD 2012 - English"\acad.exe "%%f" /b c:\"ACAD Batch"\Scripts\"Change_Project_Title.scr"
 
Script
ZOOM E
;EDIT PROJECT REVISION
-ATTEDIT
N
N
A*-TITLE
REV_NO
*
A
0
;
;EDIT PROJECT TITLE-E
-ATTEDIT
N
N
A*-TITLE
TITLE1
*
TA2015 GC-201.1/2/3 CCC POWER SUPPLIES
TA2015 GC-201 CCC CONTROLLER UPGRADE
;
;EDIT PROJECT TITLE-R
-ATTEDIT
N
N
A*-TITLE
TITLE4
*
ЭЛЕКТРОПИТАНИЕ НА GC201.1/2/3 CCC КР2015
КР2015 GC-201 МОДЕРН-ЦИЯ КОНТРОЛЛЕРА ССС
QSAVE
QUIT
Y
 
I hope that someone out there can help, this has been driving me nuts all day!
 
Cheers,
Steve


Posted By: John Connor
Date Posted: 28.Jan.2015 at 15:53
Maybe it has to do with the direction of the slash(es) after C:?


-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>



Posted By: harrissjt
Date Posted: 29.Jan.2015 at 16:06
I finally cracked it.

After much messing around trying different things, I moved the quotation marks on the script file reference, and hey presto!

FOR %%f in (c:\"ACAD Batch"\Drgs\*.dwg) do start /wait c:\"Program Files"\Autodesk\"AutoCAD 2012 - English"\acad.exe "%%f" /b "c:\ACAD Batch\Scripts\Change_Project_Title.scr"

It now works a treat now.


Posted By: CAD DSF
Date Posted: 11.Dec.2015 at 16:10
Thank you so much for bat file. I updated the script to work with the 2015 version of AutoCAD. I had 500+ drawing to modify and this worked perfectly!

First Step:
Open AutoCAD and set NEWTABMODE system variable to 0. This will stop the new tab screen from appearing.

Second Step:

FOR %%f in ("c:\Location of drawings\*.dwg") do start /wait c:\"Program Files"\Autodesk\"AutoCAD 2015"\acad.exe "%%f" /b "c:\Location of script\Name of script.scr"

You much change the location of script, location of drawings and name of script!


Posted By: harrissjt
Date Posted: 11.Dec.2015 at 18:17
@CAD DSF.  Glad that this was of help.  All the best with your future endeavours.



Print Page | Close Window