Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
<Assembly: CommandClass(GetType(Rivilis.MyCommands))>
Namespace Rivilis
Public Class MyCommands
<CommandMethod("WBTEST", CommandFlags.Modal)>
Public Sub WbTest()
Using sourceDb As Database = New Database(False, False)
Dim acObjIdCollsource As ObjectIdCollection = New ObjectIdCollection()
Using tr As Transaction = sourceDb.TransactionManager.StartTransaction()
sourceDb.ReadDwgFile("C:\TEMP\test.dwg", FileOpenMode.OpenForReadAndReadShare, True, "")
sourceDb.CloseInput(True)
Dim acBlkTblSourceDoc As BlockTable
acBlkTblSourceDoc = tr.GetObject(sourceDb.BlockTableId, OpenMode.ForRead)
Dim acBlkTblRecSourceDoc As BlockTableRecord
acBlkTblRecSourceDoc = tr.GetObject(acBlkTblSourceDoc(BlockTableRecord.ModelSpace), OpenMode.ForRead)
For Each ObjId As ObjectId In acBlkTblRecSourceDoc
acObjIdCollsource.Add(ObjId)
Next
tr.Commit()
End Using
Dim Doc As Document = Application.DocumentManager.MdiActiveDocument
Dim currentDb As Database = Doc.Database
Dim ed As Editor = Doc.Editor
Using acLckDocCur As DocumentLock = Doc.LockDocument()
Dim bobject As Entity = Nothing
Dim idModel As ObjectId = ObjectId.Null
Using tr = Doc.TransactionManager.StartTransaction()
Dim acBlkTblCurrentDoc As BlockTable =
tr.GetObject(currentDb.BlockTableId, OpenMode.ForRead)
idModel = acBlkTblCurrentDoc(BlockTableRecord.ModelSpace)
Dim acBlkTblRecCurrentDoc As BlockTableRecord =
tr.GetObject(idModel, OpenMode.ForRead)
For Each ObjId As ObjectId In acBlkTblRecCurrentDoc
bobject = tr.GetObject(ObjId, OpenMode.ForWrite)
bobject.Erase(True)
Next
tr.Commit()
End Using
Dim acIdMap As IdMapping = New IdMapping()
sourceDb.WblockCloneObjects(acObjIdCollsource, idModel, acIdMap, DuplicateRecordCloning.Replace, False)
Using tr = Doc.TransactionManager.StartTransaction()
For Each pair As IdPair In acIdMap
Dim id As ObjectId = pair.Value
If (id.ObjectClass.IsDerivedFrom(RXClass.GetClass(GetType(Dimension)))) Then
Dim d As Dimension = tr.GetObject(id, OpenMode.ForWrite)
d.RecomputeDimensionBlock(True)
End If
Next
tr.Commit()
End Using
End Using
End Using
End Sub
End Class
End Namespace