A necessary part of many AutoCAD® users’ day is cleaning up drawing files. Not all users set up their drawings with your use in mind, and sadly some don't set it up with anybody's use in mind. There are a variety of reasons that AutoCAD users would need to clean up drawings.
- MEP users who receive updated backgrounds from architects or civil engineers.
- Architects who receive clients’ prototypical drawings that need to be converted to the architects’ standards.
- Architects who receive civil drawings to clean up for an architectural site plan.
- Autodesk® Revit® users who need to clean up AutoCAD drawings before linking or, in some cases, importing them into Revit.
- Architects and engineers who clean up their drawings before sending them to an outside consultant or owner.
- Archivers who need to clean up drawings for archival purposes.
Many times, users will clean up drawings only when they have to, such as for errors (crashing drawings, inability to import in to other applications), or files being too big to email, etc. By keeping the cleanup process simple and automating as much as possible, it is more likely to get done on a regular basis. As we all have experienced, issues tend to hit on deadline day.
Everything starts with good habits and procedures. Start by keeping your drawings lean and efficient. Use standard layers, linetype, and text styles. Use polylines, and polygons when creating objects, use explode as a last resort and use blocks/dynamic blocks to represent your drawing data. Automate your drawing standards, and object insertion processes verses copying one job to create another. Sometimes, even with good drawing practices, files will need to be cleaned up. And when dealing with outside users, cleanup is a lot more likely.
AutoCAD has some built-in tools that can help make the drawing cleanup process much easier. These tools can be used individually to handle certain cleanup tasks, or they can be used in conjunction with others to handle larger cleanups. A few of the tools that you may find useful are “Purge,” "Audit," "Selectsimilar," AND Wblock.
A brief outline of what you would use each command for and then a more detailed description of how they can be used for your cleanup purposes follows, as well as some example scripts on how to automate their use for drawing cleanup. Some of these commands have dialog and command line options, so depending on your productivity style, you have options. If you are a mouse dialog, ribbon, or toolbar user, I encourage you to consider the command line versions to increase your productivity. The command line can be a powerful production option, especially when combined with shortcuts and Macros.
- PURGE: Removes unused named objects, such as block definitions and layers, from the drawing using a dialogue or the command line.
- AUDIT: Evaluates the integrity of a drawing and corrects some errors (command line).
- SELECTSIMILAR: A simple method to select objects based on similar properties such as layer, color, name, or line weight.
- WBLOCK: Saves selected objects out of the current drawing or converts an existing block to a specified external drawing file.
Over time, drawings get bloated with unnecessary and outdated information. This can include unused layers, linetypes, fonts, styles, and blocks. By getting rid of these extraneous items you keep your drawings lean. Lean drawings use less memory and have less storage requirements, thus saving drive space, backup space, load and save times, and email overhead. Lean drawings also are less likely to become corrupt. The following types of unused named objects can be removed from the current drawing: block definitions, dimension styles, groups, layers, linetypes, and text styles. It will also remove zero-length geometry and empty text objects. The PURGE command will not remove unnamed objects (see below for unnamed blocks).
Purge can be done from the command line or through a dialog box. For various scenarios you may use one or the other. See Figure A for the Purge dialog box from AutoCAD 2013. The dialog shows that basically no items are available to be purged. If you change the top option from “View items you can purge” to “View items you cannot purge,” you can see all the things that are not “purgeable.” Are these still being used? These can include styles, linetypes, layers, plot styles, and so on. If you don’t think you are using these, but items will not purge, then check some of the following.
- Could it be nested inside another block?
- Is it an attached Xref?
- Is it an anonymous block that just won’t purge? (*A…)
- Is it a standard AutoCAD layer (0 or Defpoints)?
- Is it used in part of a block definition?
- Is it set current?
- Does it have a block inserted on it?
- Could it be used in a dimension or mleader style?
- Is it set current?
- Could it be used in a layer that is not being purged?
- Is it set current?
- Is it part of a block definition?
Figure A: Purge Dialog (Version 2013)
-PURGE (command line)
Purge also allows you to remove unused ‘named’ objects from a drawing at the command prompt. You can only remove one level of nested items at a time, so you may need to repeat the process until there are no items left to be purged. (Create a macro or script to automate this.) The PURGE command will also remove un-named objects (zero-length geometry or empty text and mtext objects starting in 2010). Even when using the “All” option, purge by default will not remove REGAPPS**. Basic prompts and typical responses are below when typing “-purge” (the quotes are not required).
Enter type of unused objects to purge: “A”
Enter name(s) to purge: “*”
Verify each name to be purged? “N”
** One item that will need an extra step is “REGAPPS.” Regapps are a byproduct of objects with extended entity data (xdata). When you delete an xdata object, a REGAPP ID remains. To remove these, you must do it from the command line.
–Purge <enter> R <enter> * <enter> N <enter>
Annoying items that creep up quite often are the infamous “un-named”or “anonymous” blocks or groups. These show up as *A123, *A124, *X12, *D13, etc. You may have noticed that when you ran Audit, there were far more blocks in your drawing than you thought there should be. This builds over time as you continue to use old projects for new work and when you use outside vendors or consultants’ drawings. It can be very frustrating to find 1,000 blocks in a drawing that do not show up in your block list and will not purge! Some of these are created by AutoCAD for hatch patterns [*X nnn], associative dimensions [*D nnn] and some are created by AutoLISP routines. For me this happens a lot when working with drawings from civil and architectural offices. To remove the blocks that are not being used, you can use the Wblock or –Wblock command (see WBLOCK).
*Unnn = anonymous blocks
*E### = anonymous non-uniformly scaled blocks
*X### = anonymous hatches
*D### = anonymous dimensions
*A### = anonymous groups
From time to time you will get a file that requires recovery to open it, or during a working session you will get an error suggesting that a recovery may be necessary. One way to keep your drawings healthy is to be proactive and run the audit command. Audit is a good maintenance tool to run on your drawings to keep them clean of most errors. When you get drawings from outside firms, this is a must-do step. If a drawing contains errors that AUDIT cannot fix, try using RECOVER to open the drawing and correct its errors.
Audit is a command line tool. Following are the prompts and options.
- Type “Audit”
The following prompt is displayed.
- Fix any errors detected? [Yes/ No]. You would typically choose “Yes,” unless you’re just looking to see if the drawing has errors.
- When the routine is done it will give you a status report of how many objects it audited and how many errors it found and corrected. Running Purge prior to an Audit will often reduce the overhead of auditing items you do not intend to keep anyway.
Note: If AUDIT or RECOVER do not work and your still getting errors, try inserting the troubled drawing into a clean empty drawing, EXPLODE it, PURGE, and do a SAVEAS.
How many times have you worked on a drawing where you were just looking to get just line work or just text isolated on a layer? You try to freeze or isolate text or dims only to find out that half the drawing disappeared. This is a common issue with various trades where everything associated with a specific topic is on a single layer. For example, an architectural drawing has a ceiling plan layer: "A-CLG" that includes the grid, the lights, the diffusers, the notes, and the dimensions all on one layer—in different colors (ugh!). Or how about an HVAC drawing that has the main ducts, flex ducts, and supply grille/diffuser blocks all on a single "M-SUPPLY" layer. Sometimes you just need the lights or grid or supply grille locations, but doing layer isolate (another handy tool) gives you everything. Selectsimilar to the rescue!
Selectsimilar provides you with a way to select objects based on similar characteristics. Objects based on properties such as layer, color, or lineweight can be grabbed quickly with this command. Access the command by typing “selectsimilar” at the command line or from the right-click shortcut menu after you've selected an object. What is selected will depend on the current SELECTSIMILARMODE value.
If you have objects with a different color being included when selecting objects based on color, note that objects are considered similar if they are set to “BYLAYER.” This also includes properties like linetype, lineweight, plot style, material, and transparency. For example, you may get text or line work selected even though they are not the same color if their color property is set to BYLAYER.
To select similar objects, you can type “SELECTSIMILAR” (create a shortcut like “SS”) or select an object that represents the category of objects you want to select, right-click, and choose “SELECT SIMILAR.”
Note Only objects of the same type (lines, circles, polylines, etc.) are considered similar. You can change other shared properties with the SELECTSIMILAR command, using the “SE” (Settings) option.
The Settings dialog box controls which properties must match for an object of the same type to be selected.
- Color – Considers objects with matching colors to be similar.
- Layer – Considers objects on matching layers to be similar.
- Linetype – Considers objects with matching linetypes to be similar.
- Linetype scale – Considers objects with matching linetype scales to be similar.
- Lineweight – Considers objects with matching lineweights to be similar.
- Plot style – Considers objects with matching plot styles to be similar.
- Object style – Considers objects with matching styles (such as text styles, dimension styles, and table styles) to be similar.
- Name – Considers referenced objects (such as blocks, xrefs, and images) with matching names to be similar.
To automate the SELECTSIMILAR command in a macro or script you would use SELECTSIMILARMODE. As with many AutoCAD commands, each combination of options has a bit code (numerical value). Some examples:
- Select color only = 1
- Select Color and Layer = 3
- Select Color and Name = 129
- Select Layer and Name = 130
To determine these values, run the SELECTSIMILAR command, type SE, and toggle the options. Then run the SELECTSIMILARMODE command to find the numeric value of these options.
I use "130" most often. This allows me to isolate named objects like "Text" on the same layer. Using Selectsimilar to select a piece of text on a layer would select all text on that layer - no matter what style or color it is. Selecting a polyline with the 130 setting would select all polylines on that layer - no matter what color. Selecting a block would only select other blocks with the same name on that layer. Each of these is useful when selecting items that you may wish to delete or move to another layer.
The WBLOCK (Write Block) command is probably best known for saving selected objects or a block within a drawing to an external drawing file. WBLOCK can be a very powerful cleanup tool in your arsenal. Probably the most common method of drawing extraction is to type WBLOCK and follow select the options in the dialog to save parts of a drawing to a specific drive and folder.
The dialog gives you three options: You can choose a block within the drawing, the entire drawing, or objects that you want to selectively ‘write out’ of the drawing. When selecting objects, you select a base point, select the desired objects, and then select a new name and path where your file is to be saved.
You also have the option to access the quickselect dialog to select items via a properties filter.
You can also use WBLOCK from the command line. To use WBLOCK at the command line, add a hyphen in front of the command, e.g., -WBLOCK.
It will then prompt you to enter a name of an existing block or define a new drawing. You have three options here.
- Type an existing block name within the drawing that you want to “write out.” (Use if you have created a block in the current drawing and you want it now saved out to your master library or a project folder.)
- Hit enter and a new drawing will be created with the name you entered in the previous dialog. You will be able to select an insertion point and select the objects to write-out. (Use if you want to selectively write out objects to a new drawing file.)
- Type an asterisk ‘*’ which will cause it to write out the entire drawing. (Use to do a mass cleanup of your drawings in a single sweep.)
When cleaning up client drawings or your own from rogue data that has been inserted (often through copy-paste operations), this is a very powerful tool. This handy method writes the entire drawing to the new output file, except for unreferenced symbols. Model space objects are written to model space, and paper space objects are written to paper space.
If you use the dialog to do your WBLOCK operations, even when you selectively choose your objects, takes all the junk with it that you already can’t purge.
- Open a drawing that has unpurgeable items (bunch of *A1nnn blocks) Say “A1.DWG”.
- Turn On, Unlock, and Thaw all your layers.
- Type WBLOCK and choose the “Objects” option.
- Select everything in your drawing (crossing, window, etc.).
- For the Destination, choose a new file name “A1-Objects.DWG.”
- Type AUDIT and see how many objects are in the drawing.
- Compare your size to the original A1.DWG.
Then try this, with the drawing still open:
- Type WBLOCK and choose the “Entire drawing” option.
- Choose a new name “A1-Entire.DWG.”
- Type AUDIT and see how many objects are in the drawing.
- Compare all your sizes now.
- : )
(Already Purged), Audit reports 114,900 objects and 3,478 blocks - 4,327 KB.
WBLOCK (Entire drawing option OR –Wblock with “*”), Audit reports 4,600 objects 71 blocks - 291 KB (93 percent smaller).
The second option removes all those unused and unpurgeable items that the first would not. See how much faster your drawings open, save, and close.
++ Be careful, though, as both of these methods will remove any Layer States in the drawings.
AUTOMATE YOUR CLEANUP PROCESS
By combining a mixture of the tools above along with some other AutoCAD commands, you can reduce the cleanup time dramatically with Macros, Scripts and Scriptpro. Although macros have been my standard automation tool, it is often easier to use scripts so that you can do batch automation with Scriptpro, a free utility from Autodesk that can be found on the Autodesk website.
^C^C -PURGE;A;*;N; -PURGE;A;*;N;AUDIT;Y;-PURGE;A;*;N;ZOOM;E;SAVE;CLOSE;
Superpurge: (includes Regapps and WBlock)
Sample Macro in CUI
Note: be sure to define your “similar” mode in your script/macro by setting the “selectsimilarmode” value.
If you have to commonly bind and save your drawings to an older version (SAVEAS), you can have a Macro setup just for that.
There is not one “super cleanup” command or macro tool that will work for everyone, but you can get pretty close to what will equate to “your” super tool with a little thought. Look at your cleanup process—what are you repeating or what is client “A” always requiring as part of the cleanup process? Automate these items using the tools above and tweak as necessary for each client.
Let’s say you want one ultimate macro that varies slightly by client, but is pretty consistent overall. Some things you may want:
- Set consistent Units – Use the units command options.
- Want the drawings to be lean and error free – Use Audit and Purge.
- All items to be color by layer – Use the SETBYLER command (Thaws and Unlocks all layers).
- Want the layers to be consistent – Use client-specific Layer States.
- For clients that use the standard AutoCAD font style as “their” standard – Rename it to ARCH-STANDARD.
- Saved when zoomed to extents – Use Zoom, extents.
The below macro would accomplish that and would take literally seconds to run.
^C^C-UNITS;4;16;1;0;0;N; -LAYER;T;*;ON;*;UNLOCK;*;; -PURGE;A;;N;AUDIT;Y;-PURGE;A;;N;SETBYLAYER;ALL;;YES;YES;Z;E;-LAYER;A;I; F:/CUSTOM/LAYER_STATES/CLIENT_NAME/CLIENT.LAS;R;DESIRED_STATE;;; -RENAME;S;STANDARD;ARCH-STD;Z;E;SAVEAS;
Items in BOLD would vary by client.
If every job is totally unique for you and you need a generic macro, you would remove the layer states option above and you may want to skip the SETBYLAYER command as it may give undesired results when plotting.
After the macro runs, you could use some of the other tools mentioned above to clean up the drawing even further.
Standardization, automation, and training are the best tools for increasing your efficiency in any process in AutoCAD. Once you find out which tools (commands/macros/scripts/LISPs) are your go-to items and you have a set process, you can whip through the drawing cleanup process. Over time I have standardized on many of the above commands and macros, but I am always looking for new options to reduce any repetitive or time-wasting tasks.
Test, Test, Test! When incorporating new tools and methods into your arsenal or cleanup process, be sure to test on non-production drawings or at least copies of drawings before you implement these as standard tools. Each office may have unique file requirements that need to be considered when implementing these processes.
This article by no means covers all the tools available for drawing cleanup, but these are some very useful ones that when used individually or in conjunction with others can make your drawing cleanup process go much faster. As there are a multitude of options and tools available in AutoCAD for cleaning up your drawings, I encourage you to look in to some of these other powerful commands and AutoCAD options:
Sets selected objects to color BYLAYER (as they should be). You can also use this to change the linetype, lineweight, material, and transparency to BYLAYER. Like SELECTSIMILAR, SETBYLAYER has a mode value (SETBYLAYERMODE) that can be set (i.e., for color only the value is 113). I typically do NOT change linetype to BYLAYER as it is a common scenario to have a linetype set to by entity but on the same layer with other line types.
To create saved selection sets.
QUICK SELECT (QSELECT):
Use to select different types of objects that share the same properties such as color, linetype, plot style, lineweight, transparency, etc., and build a selection set on the fly.
Use to remove duplicate items in a drawing that share the same space (i.e., doors, walls, lights, etc.) right on top of one another. This often happens when binding similar XREFs or copying items and inadvertently selecting the same origin and destination point and not realizing it.
Clean efficient drawings make for happy users!