Public Sub unloadBaseXref(ByVal strName As String)
'get the active document, editor and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acDocEd As Editor = acDoc.Editor
Dim acCurDb As Database = acDoc.Database
'start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction
'create a collection to house the xref object id
Dim colObjId As ObjectIdCollection = New ObjectIdCollection
'open the block table for read
Dim acBlkTbl As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
'step through each record in the table
For Each acObjId As ObjectId In acBlkTbl
'open the block table record for read
Dim acBlkTblRec As BlockTableRecord = acTrans.GetObject(acObjId, OpenMode.ForRead)
'if the current block matches the supplied string
If acBlkTblRec.Name Like strName Then
'and if the current block is loaded
If acBlkTblRec.IsUnloaded = False Then
'add the object id to the collection
colObjId.Add(acBlkTblRec.ObjectId)
'unload the xref in the collection
acCurDb.UnloadXrefs(colObjId)
'document the change
acDocEd.WriteMessage(vbLf & strName & " unloaded")
End If
End If
Next
'commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Sub