Can't access all annotation fields (feature cursor)?

703
6
01-25-2013 05:06 PM
WesBailes
New Contributor III
Obviously all tabular fields are typically available for read/write in a ifeaturecursor>ifeature object but the only ones available from an annotation feature class are the OBJECTID and FEATUREID.  How do I access others?  Thanks!
0 Kudos
6 Replies
WesBailes
New Contributor III
bump...Suggestions anyone?  Thanks!
0 Kudos
JeffMatson
Occasional Contributor III
Where is the annotation stored (SDE, file gdb, etc.)?

Are all the fields visible when using arcCatalog or arcMap?


bump...Suggestions anyone?  Thanks!
0 Kudos
WesBailes
New Contributor III
Doesn't seem to matter.  I have tried both SDE and File GDB.  This code throws an error on the third iteration through the loop.  The first iteration yields the OBJECTID, the second the FEATUREID.  And yes, all fields are accessible through catalog and arcmap. 


        Dim pMap As IMap = My.ArcMap.Document.FocusMap
        Dim pPIDLayer As IFeatureLayer = pMap.Layer(0)
        Dim pPIDFClass As IFeatureClass = pPIDLayer.FeatureClass
        Dim pPIDFCursor As IFeatureCursor = pPIDFClass.Search(Nothing, False)
        Dim pPIDFeature As IFeature = pPIDFCursor.NextFeature
        For i As Integer = 0 To 5
            MsgBox(pPIDFeature.Value(i))
        Next
0 Kudos
AlexanderGray
Occasional Contributor III
yeah that code is not going to work...  The messagebox call does an implicit cast of the value in the field to a string (calls default toString method.)  However if the value in the field is a null (dbnull.value) or a value that does not have a tostring method (i.e. geometry, blob, raster...), you will get an error for sure.

Dim pMap As IMap = My.ArcMap.Document.FocusMap
Dim pPIDLayer As IFeatureLayer = pMap.Layer(0)
Dim pPIDFClass As IFeatureClass = pPIDLayer.FeatureClass
Dim pPIDFCursor As IFeatureCursor = pPIDFClass.Search(Nothing, False)
Dim pPIDFeature As IFeature = pPIDFCursor.NextFeature
For i As Integer = 0 To 5
  if pPIDFeature.fields.field(i).type <> esriFieldTypeGeometry  andalso _
   pPIDFeature.fields.field(i).type <>esriFieldTypeBlob andalso _
   pPIDFeature.fields.field(i).type <>esriFieldTypeRaster andalso _
   pPIDFeature.Value(i) isnot system.dbnull.value then
    MsgBox(pPIDFeature.Value(i))
end if
Next

The code above assumes the table has more than 6 fields, otherwise it will also fail.  If you check the field types on the featureclass before doing the search, you can pass in a query filter with only the field names in the subfields that can be converted to a string and only query those fields.  You still have to check for nulls though...

One last thing, when posting to the forum that you have 'an error' it is useful to the forum to post the exact error message, that cuts out a lot of guessing.
0 Kudos
JeffMatson
Occasional Contributor III
You might be getting a type mismatch or something similar if you're trying to send the Shape field to a message box?

Doesn't seem to matter.  I have tried both SDE and File GDB.  This code throws an error on the third iteration through the loop.  The first iteration yields the OBJECTID, the second the FEATUREID.  And yes, all fields are accessible through catalog and arcmap. 


        Dim pMap As IMap = My.ArcMap.Document.FocusMap
        Dim pPIDLayer As IFeatureLayer = pMap.Layer(0)
        Dim pPIDFClass As IFeatureClass = pPIDLayer.FeatureClass
        Dim pPIDFCursor As IFeatureCursor = pPIDFClass.Search(Nothing, False)
        Dim pPIDFeature As IFeature = pPIDFCursor.NextFeature
        For i As Integer = 0 To 5
            MsgBox(pPIDFeature.Value(i))
        Next
0 Kudos
WesBailes
New Contributor III
Thanks for all of the suggestions!  I honestly don't know what I had done to not be able to edit those fields but I am now able to.  Appreciate all of the help!
0 Kudos