The Road to the Purge Command
-----------------------------
Here's a real mystery that I've yet to figure out. I've put together this
document to gain input and maybe a solution.

A few weeks ago I started writing an automatic purging routine. I based
it on some of the techniques used in Tony Tanzillo's automatic purge
routine. Although I had to compensate for XREFS and the nonpurgable
table items (i.e. layer 0, the STANDARD text style and the CONTINUOUS
linetype), the routine went together quickly.

A few days later I was doing some experimenting and loaded up the sample
drawing HOUSEPLN that comes with AutoCAD Release 12. For some reason my
automatic purge routine failed. After several hours of debugging, tracing
and hair pulling, I discovered that a text style named "9" was to blame.

The really tricky part came when I started investigating purging and the
70 association value in the table entry. If a style is unreferenced in the
drawing and can be purged, the value paired with the 70 association value
is 0, otherwise is contains a bit code of 64. In this particular drawing
the text style "9" has a 70 value of 0 which can be demonstrated by pulling
the drawing up and issuing the following at the command prompt:
(tblsearch "style" "9")

Assuming that I'm correct about the 70 value, this style should be
unreferenced and should show up in the PURGE command. Of course it doesn't
show up yet contains a 70 value of 0.

The complete code for the automatic purging routine follows:

(defun S::STARTUP ()
   (setvar "cmdecho" 0)
   (if 
      (/=
         1
         (logand 1
            (getvar "dbmod")
         )
      )
      (progn  
         (prompt "\nCompressing drawing file ...")
         (mapcar
            '(lambda (tablename / name first)
               (setq first T)
               (setq name (tblnext tablename T))
               (while
                  (/=
                     name
                     nil
                  )
                  (if
                     (and
                        (/=
                           64
                           (logand 64
                              (cdr
                                 (assoc 70 name)
                              )
                           )
                        )
                        (/= 
                           16
                           (logand 16
                              (cdr
                                 (assoc 70 name)
                              )
                           )
                        )
                     )
                     (cond
                        (
                           (and
                              (= tablename "layer")
                              (= (cdr (assoc 2 name)) "0")
                           )
                        ) 
                        (
                           (and
                              (= tablename "linetype")
                              (= (cdr (assoc 2 name)) "CONTINUOUS")
                           )
                        )
                        (
                           (and 
                              (= tablename "style")
                              (= (cdr (assoc 2 name)) "STANDARD")   
                           )
                        )       
                        (T 
                           (if first
                              (progn 
                                 (command ".purge" tablename "y")
                                 (setq first nil)
                              )
                              (command "Y")
                           )
                        )
                     )
                  )
                  (setq name
                     (tblnext tablename)
                  )
               )
            )
            '("layer" "ltype" "style" "block" "dimstyle")
         )
         (prompt "\rCompressing drawing file ... DONE!")
      )
   )
)

If anybody can help me with this I'd appreciate it. I haven't found any
other drawing that this routine fails on so it should be a nice automatic
purge routine. Simply place it your ACAD.LSP file. This replaces the file
APURGE.ZIP located elsewhere in this forum. This updated version compensates
for XREFED tables.

Michael Jenkins
Gray Construction Company
Lexington, Kentucky
(606) 281-9276
