I'm attempting to read XRecord data that was written by another application. I can see it in the DXF file if I export, but Ive had no luck trying to get the name of the owning dictionary. I tried 'peeking' at it using DBView, and it crashes autocad with a "not open for write" error.
I wrote up a routine that grabs the ObjectID of XRecords during the Object.Modified event, and "catch them" as they pass by, when the entities that are using the XRecords get modified. When all the events are 'over', I ran a second routine to get the XRecord objects from the ObjectID's, and tried traversing up the parent tree to the Dictionary. While the XRecord objects seem to be ok, (in that I can get their NAME property, anyway), the routine tanks when it tries to get the name of the parent Dictionary. I pass the routine below, and ObjectID of an XRecord.
The error is "Run-time error '-2145386494 (80200002)':"
' "Not applicable"
Sub getDictName(lngXRecID As Long)
' attempts to get owner dictionary name, if passed the
' object ID of an xrecord. Runs fine until I attempt to
' get the name of the dictionary, then returns the following error:
' "Run-time error '-2145386494 (80200002)':"
' "Not applicable"
Dim objTmp As AcadObject
Dim objXRec As AcadXRecord
Dim lngOwnerID As Long
Dim objDict As AcadDictionary
Set objTmp = ThisDrawing.ObjectIdToObject(lngXRecID)
If objTmp Is Nothing Then
Debug.Print "No Object found for ObjectID"
Exit Sub
End If
' make sure its an Xrecord
If Not (objTmp.ObjectName = "AcDbXrecord") Then
Debug.Print "passed ObjectID was not for an XRecord"
Exit Sub
Else
Set objXRec = objTmp ' set into XRecord Object
Debug.Print "XRecord name is "; objXRec.Name
End If
' get the owner of the XRecord
lngOwnerID = objXRec.OwnerID
Set objTmp = ThisDrawing.ObjectIdToObject(lngOwnerID)
' make sure its a dictionary
If Not (objTmp.ObjectName = "AcDbDictionary") Then
Debug.Print "Owner of XRecord was not a Dictionary"
Else
' set into Dictionary Object
Set objDict = objTmp
' get a "Not applicable" error messager here
Debug.Print "The Dictionary name is "; objDict.Name
End If
End Sub
Im hoping to get the owning Dictionary, so I can see all of the available XRecords.
Its only string data, should be easy enough to return. or am I going about this the wrong way?
is there another way to get the Dictionary name? Is the dictionary name even needed ?
... perplexed in Poughkeepsie