I have the following where BK2 is a filename including path:
Code:
Try
Dim destName As String = SymbolUtilityServices.GetSymbolNameFromPathName(BK2, "dwg")
destName = SymbolUtilityServices.RepairSymbolName(destName, False)
' Create a source database to load the DWG into
Using db As New Database(False, True)
' Read the DWG into our side database
db.ReadDwgFile(BK2, FileOpenMode.OpenTryForReadShare, True, "")
' Insert it into the destination database as
' a named block definition
Dim btrId As ObjectId = destDb.Insert(destName, db, False)
' If an annotative block, open the resultant BTR
' and set its annotative definition status
Dim tr As Transaction = destDb.TransactionManager.StartTransaction()
Using tr
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(btrId, OpenMode.ForWrite), BlockTableRecord)
tr.Commit()
End Using
End Using
Catch ex As System.Exception
ed.WriteMessage(vbLf & "Problem importing ""{0}"": {1} - file skipped.", BK2, ex.Message)
End Try
OR EVEN
Dim BK2 As String = "F:\" & "Somepath" & ".dwg"
Dim doc As Document = DocumentManager.MdiActiveDocument
Dim tCmd As String = "-INSERT" & vbCr & BK2 & vbCr
doc.SendStringToExecute(tCmd, True, True, True)
I get a crash on:
Dim btrId As ObjectId = destDb.Insert(destName, db, False) in the 1st item
OR I get a crash during the sendstringtoexecute in the 2nd, I am lost to what is going on...
the error is eLockViolation - File Skipped
Any ideas?