Thrown together but working:
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Public Class Class1
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Private CurrentDoc As Document
Private Shared Sub m_doc_CommandWillStart(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
Dim curdb As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = curdb.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
Try
Dim LayerId As ObjectId
Dim LT As LayerTable = myT.GetObject(curdb.LayerTableId, OpenMode.ForRead)
LayerId = LT.Item("0")
curdb.Clayer = LayerId
myT.Commit()
Catch ex As Exception
myT.Abort()
System.Windows.Forms.MessageBox.Show("An error ocurred...", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)
Finally
myT.Dispose()
End Try
End Sub
Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
CurrentDoc = Application.DocumentManager.MdiActiveDocument
'This will make the function only available to the document use used netload on.
'It's up to you to keep up to date as you switch drawings.
AddHandler CurrentDoc.CommandWillStart, AddressOf m_doc_CommandWillStart
End Sub
Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
End Sub
End Class
Ronnie Wilkins, Jr.