Message 1 of 10
Trying to Insert Block - Error on ReadDWG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm trying to insert a dynamic block w/attributes in to a drawing where a reference doesn't already exist. I have got some code off of here (Thanks who ever wrote it.)
Here is what I'm running:
Public Sub InsertBlock(ByVal ActiveDoc As Document, ByVal blockname As String)
Dim CompleteFilePath As String
CompleteFilePath = HostApplicationServices.Current.FindFile(blockname & ".dwg", ActiveDoc.Database, FindFileHint.Default)
'Using
Dim tempdb As Database = New Database(False, False)
Try
tempdb.ReadDwgFile(CompleteFilePath, System.IO.FileShare.ReadWrite, True, Nothing)
'Using
Dim t As Transaction = ActiveDoc.TransactionManager.StartTransaction
Try
Dim idBTR As ObjectId = ThisDrawing.Database.Insert(blockname, tempdb, False)
Dim bt As BlockTable = CType(t.GetObject(ActiveDoc.Database.BlockTableId, DatabaseServices.OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = CType(t.GetObject(bt(BlockTableRecord.ModelSpace), DatabaseServices.OpenMode.ForWrite), BlockTableRecord)
Dim origin As acad.Geometry.Point3d = New acad.Geometry.Point3d(0, 0, 0)
'Using
Dim bref As BlockReference = New BlockReference(origin, idBTR)
Try
btr.AppendEntity(bref)
t.TransactionManager.AddNewlyCreatedDBObject(bref, True)
Finally
CType(bref, IDisposable).Dispose()
End Try
t.Commit()
t.Dispose()
Finally
CType(t, IDisposable).Dispose()
End Try
Finally
CType(tempdb, IDisposable).Dispose()
End Try
End Sub
There error always happens on the db.readdwg sub.
I get Error Number: -2147467261
Error Description: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
The block I'm trying to insert was a block that had been wblocked, then had dynamic properties added. I can also open the block with or without blockeditor with no errors, and I'm able to insert the block with no errors either.
Thanks,
Adam Edmonds
I'm trying to insert a dynamic block w/attributes in to a drawing where a reference doesn't already exist. I have got some code off of here (Thanks who ever wrote it.)
Here is what I'm running:
Public Sub InsertBlock(ByVal ActiveDoc As Document, ByVal blockname As String)
Dim CompleteFilePath As String
CompleteFilePath = HostApplicationServices.Current.FindFile(blockname & ".dwg", ActiveDoc.Database, FindFileHint.Default)
'Using
Dim tempdb As Database = New Database(False, False)
Try
tempdb.ReadDwgFile(CompleteFilePath, System.IO.FileShare.ReadWrite, True, Nothing)
'Using
Dim t As Transaction = ActiveDoc.TransactionManager.StartTransaction
Try
Dim idBTR As ObjectId = ThisDrawing.Database.Insert(blockname, tempdb, False)
Dim bt As BlockTable = CType(t.GetObject(ActiveDoc.Database.BlockTableId, DatabaseServices.OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = CType(t.GetObject(bt(BlockTableRecord.ModelSpace), DatabaseServices.OpenMode.ForWrite), BlockTableRecord)
Dim origin As acad.Geometry.Point3d = New acad.Geometry.Point3d(0, 0, 0)
'Using
Dim bref As BlockReference = New BlockReference(origin, idBTR)
Try
btr.AppendEntity(bref)
t.TransactionManager.AddNewlyCreatedDBObject(bref, True)
Finally
CType(bref, IDisposable).Dispose()
End Try
t.Commit()
t.Dispose()
Finally
CType(t, IDisposable).Dispose()
End Try
Finally
CType(tempdb, IDisposable).Dispose()
End Try
End Sub
There error always happens on the db.readdwg sub.
I get Error Number: -2147467261
Error Description: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
The block I'm trying to insert was a block that had been wblocked, then had dynamic properties added. I can also open the block with or without blockeditor with no errors, and I'm able to insert the block with no errors either.
Thanks,
Adam Edmonds