Imports CAD_DBS = Autodesk.AutoCAD.DatabaseServices
Public sub MY_TEST(byval FileName as String)
Dim db As CAD_DBS.Database = FUNC_OPEN_DATABASE(FileName)
If (db IsNot Nothing) Then
Using tr As CAD_DBS.Transaction = db.TransactionManager.StartTransaction
Dim bt As CAD_DBS.BlockTable = tr.GetObject(db.BlockTableId, CAD_DBS.OpenMode.ForWrite)
Dim btr As CAD_DBS.BlockTableRecord = tr.GetObject(bt(CAD_DBS.BlockTableRecord.ModelSpace), CAD_DBS.OpenMode.ForWrite)
For Each id As CAD_DBS.ObjectId In btr
Dim Ent As CAD_DBS.DBObject = tr.GetObject(id, CAD_DBS.OpenMode.ForWrite)
' что-то делаю с объектом Ent
Next
tr.Commit()
End Using
db.CloseInput(True)
db.SaveAs(Fn, CAD_DBS.DwgVersion.Current) ' 2016.05.19
db.Dispose()
End If
End Sub
Public Function FUNC_OPEN_DATABASE(byval Fn As String) As CAD_DBS.Database
Dim db As CAD_DBS.Database = Nothing
Try
db = New CAD_DBS.Database
Catch ex As Exception
Return Nothing
End Try
Try
db.ReadDwgFile(Fn, IO.FileShare.ReadWrite, False, Nothing)
Return db
Catch ex As System.Exception
MsgBox("Не могу прочитать базу чертежа " & vbCrLf & Fn & ex.Message)
db.Dispose()
Return Nothing
End Try
End Function