CAD tip # 9553:
Question
If you need to automate purging in your drawings, you can use a simple menu macro (to assign to a button click in your ribbon) or a script. For this, you will use the commandline version of the Purge command, i.e. -PURGE. Remember that not all tables and objects are purged with the option "All", so you will need to separately invoke purging of some special objects (registered applications, zero-length geometry, empty texts). Another special type of object are the DGN linetype definitions - there is a special DGN-hotfix for them (see Download) with the command DGNPURGE. Due to possible nested objects, it is advisable to repeat the purging process a couple of times.
Then the resulting script for purging really all excessive unused objects and definitions from the current DWG drawing looks like this:
_NETLOAD DGNLSPURGE.DLL DGNPURGE _-PURGE _REGAPP * _N _-PURGE _ZERO _-PURGE _EMPTY _-PURGE _ALL * _N DGNPURGE _-PURGE _ALL * _N DGNPURGE _-PURGE _ALL * _N
Except DGNPURGE, you can perform this purging also in AutoCAD LT. You can also use this script to batch-purge drawings with ScriptPro.
UPDATE: Since version 2015 you can use _-PURGE _Orphaned instead of loading and calling DGNPURGE.
Please note that all these purge commands can be executed - e.g. with a .SCR script - also in the console (non-graphical) version of AutoCAD, AcCoreConsole.exe. See the Tip 8552.

