Select to view content in your preferred language

EditOperation in 3.0 not working as expected

1088
8
Jump to solution
02-27-2023 11:38 AM
BrianBulla
Regular Contributor II

Hi,

So the following code works in 2.8.  Basically it works with the selected features, performs some calculations, and then updates a field on each selected feature.  For some reason in 3.0, only one of the selected feature s gets updated.  It goes like this:

 

//Create an Inspector to edit the selected features
                        var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();

                        //Loop through each selected OID
                        foreach (var oid in selectedOIDs)
                        {
                            insp.Load(gravitySewerLayer, oid);

                            fromMHElevation = 0;
                            toMHElevation = 0;
                            
                            //Check if the feature has NULL for either invert.  If so, skip and go to next.
                            if ((insp["UPSTREAMINVERT"].Equals(System.DBNull.Value)) || (insp["DOWNSTREAMINVERT"].Equals(System.DBNull.Value)))
                            {
                                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(insp["FACILITYID"].ToString() + "  is missing required invert information.", "Error");
                            }
                            else
                            {
                                //Get the To and From point of the currently selected feature
                                var pointCollection = ((Multipart)insp.Shape).Points;
                                MapPoint fromPoint = pointCollection[0];
                                MapPoint toPoint = pointCollection[pointCollection.Count - 1];

                                //check to make sure the mahole ELEVATION has a value before proceeding

                                if ((GetIntersectingFeature(fromPoint, sanManholeLayer, "ELEVATION") == null) || (GetIntersectingFeature(toPoint, sanManholeLayer, "ELEVATION") == null))
                                {
                                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(insp["FACILITYID"] + " has no intersecting TO/FROM Manhole, or the TO/FROM Manhole has a NULL 'ELEVATION' value.", "No Manhole data found");
                                }
                                else
                                {
                                    //Find the ELEVATION of both manholes that intersects the ends of the gravity main                                
                                    double fromMHELevation = Convert.ToDouble(GetIntersectingFeature(fromPoint, sanManholeLayer, "ELEVATION"));
                                    double toMHELevation = Convert.ToDouble(GetIntersectingFeature(toPoint, sanManholeLayer, "ELEVATION"));

                                    avgDepth = ((toMHELevation + fromMHELevation) / 2) - ((Convert.ToDouble(insp["UPSTREAMINVERT"].ToString()) + Convert.ToDouble(insp["DOWNSTREAMINVERT"].ToString())) / 2);

                                    insp["EST_AVG_DEPTH"] = avgDepth;
                                    editOperation.Modify(insp);
                                    updatedFeatures++;
                                }
                            }

                        }

                        if (editOperation.Execute() == true)
                            ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(updatedFeatures.ToString() + " features updated.", "Sani. Avg. Depth Tool - Update Complete");
                        else
                            ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(editOperation.ErrorMessage.ToString() + "\n" + "\n" + "Please try again using the current selection.  If the problem persists, let Brian know.", "Sani. Avg. Depth Tool - ERROR");

 

Any ideas what might be going wrong?  I have gone through all the "Migrate to Pro" steps, so I do not think that is an issue.  The project compiles fine and will run in debug mode with no errors.  It's just that the Edit Operation only seems to be editing the final selected feature that is processes.

 

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

We have reported case to Esri support about the same behavior. It has bug status (BUG-000153876)

View solution in original post

8 Replies
CharlesMacleod
Esri Regular Contributor

i suspect it is because u hv one inspector that u r loading/reloading in the loop. Try passing the attributes inside a dictionary to the modify instead....something like:

 

 

//use attribute dictionary
var dict_attrib = new Dictionary<string, object>();
dict_attrib["EST_AVG_DEPTH"] = insp["EST_AVG_DEPTH"];
editOp.Modify(gravitySewerLayer, oid, dict_attrib);

 

[assuming Modify makes a copy of your dictionary when u call it....which i think it does....otherwise the "new" has to go outside the loop and u wld hv to hang on to the dict reference(s).....e.g. var list_dict = new List<Dictionary<string,object>>();]

