Saturday, 5 December 2015

arcobjects - Override default ArcMap editing error dialog


Is there a way to override this dialog easily?


The custom message is already there, but I'm guessing that my client will be more annoying and will want a translated message.



Can I replace that dialog? This dialog is the one that appear if you thrown an exception from inside a class extension.


enter image description here



Answer



Since this has gone unanswered and it looks like a similar issue I had when aborting a delete feature operation, I'll offer my workaround (which I based on something I found on the old Esri forums). It's hacky and you may already be doing this and were looking for a less-hacky method.


Add FindWindow and EndDialog to a class (you might already have a PInvoke class):


public class PInvoke
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String lpszClass, String lpszWindow);


[DllImport("user32.dll")]
public static extern int EndDialog(IntPtr hDlg, IntPtr nResult);
}

Add a timer to your extension class:


private Timer timerDeleteEsriDeleteMessage;

And a property for the timer:


    private Timer TimerRemoveEsriDeleteMessage
{

get
{
if (timerDeleteEsriDeleteMessage == null)
{
timerDeleteEsriDeleteMessage = new Timer();
timerDeleteEsriDeleteMessage.Interval = 1;
timerDeleteEsriDeleteMessage.Tick += new EventHandler(OnTimerDeleteEsriDeleteMessageTick);
}

return timerDeleteEsriDeleteMessage;

}
}

Add the method that actually shuts down the window:


    private void OnTimerDeleteEsriDeleteMessageTick(object timerObject, EventArgs myEventArgs)
{
if (((Timer)timerObject).Tag.ToString().Equals("AbortOperation"))
{
// Close the dialog with the caption 'Delete'
IntPtr textBoxHandle = PInvoke.FindWindow(null, "Delete");

PInvoke.EndDialog(textBoxHandle, (IntPtr)DialogResult.OK);
}

this.TimerRemoveEsriDeleteMessage.Stop();
}

Now the timer can be started just before a delete operation.


            // I show my dialog here (if I want one)

// then start the timer, then abort the operation

this.TimerRemoveEsriDeleteMessage.Start();
this.TimerRemoveEsriDeleteMessage.Tag = "AbortOperation";
ArcMap.Editor.AbortOperation();

I'm thinking this approach may work for the Create Feature Task could not be completed. message (maybe by replacing Delete with Create in the OnTimerDeleteEsriDeleteMessageTick method).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...