Learning Curve: Put Your Files on a Diet8 Dec, 2006 By: Bill Fane
Trim bloated files with AutoCAD's FileShrink command.
Once upon a time (about two weeks ago), Captain LearnCurve and his gorgeous wife loaded their suitcases into the boot (trunk) of their 1937 Rolls-Royce limousine and proceeded south from Vancouver, Canada. It should be noted at this point that Rolls-Royces don't drive, they proceed. Conversely, they never break down, but on very rare occasions they may FTP (fail to proceed).
The adventurers proceeded to Sedona, Arizona, where they joined 20 other Rolls-Royce and Bentley enthusiasts for a week-long tour of the Grand Canyon and surrounding attractions. Upon returning home, 4,000 miles later, with only a few near-FTP incidents, Captain LearnCurve checked his e-mail to find that about 90% of it consisted of spam, trying to sell miracle weight-loss potions. Hmmm, maybe the spammers know him better than he thought. . . .
That's it! This month's column topic! How to use the FileShrink command to reduce the size of bloated AutoCAD files!
"Wait a minute, there isn't really a FileShrink command, is there?"
Well, no, but there are several other commands and techniques that can help.
Mystery File Sizes
At first glance, in these days of multi-gigabyte hard drives, it would seem that file size isn't as much of an issue as it was in the days when 20MB was considered a large drive. On the other hand, it is quite easy to run up against e-mail size limitations when sending drawings. A drawing file that is larger than necessary also takes longer to open and to save.
Current releases are much better than in the good old days. Until fairly recently, if you erased an object and then saved the file, the file didn't get any smaller. The object was tagged as being erased, but it still existed in the file. AutoCAD would not perform a garbage collection until the next time the file was opened, so a heavily edited file could still be quite large. I once saw a 7MB file that consisted of only four lines.
Nonetheless, a current file can still be much larger than it needs to be. A common cause of this problem is block definitions and block insertions.
"Wait a minute, the use of blocks is supposed to be a space-saving technique!"
Normally it is. Rather than making multiple copies of a repeated detail, the correct procedure is to create a block definition, then insert it multiple times. No matter how big the block definition is, each insertion only adds a few hundred bytes to the file size. All it needs to contain is the name of the block, the insertion point, the rotation angle and the scale factors.
Problems arise when your drawing contains block definitions that are no longer used. Although no insertions remain, the definitions live on, taking up file space.
Originally, there was no direct way to get rid of these orphaned definitions, but clever users soon devised a couple of work-arounds. The first was simply to redefine the block to only contain a single object, such as a circle. This didn't really remove the definition, but it did make it much smaller. The other trick, which is still valid today, is to use the Wblock (WriteBLOCK) command. You won't find this command in the menus or toolbars, so you must enter it at the Command prompt. When invoked, it launches the dialog box shown below.
The Wblock dialog box is used to write blocks out to disk.
You use the Wblock command to write selected objects out to disk, where it creates a new drawing file containing them, or to copy selected existing block definitions out to new drawing files on disk. For our purposes I have selected the Entire Drawing radio button.
The next step is to specify a filename and destination. Note that it is possible to overwrite the current file. When we click OK, the entire drawing is written out to disk. The trick here is that it writes only what it needs; no more, no less. It ignores any unused block definitions, along with any other unused named objects, including layers and linetypes, as well as text, dimension, mline, table and plot styles. We end up with a lean, mean, drawing machine.
Now let's back up a bit to see how all these unused objects got into our drawing in the first place. The first option is the template file from which the drawing was created. A template can contain any AutoCAD objects, so a common technique is to pre-load it with our standard definitions for title blocks, borders, layers, the various style objects, block definitions for our standard details and so on. This can be a valuable time-saving technique, but it can also leave debris in the final drawing file. The next possibility is that you simply changed your mind. You created a block definition or named style, then decided you didn't need it. The third suspect is block definitions inserted from disk into the current drawing. The Insert command (Insert / Block) lets you insert any existing drawing into the current one. For example, you may be working on a drawing and know that an existing drawing contains a block definition for a detail that you want to use in your current drawing.
Simply insert the existing file into your current one, and all its block definitions become available in the current drawing. Here's the problem! All of its block definitions now exist in your current drawing, even though you only wanted one of them. Worse than that, the entire inserted drawing is now a block definition in its own right! Worst of all, its layer definitions and named styles were also absorbed. This also happens if you bind an xref. The Borg have nothing on AutoCAD.
Resistance is Not Futile!
There are three ways to overcome this problem. The first is to avoid it to begin with. Rather than inhaling the entire second drawing, use the DesignCenter or customize your tool palettes so you only insert exactly what you need into your drawing (see these previous Learning Curve columns: Pleasing to the Palette, Tooling Right Along and The Right Tools for the Job). The second solution is to Wblock your entire drawing file out to disk, as previously discussed. The third way is to use AutoCAD's Purge command (File / Drawing Utilities / Purge).
The Purge dialog box enables you to purge unused objects.
Okay, I lied a bit in this figure. When the Purge dialog box first comes up, the - buttons show up as + buttons, and it does not display the indented objects. I have expanded the + buttons for discussion purposes. The indented objects in each category are unused, and can be purged from the drawing. There are several purge levels available.
First, Purge All purges everything (obviously), but because the Confirm Each Item box is checked, it asks you to verify each item. If you know you want to purge everything, simply uncheck this box. Next, the Purge button purges only the selected category. By default, the selection focus is on the All Items level, so this is really equivalent to Purge All unless you move it to a sub-category. Moving down a bit, you can also select, and then Purge, a single item. For example, you may want to get rid of the unused block called DamnedSpot, but leave the others intact. Washing your hands and muttering "Out, DamnedSpot!" doesn't work, but highlighting it in the tree and then clicking on Purge does.
The final level is to select the Purge Nested Items box. Nested items occur when a block definition includes one or more other block definitions within it. This also includes layers, linetypes and named style objects that are only used within the nested blocks. If you only purge the parent, then the nested items become orphans that you must purge separately, unless you select Purge Nested Items.
Turning off Confirm Each Item, turning on Purge Nested Items and then clicking on Purge All is equivalent to Wblock without actually writing the file to disk. Sometimes, Wblock or Purge All doesn't get rid of certain items. It's possible to create a block definition that doesn't have any objects in it. You can Insert it, but you can't delete it, because it can't be selected. You can't see any insertions, but it doesn't appear in the Purge list. If it is nested within another block definition, layer and other styles can also get hung up. The solution is to redefine the block to contain a single object, such as a circle, so its insertions can be deleted and then the definition can be purged.
Now you know how drawing files come to comprise extraneous items, and also how to get rid of them. A slim drawing is a happy drawing!
And Now for Something Completely Different
There are two kinds of overnight accommodations in the world. Type A accommodations charge $10-20 per day for Internet access, $1-3 to get an outside phone line, and $1 per day for the morning newspaper. Type B accommodations provide all of the Type A amenities for free, and also include a free breakfast. How can you tell them apart? It's easy: the higher the price per night, the more likely they are to be in the Type A category. Wait a minute, that sounds backwards. . . .
In her easy-to-follow, friendly style, long-time Cadalyst contributing editor Lynn Allen guides you through a new feature or time-saving trick in every episode of her popular AutoCAD Video Tips. Subscribe to the free Cadalyst Video Picks newsletter, and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!