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

Automate stupid DWG post-processing?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
johanwall
641 Views, 6 Replies

Automate stupid DWG post-processing?

Hello everyone,

 

We export drawings from our BIM software to DWG format. But according to drawing delivery requirements we need to post-process the DWG files in AutoCAD with the following routine:

  1. Open DWG file
  2. Change active layer to Layer 0
  3. Zoom Extents
  4. Purge all (usually 1-3 times)
  5. Save DWG file as AutoCAD 2013 Drawing format.

This is repeated for every DWG file. In large projects with lots of drawings this is a very tedious process, as you can understand. We can not deviate from the delivary requirements because they are deeply intertwined with consultancy contracts here in Sweden.

 

It would be great if we could run a script in AutoCAD which performs this process on all DWG files in a folder.

Is it possible to automate this process with a script? If so, we would appreciate pointers. Prepared to spend some time on this matter.

 

Best regards,


J. Wall

Architect

www.johanwall.com

6 REPLIES 6
Message 2 of 7
hak_vz
in reply to: johanwall

Here is option using accoreconsole.exe

For a test create directory D:/test and copy to it some dwg file to process (for testing).

In that directory create batch file named "proc.bat" and change path to accoreconsole.exe in it according to your version.

 

 

echo off

:: Path to AutoCAD core console
set accoreexe="C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe"
:: Path the directory to process
set "source=D:\test"
:: Path to the script to run
set script="D:\test\proc.scr"
FOR /f "delims=" %%f IN ('dir /b "%source%\*.dwg"') DO %accoreexe% /i "%source%\%%f" /s %script%

pause

 

 

 

In same directory create script file named "proc.scr"

 

(setvar 'ctab "MODEL")
(load "d:\\test\\proc.lsp")
save ""

 

In same directory create lisp file named "proc.lsp". It may look something like this. I guess defaultformat for save is 60 but check . copy to acad console and run (getenv "DefaultFormatForSave") after ypu set default save format to version Acad 2013

 

(setvar 'cmdecho 0)
(command "_.-layer" "_set" "0" "")
(command "-zoom" "e")
(command "-purge" "All" "n" "" "")  
(setenv "DefaultFormatForSave" "60")
(setvar 'cmdecho 1)
(princ)

 

In lisp file append command options in accordance wit the version you use, by running command in console i.e. -layer -purge (repeat that row 2-3 times if necessary.

 

Run proc.bat to process dwg files in directory(folder) D:test. Always hold original files and process copies for safety reasons.

 

Miljenko Hatlak

EESignature

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.
Message 3 of 7
johanwall
in reply to: hak_vz

Thank you for the eloborative suggestion and explanation. We will give this a try!


J. Wall

Architect

www.johanwall.com

Message 4 of 7
pbejse
in reply to: johanwall

IMO the best way to clean a drawing imported from revit is to use the command -EXPORTTOAUTOCAD in conjunction with a script and not just PURGE all

 

Command: -EXPORTTOAUTOCAD
File format: 2018
Bind xrefs: Yes
Bind type: Insert
Filename prefix: ACAD-
Filename suffix:

Export options [Format/Bind/bind Type/Maintain/Prefix/Suffix/?] <Enter for filename>: F

Enter file format [r14/2000/2004/2007/2010/2013/2018] <2013>: 

Export options [Format/Bind/bind Type/Maintain/Prefix/Suffix/?] <Enter for filename>: 

 

Message 5 of 7
maratovich
in reply to: johanwall

Use this - AutoRunLisp 

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
Message 6 of 7
Anonymous
in reply to: johanwall

Most of that can be handled through DWGConvert in AutoCAD, or even TrueView.  Look into the conversion options, there are settings for purge, importing named page set-ups, set default printer to 'none', and AUDIT.

Message 7 of 7
johanwall
in reply to: hak_vz

This method turned out to work exactly as I wanted, thanks! I reworked your method/code to fit my needs. Thought I might share my solution for other forum visitors to find. It relies on two files: one .bat file and one .scr file.

 

The files automate this process:

  1. Switch to model space
  2. Set active layer to 0
  3. Zoom extents
  4. Purge all (x3)
  5. Save as AutoCAD 2013 DWG

Here's how I use  it.

  1. Copy BOTH of these files to the folder with your DWG's
        DwgExportPostProcessingScript.lsp
        DwgExportPostProcessingExecutable.bat
  2. Execute the .bat file.
  3. Take a break while your files are being processed.
  4. Done!

 

DwgExportPostProcessingExecutable.bat

 

echo on

:: Path to AutoCAD core console
set accoreexe="C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe"

:: Path the directory to process
set "source=%CD%"

:: Path to the script to run
set script="%CD%\DwgExportPostProcessingScript.scr"
FOR /f "delims=" %%f IN ('dir /b "%source%\*.dwg"') DO %accoreexe% /i "%source%\%%f" /s %script%

pause

 

 

DwgExportPostProcessingScript.scr

 

(setvar 'cmdecho 0)
(setvar 'ctab "MODEL")
(command "zoom" "e")
(command "_.-layer" "_set" "0" "")
; Triple purge just to be sure
(command "-purge" "All" "*" "N" "")
(command "-purge" "All" "*" "N" "")
(command "-purge" "All" "*" "N" "")
; DefaultFormat 60 equals saving as AutoCAD 2013 DWG
(setenv "DefaultFormatForSave" "60")
(setvar 'cmdecho 0)
(princ)
(command "_.save" "" "Y")
; Important to end script with linebreak below this last comment

 

 


J. Wall

Architect

www.johanwall.com

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

Post to forums  

Forma Design Contest


AutoCAD Beta