Select to view content in your preferred language

Modify feature using VB code on a version

763
1
05-24-2011 09:12 AM
DanNguyen
Emerging Contributor
I wrote some VB code (attached at the end of this post) to change value of a field of a set of selected features.
It works fine when the features is from a local shape file.
When I run it against features from a version, it wipe out all the records in the feature attribute table.
It seems that the pFeature.Store is where that happens.

Does anyone have experience doing similar task and have been successful?

This code basically select all features that that resulted from the query filter, then set the field 'CLEditResponse' for the feature to 3.

Thanks in advance for any help at all.

------------


Sub ChangeCLEditToAbsoluteSelect()

    Dim pLayer As IFeatureLayer
    Dim pFeatureClass As IFeatureClass
    Dim pFeatureCursor As IFeatureCursor
    Dim pFeature As IFeature
   
    Dim pEditTask As IEditTask
    Dim pEditor As IEditor
    Dim pEditSketch As IEditSketch
 
    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pApp As IApplication
   
    Dim pQF As IQueryFilter
    Dim pID As UID
    Dim gLayer As GroupLayer
    Dim LayerList As EnumGPName
           

    'Get the current map
    'Set pDoc = ThisDocument
   
    Set pApp = Application
    Set pDoc = pApp.Document
    Set pMap = pDoc.FocusMap
   
    Set pID = New UID
    pID.Value = "escriEditor.Editor"
    Set pEditor = Application.FindExtensionByCLSID(pID)
    Set pEditTask = GetEditTaskByName(pEditor, "Modify Feature")
    Set pEditor.CurrentTask = pEditTask
    Set pEditSketch = pEditor
   
    Dim STA_ID As String
    Dim enumFeature As IEnumFeature
    Dim feature As IFeature
   
    Dim i As Integer
    Dim Layers(0 To 1) As String
    Layers(0) = "Tap"
    Layers(1) = "Tee"
       
    Set enumFeature = pMap.FeatureSelection
  
    Set feature = enumFeature.Next
    STA_ID = feature.Value(feature.Fields.FindField("EVENTID"))
    pMap.ClearSelection
   
    Dim pFeatureSelect As IFeatureSelection
    Dim pSelectSet As ISelectionSet
   
    Dim pMainActiveView As IActiveView
    Set pMainActiveView = pMap
                       
    Dim pFilter As IQueryFilter
    Set pFilter = New QueryFilter
   
    Dim strQuery As String
    strQuery = "STATIONSERIESEVENTID = '" & STA_ID & "'"
   
    Dim pSelectLayerDef As IFeatureLayerDefinition
   
    For i = LBound(Layers) To UBound(Layers)

        Set pLayer = FindLayerByName(pMap, Layers(i))
        Set pSelectLayerDef = pLayer
        Set pFeatureSelect = pLayer
       
        pFilter.WhereClause = strQuery
       
        pFeatureSelect.SelectFeatures _
        pFilter, esriSelectionResultNew, False
         
        Dim pSelectClass As IFeatureClass
        Set pSelectClass = pLayer.FeatureClass
        
        Dim pFCursor As IFeatureCursor
        Set pFCursor = pSelectClass.Search(pFilter, False)
       
        Set pFeature = pFCursor.NextFeature
             
        Do While Not pFeature Is Nothing
            pFeature.Value(pFeature.Fields.FindField("CLEDITResponse")) = 3
            pFeature.Store
            Set pFeature = pFCursor.NextFeature
       
        Loop
     
    Next
End Sub
0 Kudos
1 Reply
JamesCrandall
MVP Alum
Dan,

Can we assume that you are attempting to update the attributes for features of an ArcSDE Layer?  (you say that the issue occurs with a "version", but not with a shapefile).

This may or may not be the exact resolution to your problems (you say it wipes out all of the rows after it runs), but I do know that if you are attempting to modify or alter SDE data, then you will need to Start and Stop an edit session.

Have you tried to manually start an edit session, then run your code?
0 Kudos