Export Annotation features from ArcSDE to Personal Geodatabase Feature Class

791
2
Jump to solution
05-22-2014 08:11 AM
NikkiSmith
New Contributor
Hi

I'm trying to export some annotation data out of ArcSDE into an annotation feature class in a personal geodatabase and I'm stuck. I've cloned the ArcSDE feature class to create a new feature class in the personal geodatabase and now I need to get the data into the new feature class so I'm trying to use an insert cursor but it throws an error on the following line

pFBuffer.Value(pFBuffer.Fields.FindField(i)) = pFeat.Value(pFeat.Fields.FindField(i))

the error I get states that 'the Index passed was not in the valid range'

If anyone has any ideas they would be much appreciated - or if I'm going about this in totally the wrong then suggestions for a better way would also be welcome.

Thanks

The section of my code is below:-


If pFeatClass.FeatureType = esriFeatureType.esriFTAnnotation Then
                    'code to export annotation which needs to be handled differently

                    If OutputFeatureClassName = "MapFaceNote" Then
                        Call CloneAnnoFeatureClass(pFeatClass, MDBworkspace, OutputFeatureClassName)

                        pNewFeatClass = OpenFeatureClass(MDBworkspace, OutputFeatureClassName)

                        pFeatCursor = pFeatClass.Search(Nothing, False)

                        pFeat = pFeatCursor.NextFeature

                  
                        Do Until pFeat Is Nothing
                            pInsertCursor = pNewFeatClass.Insert(True)
                            pFBuffer = pNewFeatClass.CreateFeatureBuffer

                            For i = 0 To pFBuffer.Fields.FieldCount - 1
                                If pFBuffer.Fields.Field(i).Editable Then
                             
                                    pFBuffer.Value(pFBuffer.Fields.FindField(i)) = pFeat.Value(pFeat.Fields.FindField(i))
                        
                                End If
                            Next i
                            pInsertCursor.InsertFeature(pFBuffer)
                            pInsertCursor.Flush()
                 
                            pFeat = pFeatCursor.NextFeature
                        Loop

                    End If
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
There are several things wrong with this line of code:

pFBuffer.Value(pFBuffer.Fields.FindField(i)) = pFeat.Value(pFeat.Fields.FindField(i))

First and foremost, the FindField method takes a field name for a parameter.  You're passing in a field index.  Second, you don't need to call FindField on both the feature and the feature buffer.  Last, you should always check the field index returned by FindField to make sure it isn't -1 (which means the field was not found).  Your code should look something like this.  I just typed this in off the top of my head so you may have to tweak it some.

For i = 0 To pFBuffer.Fields.FieldCount - 1     Dim field as IField = pFBuffer.Fields.Field(i)     Dim fieldName as String = field.Name     If field.Editable Then         Dim index as Int32 = pFeat.Fields.FindField(fieldName)         If index <> -1 Then pFBuffer.Value(i) = pFeat.Value(index)     End If Next i

View solution in original post

0 Kudos
2 Replies
NeilClemmons
Regular Contributor III
There are several things wrong with this line of code:

pFBuffer.Value(pFBuffer.Fields.FindField(i)) = pFeat.Value(pFeat.Fields.FindField(i))

First and foremost, the FindField method takes a field name for a parameter.  You're passing in a field index.  Second, you don't need to call FindField on both the feature and the feature buffer.  Last, you should always check the field index returned by FindField to make sure it isn't -1 (which means the field was not found).  Your code should look something like this.  I just typed this in off the top of my head so you may have to tweak it some.

For i = 0 To pFBuffer.Fields.FieldCount - 1     Dim field as IField = pFBuffer.Fields.Field(i)     Dim fieldName as String = field.Name     If field.Editable Then         Dim index as Int32 = pFeat.Fields.FindField(fieldName)         If index <> -1 Then pFBuffer.Value(i) = pFeat.Value(index)     End If Next i
0 Kudos
NikkiSmith
New Contributor
Dear Niel

Thank you so much - I did have code very similar to that in my first iteration but it didn't work and in the process of trying to make it work I clearly did something very daft (doh!!)!! All working perfectly now - hurrah!!!

Many thanks
Nikki
0 Kudos