Select to view content in your preferred language

IFeature.set_Value not being saved

1653
7
01-05-2012 01:25 PM
MurraySwanson
Emerging Contributor
Hi all, I am trying to troubleshoot a portion of our program that fires during the onExplode event using arcObjects and C#.net. A user can select, through our custom toolbar, the button "Explode Multi Part Features". We have a bit of code that runs for some other things but the reason for my question is that we have a field called Poly_no that I need to update. (If there are two parts to explode then I want one of the newly created polygon's to be numbered "x" and then each one after to increment accordingly). My code is this:

public void OnExplodeFeatures()
        {
          
           int intPOLY_NO = 0;
           string sPolyNo = string.Empty;
            //Get currently selected files
            IEnumFeature selectedFeatures = RMF93.BLL.EditorHelper.Editor.EditSelection as IEnumFeature;
            selectedFeatures.Reset();
            IFeature pFeat = selectedFeatures.Next();

            if (RMF93.BLL.EditorHelper.intPolyNo == 0) //store poly_no
            {
                sPolyNo = pFeat.get_Value(pFeat.Fields.FindField(Constants.CONST_FLD_POLY_NO)).ToString();
                intPOLY_NO = Convert.ToInt32(sPolyNo);              
                RMF93.BLL.EditorHelper.intPolyNo = intPOLY_NO;
            }
            else
            {
                intPOLY_NO = RMF93.BLL.EditorHelper.intPolyNo;
            }

            string sGUID = pFeat.get_Value(pFeat.Fields.FindField(Constants.CONST_FLD_PK_POLY_GUID)).ToString();
            if (sGUID.Length > 0)
                DeleteDecilesByPolyGUID(sGUID);
            try
            {
                while (pFeat != null)
                {
                    sGUID = "{" + System.Guid.NewGuid().ToString() + "}";

--> This line works all the time
                    pFeat.set_Value(pFeat.Fields.FindField(Constants.CONST_FLD_PK_POLY_GUID), sGUID);
<--

--> This is the line that won't save                   other than the first time through
pFeat.set_Value(pFeat.Fields.FindField(Constants.CONST_FLD_POLY_NO), intPOLY_NO);
<--

                    pFeat = selectedFeatures.Next();
                    RMF93.BLL.EditorHelper.intPolyNo = intPOLY_NO + 1; //Increment Poly_No & store
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLogError(ex.Message);                
            }

        }


I can't figure this out as the other command we have is OnSplit and it works just fine. The field (Poly_No) is editable and in fact I have tried several different fields just to make sure but none will stick. Now the reason why I know I'm doing something wrong is that the first time through the while statement any values I set do stick (GUID always sticks regardless), just the subsequent ones do not (so for the first polygon feature, changes are saved and then when it moves to the next feature part thats when the changes are ignored for the Poly_No only the GUID is fine. My explanation is probaly even more confusing, sorry 😮

Any help or insight would be appreciated tons!!

Cheers
0 Kudos
7 Replies
sapnas
by
Frequent Contributor
If I understood right, I think the issue might be with the RMF93.BLL.EditorHelper.intPolyNo = intPOLY_NO + 1; statement. Either you will have to use RMF93.BLL.EditorHelper.intPolyNo = intPOLY_NO++; to auto increment intPOLY_NO or explicitly store the incremented value to intPOLY_NO.
0 Kudos
MurraySwanson
Emerging Contributor
Thanks for the reply, but changing it has no affect. I think this is an ESRI mystery issues where it errors but doesn't tell me.. 🙂 I have catch statements but its not actually erroring out. So basically I can change any of the field's values the first time it enters the OnExplodeFeatures routine but when it comes through the second time the only value that gets saved is the GUID - nothing else does.
0 Kudos
sapnas
by
Frequent Contributor
can you send the error details?
0 Kudos
JeffGiesler
Deactivated User
Murray,
Try adding pFeat.Store() right after the are you highlighted in red. I have had a problem that sounds similar to this and that's what I forgot to do.
Cheers,
Jeff
0 Kudos
MurraySwanson
Emerging Contributor
Thanks Jeff, I tried that but nothing. The multi-part feature I have is basically 2 polygons so when it goes through the code I've listed twice, once for each polygon. If I change any of the values they will stick for the first pass through, but the second polygon won't save any of my changes other than where I set the GUID. Bizarre...:confused:
0 Kudos
AlexanderGray
Honored Contributor
What field type is the poly_no field?  I notice when you retrieve the value, you convert it to a string first then an integer, then you set the value as an integer.
How is the explode being called?  I am not familiar with an event that specifically listens to explode.  If memory serves me right, when you explode (convert multipart to single part), one feature gets modified and as many new features get created as are parts -1.  I am not sure if the new features are created according to the split policy of the new feature policy.  Most of the time numeric fields have split policies or create policies.  A create policy for the field defines the default value.  A split policy will determine the value of a field according to the split policy.  Split policy could be to duplicate the value, or half a numeric value etc.
Without understanding of the context in which this code is called it is difficult to say, but there could be some esri code executed after this piece of code setting the value to something else.
0 Kudos
MurraySwanson
Emerging Contributor
Thanks for the reply Alexander. For some reason the client does not want to setup a split/merge policy. That would make it easier for sure. As it stands I just made another event that searches for the newly created polygons and changes the poly_no's accordingly. Seems to work well enough but would like to know why changes to the polygons only stick for the first one but not the second one. I'm sure that I am  missing some process or another that I don't fully understand. But Im sure there is some sort of process that I am missing and don't understand. But thanks everyone for your help, I appreciate it!
0 Kudos