Display full version of the post: Initialize Script Using Batch File

mfkozlow
17.07.2014, 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.scrHere 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.scrxxxxx1.dwg /b clean.scrThe 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.

John Connor
17.07.2014, 17:30
Maybe this program by Lee Mac might prove more useful.http://lee-mac.com/scriptwriter.html

mfkozlow
18.07.2014, 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.

John Connor
18.07.2014, 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
John Connor2014-07-18 17:43:38

mfkozlow
18.07.2014, 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.EXEEven 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.

John Connor
18.07.2014, 18:27
Why is it a Windows problem?  You open AutoCAD first then you run the script not the other way around.

mfkozlow
18.07.2014, 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!

mfkozlow
18.07.2014, 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?

harrissjt
28.01.2015, 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;.BATFOR %%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" ScriptZOOM E;EDIT PROJECT REVISION-ATTEDITNNA*-TITLEREV_NO*A0;;EDIT PROJECT TITLE-E-ATTEDITNNA*-TITLETITLE1*TA2015 GC-201.1/2/3 CCC POWER SUPPLIESTA2015 GC-201 CCC CONTROLLER UPGRADE;;EDIT PROJECT TITLE-R-ATTEDITNNA*-TITLETITLE4*ЭЛЕКТРОПИТАНИЕ НА GC201.1/2/3 CCC КР2015КР2015 GC-201 МОДЕРН-ЦИЯ КОНТРОЛЛЕРА СССQSAVEQUITY I hope that someone out there can help, this has been driving me nuts all day! Cheers,Steve

John Connor
28.01.2015, 15:53
Maybe it has to do with the direction of the slash(es) after C:?

harrissjt
29.01.2015, 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.

CAD DSF
11.12.2015, 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!

harrissjt
11.12.2015, 18:17
@CAD DSF.  Glad that this was of help.  All the best with your future endeavours.