I have a number of batch tools that utilize scripts to process lists of drawings.
My general method is:
1) Separate LISP into 2 functions, one that creates and runs the main script, and one that will run in each dwg, ex: f-external and f-internal
2) In (f-external), for each dwg in the batch list, add to the main script something similar:
"_.OPEN"
"path-to-dwg"
"(load \"path-to-lisp\")"
"(f-internal)"
Loading and executing the (f-internal) function per drawing keeps all real work inside LISP, instead of having a long script file that can only
issue commands. This lets you do all the cool vla/vlax functions and decisions/loops that you can't do through script commands.
If you are loading each drawing in its own session, such as through core console, then you can omit the open command and use the same
script for every drawing, instead of making a long assembly line type of script.
3) In (f-internal), do all necessary work, then save and close the drawing
4) At the end of (f-internal), I append a report or log file of work done. You could also write variables to a file at this point so that the main code can read them back if needed.
As for keeping main code paused while f-internal is working, what I have been doing is creating my own .lock file that gets deleted when f-internal is finished (it may be any file type really, and does not need to contain any actual data). Somewhere in a (foreach dwg dwgs..) processing loop or in a main code block just before the main script starts running, I usually have code similar to the following:
(while (findfile "path-to-lock")
(command "DELAY" 1000)
)
So every second it checks if the lock file still exists, and if so it waits before continuing along in the loop. If you would like to use only one lock file that exists for the duration of the batch, you could have the end of script delete the lock file instead of (f-internal) with:
"(vla-file-delete \"path-to-lock\")"
This method has been very successful for me, both in MDI and SDI batches. Hope it helps.