Detecting which Modify Operation is running

535
7
11-28-2018 01:52 PM
MKa
by
Occasional Contributor III

In my module code, I attempt to stop users from deleting more than one feature at a time using this logic, which has always worked

protected async static void OnRowDeleteEvent(RowChangedEventArgs args)
        {
            try
            {
                // get the currently selected features in the map
                int selectedCount = await FeatureServiceManagement.GetMapSelectionCount();
                int selectedFeatureCount = await FeatureServiceManagement.GetMapFeatureSelectionCount();
                if (selectedCount > 1 || selectedFeatureCount > 1)
                {
                    //CANCEL the Delete
                    args.CancelEdit(() => DeleteMultipleError());
                    return;
                }
.
.
.

However, I need to allow a user to use the MERGE functionality/tool from the modify features toolset.  the merge tool requires one or more of the selected features to be deleted, the problem is that my code above prevents that deletion (as 2 features are selected).  I want to determine if the merge tool has been clicked and by pass my logic if that tool has been initiated.  However whenever I call FrameworkApplication.ActiveTool it just returns the Select tool that I previously had selected, not the tool I clicked in the Modify Features window.  How do I get the name of the Modify features tool selected from my Module code.

0 Kudos
7 Replies
MKa
by
Occasional Contributor III

I wonder if anyone has looked into this.  Since I need to prevent any deletes of multiple features at all times, I need to be able to detect which construction tool is currently being used.  I need to be able to use the Merge tool.  Since the Merge tool requires you to select two or more features, my delete logic fails as it thinks you are deleting more than one feature.  I could prevent this logic from being hit, or bypass it, by knowing that the tool being used is the esri_editing_MergeFeatures tool.  But when i ask for the active tool, it always comes up with selection or whatever tool was previously selected before the Contruction tool was chosed.ArcGIS Pro SDK

0 Kudos
by Anonymous User
Not applicable

Architecturally, Merge is a command as it doesn't require any interaction from the map. The selection tool is activated as a convivence to change the selection as an input for merge. Clip is the same.

The split tool by comparison is a tool as it requires you to point at something on the map to split (for lines) or sketch a splitting line (for polygons/lines). The selection 'tool' on the split pane is a mode of the split tool which allows you to change the selection for convenience. Notice it has a different icon from the regular selection tool.

Currently there's no public way to tell what operation is calling the row events. At 2.4 the calling editoperation will be passed down to the row events so you could query the editoperation name, which in this case would be "Merge Features".

0 Kudos
MKa
by
Occasional Contributor III

Is this possible now to query the editoperation?  I need to detect which operation is running

0 Kudos
MKa
by
Occasional Contributor III

I found a way to get to what I want, but i cannot figure out how to get the value from the object?  I wand to get the value for the variable DialogHeading from the window object.  All my attempts to get the value have failed.  This is what I have so far.


IFrameworkWindow window = FrameworkApplication.ActiveWindow;
var currentTool = window.GetType().GetProperty("DialogHeading");

This should return "Merge" (When the Merget tool is the active Tool), but is just give me back "DialogHeading" again.  What am I missing?  

0 Kudos
by Anonymous User
Not applicable

Reflection syntax is always a crapshoot.

Try this:

      IFrameworkWindow window = FrameworkApplication.ActiveWindow;
      var currentTool = window.GetType().GetProperty("DialogHeading").GetValue(window, null);‍‍
0 Kudos
MKa
by
Occasional Contributor III

That worked for now, thank you.  This will allow me to proceed with certain operations that i normally stop in my code.  In this case below I want to see if the tool being used is "Merge", this function will return the name of the open window, which has a dialog header of "Merge".  This is only temporary I hope.

Will this EditOperation be available to query anytime soon?

public static Task<string> GetActiveWindowTool()
        {
            return QueuedTask.Run(() =>
            {
                string ReturnActiveWindowTool = "";
                try
                {

                    IFrameworkWindow window = FrameworkApplication.ActiveWindow;
                    if (window != null)
                    {
                        var currentToolProp = window.GetType().GetProperty("DialogHeading");
                        if (currentToolProp != null)
                        {
                            string currentTool = currentToolProp.GetValue(window).ToString();
                            ReturnActiveWindowTool = currentTool;
                        }
                    }
                }
                catch (Exception e)
                {
                    LogError("GetActiveWindow", e);
                }

                return ReturnActiveWindowTool;
            });
        }       
0 Kudos
by Anonymous User
Not applicable
Will this EditOperation be available to query anytime soon?

The good news is the operation is being passed to the row events in 2.4 so you can add to the existing operation. The bad news is the name and token properties arent passed down. This will be addressed after 2.4

0 Kudos