Message 1 of 5
Problem with getting XData between VB6 and .NET
Not applicable
03-21-2011
12:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In my application we have a hidden block in the drawing with the name MyCAD.Info
The XData stores information that pertains to the entire drawing. The most import of which is a unique Drawing ID.
WIth the VBA interface I get the XData easily both under VB6 and using interop under .NET.
Dim mApp As AcadApplication = CType(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, Autodesk.AutoCAD.Interop.AcadApplication)
Dim mDoc As AcadDocument = mApp.ActiveDocument
Dim mDocBlock As AcadBlock = mDoc.Blocks.Item("MyCAD.Info")
Dim xDataType As Object = Nothing
Dim xData As Object = Nothing
mDocBlock.GetXData("MyCAD", xDataType, xData)xData returns all the data that I expected.
But when when I try using the .NET API I get nothing
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Using tr As Transaction = db.TransactionManager.StartTransaction 'OpenTransaction()
Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead), BlockTableRecord)
Dim it As BlockTableRecordEnumerator = btr.GetEnumerator()
While it.MoveNext()
Dim obj As DBObject = GetObject(it.Current, OpenMode.ForRead, tr)
If obj IsNot Nothing Then
Dim br As BlockReference = TryCast(obj, BlockReference)
If br IsNot Nothing Then
Dim TempS As String = br.Name
If br.Name = "MyCAD.Info" Then
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbNewLine + TempS + vbNewLine)
TempS = "=================================================="
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbNewLine + TempS + vbNewLine)
Dim rb As ResultBuffer = obj.XData()
If rb IsNot Nothing Then
For Each tv As TypedValue In rb
TempS = tv.Value.ToString
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbNewLine + TempS + vbNewLine)
Next
End If
TempS = "=================================================="
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbNewLine + TempS + vbNewLine)
End If
End If
End If
End While
End Using
Tracing through this, it finds the block but the XData is empty. I wonder is the place that GetXData of VBA is pulling from the same place as the XData method.