Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Batch file for script problem

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
TDD
Participant
4330 Views, 9 Replies

Batch file for script problem

Hi All,

I have trialled writing a script and a batch file to carry out a series of tasks to a set of drawings in AutoCAD 2016.

The aim is to open the vendor supplied drawings, add a layer name, switch to a layout, insert a sheet border + attribute sheet, make defpoints the current layer and insert a single viewport, save & close.

Well the script works fine in a single drawing. However when I try to run the batch file, AutoCAD will open the file invoke the script and run as expected, then quit out of AutoCAD, then repeat for the next file, etc, etc.

Is there a way I can speed this up by not shutting down AutoCAD each time. My script trials using 'close' instead of 'quit' do not work, just stops after the first file has been converted.

My Script file (xxxlayer.scr) is as follows;

-Layer
_new
xxx
_m
xxx

-layout
_set

_zoom
_extents
-insert
KCA5-A3E-PCMC.dwg
0,0
1
1
0
_zoom
Extents
-insert
KCA5-A3EA-PCMC.dwg
0,0
1
1
0

 

-layer
_m
defpoints

_zoom
extents
-vports
20,43
410,287
qsave
quit

 

My Batch File is as follows;

FOR %%f in (C:\temp\*.dwg) do start /wait C:\"Program Files"\"Autodesk\AutoCAD 2016"\acad.exe "%%f" /b "C:\temp\xxxlayer.scr"

 

This is something new for me and am relatively pleased with how far I have progressed using information from this forum so far.

Looking forward to continuing to learn

 

9 REPLIES 9
Message 2 of 10
redtransitconsultants
in reply to: TDD

My guess is it is in your batch code that is closing CAD each time. I forget what all the switches stand for off hand, but this code seems to work for me, and it does not close CAD after each file.

 

FOR %%F IN ("C:\MY\FILE\PATH\*.DWG") DO "C:\Program Files\Autodesk\AutoCAD 2016\accoreconsole.exe" /I "%%F" /S "C:\MY\FILE\PATH\MyScript.scr" /L en-US

 

 

Steve Hill,Civil Designer / .NET Developer / AutoCAD and AutoCAD Civil 3D Certified Professional
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

http://redtransitconsultants.com/
Autodesk Exchange Store
Twitter | LinkedIn | YouTube

Message 3 of 10
steven-g
in reply to: TDD

That is just how this method works, the batch file starts autocad and cannot move onto the next file until it receives a signal that Autocad has closed again, if you want to run this script from within an open Autocad session you will be better of learning one of the programming languages within Autocad such as LISP, though I do believe there is a built in method for running a batch file within Autocad (the full version, I use LT so I can't help you on that) try looking at Autocad's scriptpro.

Message 4 of 10
TDD
Participant
in reply to: redtransitconsultants

Thanks for the quick response.

I tried the solution a few moments ago and it worked perfectly.

Having seen the benefits of this I think I might now experiment with other script functions.

The next idea I have is to try and use the file name and insert this into an attribute.

Thanks again.

Message 5 of 10
TDD
Participant
in reply to: steven-g

Thanks for the reply, I will look into Scriptpro as you suggested.

Message 6 of 10
Anonymous
in reply to: TDD

I posted an example of AcCoreConsole usage in another post

 

Message 7 of 10
Y.AUBRY
in reply to: TDD

Hello from France,

 

You can use the SuperAutoScript program from CADERIX

Download SuperAutoScript 

 

It's very easy to use.

 

Bye

Yoan AUBRY

EESignature

Message 8 of 10
Sea-Haven
in reply to: TDD

Going back to the use of a script in autocad using say  Scriptpro, or for me its old fashioned DOS 

DIR *.dwg /b >Dirdwg.scr This makes a list of dwg names. I use Word to create the script you can replace the end of para ^p with lines of code so repeating what is required.

I would also make all the commands to be executed to be a lisp. Lisps can be called from scripts so long as no use input required.

 

so my script would be and Autocad stays open.

 

Open dwg1
(load "mylisp with all the steps")
Close Y
Open dwg2
(load "mylisp with all the steps")
Close Y
Open dwg2
(load "mylisp with all the steps")
Close Y

 

Message 9 of 10
rvtquestions
in reply to: steven-g

Revisiting this years later...

 

Can anyone advise how to make Autocad close automatically so that the batch file continues? Currently when I run my batch file (which runs a script performing several basic clean functions, qsave, and then close) it opens a file, performs the script, closes the file but not the program session and the batch file waits until Autocad is fully closed.  A user has to manually close the Autocad window so that the batch moves onto the next file. For those who successfully have it automated, what might be incorrect in my batch or perhaps Autocad variable settings?

 

Here is what I have and know:

 

  • Batch Contents:
    • FOR %%f IN (Drawing Directory\*.dwg) DO start /wait C:\"Program Files"\"Autodesk"\"AutoCAD 2023"\acad.exe "%%f" /b Name of Script.scr
      • Removing the "/wait" works however it opens a new session of Autocad per drawing so ultimately multiple Autocad windows which is prone to resource intensive conditions and crashing.
  • Whether I end my script with Close, Quit, or nothing, it doesn't change anything. The file closes but the Autocad session/window is still open.

 

Thank you.

Message 10 of 10
Sea-Haven
in reply to: TDD

Using scripts it was intended to have Autocad open at all times, using a batch file  is probably the problem. You can use lisp to make a script file that has the open dwgname line at start.

 

Look into using accoreconsole it will run in the batch file method.

https://autocadtips1.com/2013/01/30/up-and-running-with-the-2013-core-console/

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report