Add to current selection when creating new features

08-04-2020 10:51 AM
Occasional Contributor III


I'm using a MapTool to create some custom features to represent Sanitary Service Connections.  The completed line contains a line, with a point on either end.  My code is working fine, but I'd like to keep all of the created features selected.  When I go to create the next service connection, the previous one de-selects.  Is there a way to keep all features selected through the code??

        protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
            var pointCollection = ((Multipart)geometry).Points;
            MapPoint connectionPoint = pointCollection[0];
            MapPoint plugPoint = pointCollection[1];


            QueuedTask.Run(() =>
                if (IntersectsLayer(connectionPoint, gravityMainLayer) == false)
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("The starting point must intersect the GravitySewer layer.", "Error");

                var editOp = new EditOperation();
                editOp.Name = "Create new Sewer Connection";

                var connectionAttributes = new Dictionary<string, object>
                    {"SUBTYPECD", 3 },
                    {"Shape", connectionPoint.Clone() }

                //editOp.Create(sewerFittingsLayer, connectionPoint);
                editOp.Create(sewerFittingsLayer, connectionAttributes);

                var plugAttributes = new Dictionary<string, object>
                    {"SUBTYPECD", 2 },
                    {"Shape", plugPoint.Clone() }
                    //determine ROTATION here also!!

                editOp.Create(sewerFittingsLayer, plugAttributes);

                var lineAttributes = new Dictionary<string, object>
                    {"SUBTYPECD", 1 },
                    {"Shape", GeometryEngine.Instance.ReverseOrientation((Multipart)geometry).Clone() },
                    {"DIAMETER", 50 },                    
                    //determine LENGTH here!!

                editOp.Create(sewerServiceLayer, lineAttributes);

                var result = editOp.Execute();
                if (result != true || editOp.IsSucceeded != true)
                    throw new Exception($@"Edit failed: {editOp.ErrorMessage}");               


            return base.OnSketchCompleteAsync(geometry);
0 Kudos
2 Replies
by Anonymous User
Not applicable

Hey Brian,

Another one for the list im afraid.

The only thing you can automagically control is if created or modified features get exclusively selected through an operation via the SelectNewFeatures and SelectModififiedFeatures methods on EditOperation. This is where we would add a 'Add to' method.

For now you would have to manually track changed features, either through rowevents or editcompleted and add them to the current selection set.

Occasional Contributor III

OK.  Thanks Sean Jones.  I'm rebuilding an old ArcObjects tool I created ages ago to work in ArcGIS Pro.  With ArcObjects all of the features stay selected, regardless of how many you make.  I think it just did special programming from what I remember.  I'll have to go back and look at the code to be sure.

Anyways, "Yes" if something could be added in a future release to "Add to Selection" that would be great.

Thanks again!

0 Kudos