- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Trying my first few tentative steps with coding for AutoCad with .NET, I am a NOOB.
I have several objects in my drawing with object data attached. I am trying to read through the object data, but the code does not seem to find it. The below code fails the check at 'If (extensionDict IsNot Nothing AndAlso extensionDict.Contains("ACAD_OBJECT_DATA"))', I would expect this not to fail if there is ObjectData.
Can anyone explain why I am not seeing what I am expecting?
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Namespace AutoCADObjectDataReader
Public Class TemplateClass
<CommandMethod("ReadObjectData")>
Public Sub ReadObjectData()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
'ed.WriteMessage("Starting" & vbCrLf)
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim modelSpace As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead)
For Each entityID As ObjectId In modelSpace
Dim MyEntity As Entity = tr.GetObject(entityID, OpenMode.ForRead)
'Check If the entity has extended data
If (MyEntity IsNot Nothing AndAlso MyEntity.ExtensionDictionary.IsValid) Then
Dim extensionDict As DBDictionary = tr.GetObject(MyEntity.ExtensionDictionary, OpenMode.ForRead)
'Check If the entity's extension dictionary contains object data
If (extensionDict IsNot Nothing AndAlso extensionDict.Contains("ACAD_OBJECT_DATA")) Then
Dim MyxRecord As Xrecord = tr.GetObject(extensionDict.GetAt("ACAD_OBJECT_DATA"), OpenMode.ForRead)
'Check If the Xrecord Is valid And has data
If (MyxRecord IsNot Nothing AndAlso MyxRecord.Data IsNot Nothing) Then
Dim MyresultBuffer As ResultBuffer = MyxRecord.Data
Dim values As TypedValue() = MyresultBuffer.AsArray()
'Output the Object data To the console
'Dim value As TypedValue
For Each value As TypedValue In values
ed.WriteMessage(value.Value.ToString() & vbCrLf)
Next
Else
ed.WriteMessage("MyxRecord is empty or not valid" & vbCrLf)
End If
Else
ed.WriteMessage("extensionDict is empty or not valid" & vbCrLf)
End If
Else
ed.WriteMessage("MyEntity is empty or not valid" & vbCrLf)
End If
Next
End Using
End Sub
End Class
End Namespace
Solved! Go to Solution.