Message 1 of 7
Why I can not add Xrecord to DBDictionary
Not applicable
03-29-2018
01:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have simple code that creates an entity and extension dictionary for it.
This procedure I made with Visual Basic 2010 and used it with AutoCAD 2011. It worked fine. When I tried to update my code with Visual Studio 2015 and use it with AutoCAD 2018 it leads to failure of application.
I think that problem occurs when method SatAt is called.
Thank you in advance !
<CommandMethod("Test_Add")> Public Sub Add_XRec()
'' Get the current document and database, and start a transaction
Dim acPoly As Polyline
Dim acDoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Open the Block table record for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead)
'' Open the Block table record Model space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace),
OpenMode.ForWrite)
'' Create a polyline
acPoly = New Polyline()
acPoly.AddVertexAt(0, New Point2d(1, 1), 0, 0, 0)
acPoly.AddVertexAt(1, New Point2d(1, 2), 0, 0, 0)
'acPoly.Closed = False
'' Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPoly)
acTrans.AddNewlyCreatedDBObject(acPoly, True)
Dim exd As DBDictionary
Dim ent As Entity = CType(acTrans.GetObject(acPoly.ObjectId, OpenMode.ForWrite), Polyline)
ent.CreateExtensionDictionary()
exd = acTrans.GetObject(ent.ExtensionDictionary, OpenMode.ForWrite)
'' Create a ResultBuffer and Xrecord
Dim xr As New Xrecord()
Dim buff As New ResultBuffer()
buff.Add(New TypedValue(DxfCode.ExtendedDataAsciiString, "TEXT_1"))
buff.Add(New TypedValue(DxfCode.ExtendedDataAsciiString, "TEXT_2"))
xr.Data = buff
Try
'' Add the new Xrecord to the extension dictionary and the transaction
exd.SetAt("XREC_KEY", xr)
acTrans.AddNewlyCreatedDBObject(xr, True)
Catch ex As System.Exception
acDoc.Editor.WriteMessage(vbLf & ex.Message)
acTrans.Abort()
End Try
'' Save objects to the database
acTrans.Commit()
End Using
End Sub