Author Topic: Purge Tools  (Read 13916 times)

0 Members and 1 Guest are viewing this topic.

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: Purge Tools
« Reply #15 on: November 19, 2008, 03:11:09 PM »
Note that if you try to clean a drawing that has lots of Application IDs, and xrefs, it will typically run very slow.
Those App IDs are worse than anything else.  I would leave them out, in favor of a tool that cleans them RealDwg style.
That is what Adesk did for me, wrote an exe that cleans regapps and layer filters.  It runs outside of acad, so just does nothing if a corrupt drawing is encountered, and is very fast.  Its 20x faster than any other solution I have seen, so that is a big deal.
Grab the PurgeIDs prog from cadthinking.com to get my prog, the exe's are included.
You run the exe with a filename param, it cleans one file at a time.
James Maeding

Chuck Gabriel

  • Guest
Re: Purge Tools
« Reply #16 on: November 19, 2008, 03:17:02 PM »
Did I read that right?  The folks at Autodesk wrote a custom app for you?  How do I get that kind of clout!?

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Purge Tools
« Reply #17 on: November 19, 2008, 06:42:52 PM »
Has anyone done comparative testing with
1) purgeall then add back template layers and dims
2) Purge all layers except the template layers, purge all dims except the template dims.
 
I use the 2nd version in vba, but I have the feeling using Chuck's code and adding back in what I need will be faster.

TJK44

  • Guest
Re: Purge Tools
« Reply #18 on: May 29, 2013, 04:09:28 PM »
Hi Chuck,

Thanks for your routine, it has helped me out a lot.

I found a need to purge nested items which it did not do. I added a loop to PurgeItems to get this to work.

Code - Visual Basic: [Select]
  1. Public Shared Function purgeItems(ByVal db As Database, ByVal tableIds As ObjectIdCollection, ByVal silent As Boolean) As Boolean
  2.             Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  3.             Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  4.             Dim itemsPurged As Boolean = False
  5.  
  6.  
  7.             Using tr As Transaction = db.TransactionManager.StartTransaction()
  8.                 Using docLoc As DocumentLock = doc.LockDocument
  9.                     Dim keepPurging As Boolean = True
  10.                     'loop to purge nested items
  11.                    While keepPurging
  12.                         Dim purgeableIds As New ObjectIdCollection()
  13.                         For Each tableId As ObjectId In tableIds
  14.                             Dim table As SymbolTable = DirectCast(tr.GetObject(tableId, OpenMode.ForRead, False), SymbolTable)
  15.                             For Each recordId As ObjectId In table
  16.                                 purgeableIds.Add(recordId)
  17.                             Next
  18.                         Next
  19.  
  20.                         db.Purge(purgeableIds)
  21.  
  22.                         If purgeableIds.Count <> 0 Then
  23.                             itemsPurged = True
  24.                             For Each id As ObjectId In purgeableIds
  25.                                 Dim record As SymbolTableRecord = DirectCast(tr.GetObject(id, OpenMode.ForWrite), SymbolTableRecord)
  26.                                 Dim recordName As String = record.Name
  27.                                 If Not silent Then
  28.                                     If Not recordName.Contains("|") Then
  29.                                         ed.WriteMessage(vbLf & "Purging " + record.[GetType]().Name & " " & recordName)
  30.                                     End If
  31.                                 End If
  32.                                 record.Erase(True)
  33.                             Next
  34.                         Else
  35.                             keepPurging = False
  36.                         End If
  37.                     End While
  38.                     tr.Commit()
  39.  
  40.                 End Using
  41.             End Using
  42.  
  43.             Return itemsPurged
  44.         End Function
  45.