Greetings!
I'm trying to re-create an ArcMap add-in in Pro that opens the Divide command frame, and then executes some custom attribute updates after the user divides a polyline. The button opens the Divide tool, but doesn't wait for user interaction before executing additional code. How do I get the button to wait for a successful divide operation before executing the custom code?
Thanks!
Here's my add-in structure (with a message box replacing the custom code):
protected override void OnClick()
{
QueuedTask.Run(() =>
{
// ArcGIS Pro Command's DAML ID.
var commandId = "esri_editing_DivideCommand";
// get the ICommand interface from the ArcGIS Pro Button
// using command's plug-in wrapper
var iCommand = FrameworkApplication.GetPlugInWrapper(commandId) as ICommand;
if (iCommand != null)
{
// Let ArcGIS Pro do the work for us
if (iCommand.CanExecute(null))
{
iCommand.Execute(null);
MessageBox.Show("Any custom code written here executes without waiting for the user to divide a polyline");
}
}
MessageBox.Show("iCommand is done");
});
}
Solved! Go to Solution.
Kerry,
Sorry for the confusion. I would have to qualify my above statement with regards to determining when a button / command has finished executing; is that it depends on the command.
In the example in the documentation, the command "esri_mapping_createBookmark" displays a modal dialog and performs some action on the ok button.
The command in your example "esri_editing_DivideCommand" activates the divide tool and displays a UI in a dockpane. This is not a modal dialog as tools very often require some interaction with the map. The divide command at this point has finished executing. It is the divide tool and the dockpane UI that actually controls the divide operation. The only way to know when the user has finished interacting with the UI and executed the divide edit is to use the edit events. .
Hope this helps clarify things a bit.
Narelle
Hi,
There is no need to use QueuedTask.Run. GetPlugInWrapper doesn't need MCT thread
protected override void OnClick()
{
// ArcGIS Pro Command's DAML ID.
var commandId = "esri_editing_DivideCommand";
// get the ICommand interface from the ArcGIS Pro Button
// using command's plug-in wrapper
var iCommand = FrameworkApplication.GetPlugInWrapper(commandId) as ICommand;
if (iCommand != null)
{
// Let ArcGIS Pro do the work for us
if (iCommand.CanExecute(null))
{
iCommand.Execute(null);
MessageBox.Show("Any custom code written here executes without waiting for the user to divide a polyline");
}
}
MessageBox.Show("iCommand is done");
}
My custom code requires the MCT thread, but I can start the QueuedTask after the iCommand.Execute and the MessageBox.
But I'm still not sure how to wait for the user to finish interacting with the divide tool before executing the custom code.
Hello,
There is no way to determine when a button has finished executing like you're attempting to do. However when it comes to edit operations, you can determine when an edit has occurred by using the edit events. See this documentation. https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Editing#edit-events
In your case you would need to subscribe to the row Events to determine when the Divide operation has completed and add your custom attribute updates within that event.
Narelle
Thanks Narelle,
Just to make sure we're talking about the same thing before I give up...
Unless I misunderstand this reference reusing-arcgis-pro-commands-in-your-add-in-ribbon-ui-in-code-behind, it seems that the first MessageBox line in my add-in code above should execute after the user closes the command's dialog box.
to quote step #7 in that section:
"After the 'Borrowed code-behind' completes (after closing the Create Bookmark dialog) the add-on function will start running popping up the message box with the Here is my own optional add-on functionality string displayed"
(Note: In my code example above, I replaced the message "Here is my own optional add-on functionality"
with "Any custom code written here executes without waiting for the user to divide a polyline")
I assume that they are referring to behavior similar to what I see with my ArcMap version of the add-in: executing the split tool (aka the divide tool in Pro) from within a button creates a pop-up window that has to be interacted with before the rest of the button's OnClick() code runs.
Is this behavior really not possible with a Pro add-in?
Thanks again!
Kerry,
Sorry for the confusion. I would have to qualify my above statement with regards to determining when a button / command has finished executing; is that it depends on the command.
In the example in the documentation, the command "esri_mapping_createBookmark" displays a modal dialog and performs some action on the ok button.
The command in your example "esri_editing_DivideCommand" activates the divide tool and displays a UI in a dockpane. This is not a modal dialog as tools very often require some interaction with the map. The divide command at this point has finished executing. It is the divide tool and the dockpane UI that actually controls the divide operation. The only way to know when the user has finished interacting with the UI and executed the divide edit is to use the edit events. .
Hope this helps clarify things a bit.
Narelle
It certainly does. Thanks Narelle!