Module Extension
<System.Runtime.CompilerServices.Extension()> _
Public Function ImportSymbolTableRecord(Of T As SymbolTable)(targetDb As Database, sourceFile As String, recordNameAs String) As ObjectId
Using sourceDb As New Database()
sourceDb.ReadDwgFile(sourceFile, System.IO.FileShare.Read, False, "")
Dim sourceTableId As ObjectId, targetTableId As ObjectId
Select Case GetType(T).Name
Case "BlockTable"
sourceTableId = sourceDb.BlockTableId
targetTableId = targetDb.BlockTableId
Exit Select
Case "DimStyleTable"
sourceTableId = sourceDb.DimStyleTableId
targetTableId = targetDb.DimStyleTableId
Exit Select
Case "LayerTable"
sourceTableId = sourceDb.LayerTableId
targetTableId = targetDb.LayerTableId
Exit Select
Case "LinetypeTable"
sourceTableId = sourceDb.LinetypeTableId
targetTableId = targetDb.LinetypeTableId
Exit Select
Case "RegAppTable"
sourceTableId = sourceDb.RegAppTableId
targetTableId = targetDb.RegAppTableId
Exit Select
Case "TextStyleTable"
sourceTableId = sourceDb.TextStyleTableId
targetTableId = targetDb.TextStyleTableId
Exit Select
Case "UcsTable"
sourceTableId = sourceDb.UcsTableId
targetTableId = targetDb.UcsTableId
Exit Select
Case "ViewTable"
sourceTableId = sourceDb.ViewportTableId
targetTableId = targetDb.ViewportTableId
Exit Select
Case "ViewportTable"
sourceTableId = sourceDb.ViewportTableId
targetTableId = targetDb.ViewportTableId
Exit Select
Case Else
Throw New ArgumentException("Requires a concrete type derived from SymbolTable")
End Select
Using tr As Transaction = sourceDb.TransactionManager.StartTransaction()
Dim sourceTable As T = DirectCast(tr.GetObject(sourceTableId, OpenMode.ForRead), T)
If Not sourceTable.Has(recordName) Then
Return ObjectId.Null
End If
Dim idCol As New ObjectIdCollection()
Dim sourceTableRecordId As ObjectId = sourceTable(recordName)
idCol.Add(sourceTableRecordId)
Dim idMap As New IdMapping()
sourceDb.WblockCloneObjects(idCol, targetTableId, idMap, DuplicateRecordCloning.Ignore, False)
tr.Commit()
Return idMap(sourceTableRecordId).Value
End Using
End Using
End Function
End Module