Thanks for the help.
Here is my code so far:
Public Function SwapLayerContents(ByVal acdocDest As Document, ByVal fname As String, ByVal strSourceLayer As String, ByVal strDestLayer As String, ByVal bCopyBlocks As Boolean) As Boolean
Dim bDone = False
Dim acDestDB As Database = acdocDest.Database
Dim acSourceBlockTable As BlockTable
Dim acSourceModelSpace As BlockTableRecord
Dim acDestBlockTable As BlockTable
Dim acDestModelSpace As BlockTableRecord
Dim acSourceLayerTable As LayerTable
Dim acDestLayerTable As LayerTable
Dim acObjID_New As ObjectIdCollection = New ObjectIdCollection()
Dim acIDMap As IdMapping = New IdMapping()
Try
'Lock Doc
Using acDocLock As DocumentLock = acdocDest.LockDocument()
'DBase
Using acSourceDB As New Database(False, True)
'Start Trans
Using acSourceTrans As Transaction = acSourceDB.TransactionManager.StartTransaction()
acSourceDB.ReadDwgFile(fname, IO.FileShare.Read, True, "")
'Start Trans
Using acDestTrans As Transaction = acDestDB.TransactionManager.StartTransaction()
acSourceBlockTable = acSourceTrans.GetObject(acSourceDB.BlockTableId, OpenMode.ForRead)
acSourceModelSpace = acSourceTrans.GetObject(acSourceBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForRead)
acSourceLayerTable = acSourceTrans.GetObject(acSourceDB.LayerTableId, OpenMode.ForRead)
acDestBlockTable = acDestTrans.GetObject(acDestDB.BlockTableId, OpenMode.ForWrite)
acDestModelSpace = acDestTrans.GetObject(acDestBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
acDestLayerTable = acDestTrans.GetObject(acDestDB.LayerTableId, OpenMode.ForRead)
'Test Layers
If acSourceLayerTable.Has(strSourceLayer) And acDestLayerTable.Has(strDestLayer) Then
For Each acObjID As ObjectId In acSourceModelSpace
Dim acEnt As Entity = acSourceTrans.GetObject(acObjID, OpenMode.ForRead)
If acEnt.Layer = strSourceLayer Then
acObjID_New.Add(acObjID)
End If
Next acObjID
Dim myMap As New IdMapping
'SDK docs seem to suggest that mapping can ignore the layer table here
acSourceDB.WblockCloneObjects(acObjID_New, acDestModelSpace.ObjectId, myMap, DuplicateRecordCloning.Ignore, False)
acDestTrans.Commit()
bDone = True
Else
bDone = False
End If
End Using
End Using
End Using
End Using
Catch ex As Exception
MsgBox("Error " & ex.Message & vbCrLf & vbTab & ex.StackTrace, MsgBoxStyle.Critical)
bDone = False
End Try
Return bDone
End Function
<CommandMethod("swapLayer")> _
Public Sub swapLayer()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim fname As String = "c:\FilesBin\Source.dwg"
ed.WriteMessage(vbCr & "Result = ++{0}--", SwapLayerContents(doc, fname, "SUR_BANK_BOTTOM", "SUR_BANKS", False))
End Sub
Seems to me that I must be missing something basic or coming at this from the totally wrong angle?