0

I am try to export field and X Y but I get the following error. Is it possible for someone to help me with this?

system.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Geometry.IPoint'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{1B077915-38C5-11D0-92D2-00805F7C28B0}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

The Code:

Dim delimiter As String = ","
Dim aFileName As String
aFileName = "c:\log.txt"
Dim pPt As IPoint

FileOpen(1, aFileName, OpenMode.Output, OpenAccess.Default, OpenShare.Shared)

' Get first layer in map which is the annotation layer
Dim pMXDocument As IMxDocument
'  pMXDocument = My.ArcMap.Document.ActiveView
pMXDocument = My.ArcMap.Document

Dim pMap As IMap
pMap = pMXDocument.FocusMap
Dim pLayer As ILayer
pLayer = pMap.Layer(0)
Dim pFeatureLayer As IFeatureLayer
pFeatureLayer = pLayer

' Create a cursor
Dim pFtrCsr As IFeatureCursor
pFtrCsr = pFeatureLayer.Search(Nothing, False)

' loop printing text string
Dim s As String
Dim pFtr As IFeature
pFtr = pFtrCsr.NextFeature
Do While Not pFtr Is Nothing
   ' On Error Resume Next
    pPt = pFtr.Shape

    s = CStr(pFtr.Value(pFtr.Fields.FindField("TEXTSTRING"))) + "," + CStr(pPt.X) + "," + CStr(pPt.Y)

    '  s = pFeature.Value(pFeature.Fields.FindField("TEXTSTRING"))
    '  Debug.Print(s)

    WriteLine(1, s)

    pFtr = pFtrCsr.NextFeature
Loop

FileClose(1)
1

I believe the problem is that you are assuming your annotation is a point which is causing an invalid cast exception.

If you cast your pFtr into an IAnnotationFeature2 you can get to the geometry of the Element.

Dim pAnnotationFeature2 As IAnnotationFeature2
pAnnotationFeature2 = pFtr
msgbox(str(pAnnotationFeature2.Annotation.Geometry.GeometryType))

In my test data it was returning a 3 for geometry type which is a polyline. I don't know if an Annotation geometry is always a polyline, may be someone else can confirm this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.