How to use Batch Save Utility

How to use Batch Save Utility

joel.harry
Contributor Contributor
980 Views
7 Replies
Message 1 of 8

How to use Batch Save Utility

joel.harry
Contributor
Contributor

Hi All,

I’m trying to use the Batch Save Utility to run scripts on multiple drawings. I’ve explored various batch utilities like MultiFileTool.lsp, ScriptPro, ACCoreConsole.exe, AutoScript, and Autodesk Batch Save Utility (BSU). MFT and accore seemed a bit out of my league as it seemed there's a lot of backend stuff that might need to be done (DosLib and such...I don't know anything about programming). ScriptPro didn't work, had some success with AutoScript but BSU seemed promising since it's an AutoCAD product so wanted to see if it would work.  

 

I couldn’t get it to work with Civil3D 2022 files. No matter what I did it either didn't save the files or got hung up. Has anyone had success with it? If so, did it work immediately, or were specific settings needed? I suspect my limited admin rights on my company computer might be causing issues, especially if admin access is required for tools like accoreconsole. If it matters, the script I'm trying to run is a very simple one to remove all xrefs from files. The script is not the problem. It works in CAD.  

0 Likes
981 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

have you tried Lee Mac's Scriptwriter:

Script Writer | Lee Mac Programming (lee-mac.com)


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 8

DGCSCAD
Collaborator
Collaborator

I've used modified versions of this code for batch processing with success. Here, it has been adjusted for your needs:

 

;Batcher_XRef.lsp
;Description: Removes all XRefs in Batch Process applied to all dwgs in Specified Directory.
;Tip: Run this from a drawing that is NOT in the Specified Directory.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Start Main Prog

(defun c:Batcher_XRef (/ wutdir wutfiles scrfile n2 scrline)
(vl-load-com)
	(setq wutdir (LM:browseforfolder "Select directory to process:" "C:\\" 512));;;<--Specified Directory
	(setq wutfiles (vl-directory-files wutdir "*.dwg"))
	(setq scr_name (strcat wutdir "\\scrfile.scr"))
	(setq scrfile (open scr_name "w"))
	(close scrfile)
	(setq scrfile (open scr_name "a"))
(foreach n wutfiles
	(setq n2 (strcat "\""wutdir "\\" n "\""))
	(setq n2 (vl-string-translate "\\" "\\" n2))
	(setq scrline (strcat "open" " " n2 " " "(load\"Batcher_XRef\")" " " "LISP_Functions" " " "qsave" " " "close"))
	(write-line scrline scrfile)
	(princ)
)
	(close scrfile)
(command "script" scr_name)
(princ "\n***Batch complete.***")
(princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Start LISP Functions

(defun c:LISP_Functions ()
(command "_.-xref" "detach" "*");;;<--LISP Function - Change to your neeeds
(princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Start Browse for Folder
;; THANKYOU Mr. M!
;; Browse for Folder  -  Lee Mac
;; Displays a dialog prompting the user to select a folder.
;; msg - [str] message to display at top of dialog
;; dir - [str] [optional] root directory (or nil)
;; bit - [int] bit-coded flag specifying dialog display settings
;; Returns: [str] Selected folder filepath, else nil.

(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
    (setq err
        (vl-catch-all-apply
            (function
                (lambda ( / app hwd )
                    (if (setq app (vlax-get-acad-object)
                              shl (vla-getinterfaceobject app "shell.application")
                              hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
                              fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
                        )
                        (setq slf (vlax-get-property fld 'self)
                              pth (vlax-get-property slf 'path)
                              pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
                        )
                    )
                )
            )
        )
    )
    (if slf (vlax-release-object slf))
    (if fld (vlax-release-object fld))
    (if shl (vlax-release-object shl))
    (if (vl-catch-all-error-p err)
        (prompt (vl-catch-all-error-message err))
        pth
    )
)
(princ)

 

Tips for running the function:

1. Save the Batcher_XRef.lsp file to a support directory.

2. Copy all target drawings to a temp directory.

3. Start a new drawing.

4. Drag/drop Batcher_XRef.lsp onto the new drawing.

5. Type: Batcher_XRef at the command line.

6. Select the temp directory where the files reside.

7. Grab a cup of coffee.

8. Move/overwrite the drawings back into the directory they were copied from after the function has completed.

 

The XRef portion of the code is untested, but should suffice.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 4 of 8

joel.harry
Contributor
Contributor

@DGCSCAD thanks for that. Here's what happens when I run that lisp:

  1. prompts for folder with drawings
  2. prompts to select a file and opens a file select dialog box
  3. if you select a file, it opens the file
  4. xref manager opens
  5. After that, nothing else happens.

So it's working in the sense that it prompts for the folder with the drawings but having to select drawings manually isn't good. It needs to do that automatically. Not sure why the xref detach lisp isn't working but that's secondary because if the multiple drawing open/save/close worked, I'd like to replace the lisp with a script that does the xref remove and other sequential commands that could be added based on project specific needs. 

0 Likes
Message 5 of 8

DGCSCAD
Collaborator
Collaborator

It shouldn't ask for a file, just a folder where the files reside.

 

Could be something with using Civil 2022, since this was written for vanilla AutoCad.

 

I just tested it in AutoCad 2018 with no issues.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 6 of 8

joel.harry
Contributor
Contributor

I don't have 2018 installed any longer but tried it in 2020 vanilla ACAD and same result. After folder pick it prompts to select a file.

joelharry_0-1724342991246.png

 

0 Likes
Message 7 of 8

DGCSCAD
Collaborator
Collaborator

Go to the folder you selected and open the scrfile.scr file.

What are the contents of that file?

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 8 of 8

ec-cad
Collaborator
Collaborator

You could try the ECBATCH Utility attached here in the .zip file. This batch process is entirely Lisp / DCL,

and does the same thing as ECBatch.exe - a VB6 program.

I'm releasing this version as a freebee.

 

See the notes at top of the ECbatch.lsp  for installation.

 

Let us know if you like it !

 

ECCAD

0 Likes