BrianBulla
Regular Contributor II

Hi Charles,

Thanks, I will give that a go, but do you know if there is something specific to 3.0 that might be the issue?  This exact same code has been working in 2.8 for years.  I use this same looping/EditOperation strategy in many of my tools I've created for 2.8 and never had any issues.

This is the first tool I am converting to 3.0 and I'm only now seeing issues.  I haven't seen anything online about EditOperation working differently in 3.0.

0 Kudos
CharlesMacleod
Esri Regular Contributor

right, no, sorry, i don't. could be that at 2.x the internals were likewise making a copy of the (internal) inspector attribute collection in the Modify call but are now just holding a reference (as an optimization of sorts)....that's a guess just based on the change in behavior u r seeing tho.

GKmieliauskas
Esri Regular Contributor

Hi,

We have reported case to Esri support about the same behavior. It has bug status (BUG-000153876)

BrianBulla
Regular Contributor II

Hi....just wondering if there is a fix for this yet in 3.0.....or even in 3.1??  I only have access to 3.0 currently.

I am converting another tool from 2.9 to 3.0, but having issues with the EditOperation working, again using the .Modify:

await QueuedTask.Run(() =>
                {
                    Map map = MapView.Active.Map;

                    //Create the MAIN edit operation....this will show up on the Undo Stack
                    var editOperation = new ArcGIS.Desktop.Editing.EditOperation();
                    editOperation.Name = "Multi-Layer Attribute Update Tool";
                    editOperation.EditOperationType = ArcGIS.Desktop.Editing.EditOperationType.Long;

                    var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();

                    //Go through each layer in the Layers listbox
                    foreach (string layer in lstLayers.Items)
                    {
                        var currentLayer = map.FindLayers(layer).FirstOrDefault() as BasicFeatureLayer;
                        var selection = currentLayer.GetSelection();
                        IReadOnlyList<long> selectedOIDs = selection.GetObjectIDs();

                        inspector.Clear();
                        inspector.Load(currentLayer, selectedOIDs);

                        foreach (var finalListRow in finalList)
                        {
                            if (finalListRow.FieldValue != null)
                                inspector[finalListRow.FieldName.ToString()] = finalListRow.FieldValue.ToString();
                        }

                        editOperation.Modify(inspector);
                    }

                    //Finished the layer loop....commit all the edits
                    if (!editOperation.IsEmpty)
                    {
                        bool result = editOperation.Execute();
                        if (!result)
                            MessageBox.Show("ERROR");
                    }
                });  //end of QueuedTask

 

Thanks,

0 Kudos
BrianBulla
Regular Contributor II

Thanks for posting a link to the bug.  So, with most of my editing tools, I follow the same process, and so far with my code upgrade to 3.0, none of them have worked.  But today I updgraded one and it actually did work.  The only difference was that it only edited geometry on each feature....no attribute editing.  Hopefully the bug fix above will solve the problems.

This code here, using .Modify, seems to be working in 3.0 for all selected features it's run on.  But only editing geometry.

 

 

// start the EditOperation
                var modifyAsBuilts = new EditOperation();
                modifyAsBuilts.Name = "Move As-Builts and Site Plans";

                // Get any selected OIDs for the layer, and move each point to the mouse click point (geometry).
                if (asBuiltLayer != null)
                {
                    var selectedAB = asBuiltLayer.GetSelection();
                    IReadOnlyList<long> selectedAsbuiltOIDs = selectedAB.GetObjectIDs();

                    foreach (var oid in selectedAsbuiltOIDs)
                    {                        
                        modifyAsBuilts.Modify(asBuiltLayer, oid, geometry);
                        abCount++;
                    }
                }

// End the edit operation - move the selected As-Built and/or Site Plan points
                modifyAsBuilts.Execute();

 

 

 

0 Kudos
BrianBulla
Regular Contributor II

After finally getting back to this, I can confirm that the BUG fix for this is working.....yeah!!

0 Kudos