Subtle problem with IEditSketch

1922
4
Jump to solution
04-09-2013 05:51 PM
StevenHill1
New Contributor
I have a set of tools (inherited from BaseTool) developed in VS2008 C# for ArcMap 9.3.  One of the tools (call it Tool A) uses the editsketch to create a polygon which is then added as a new feature to a feature class (call it feature class A).  The edit operation is stopped at that point.  Then in another tool (call it Tool B) I again use the edit sketch to draw a polygon which is used to select point features and perform some operations on them (I do this because it is easy to set up the edit sketch geometry and capture the FinishSketch event to get the edit sketch geometry).  However, the first time I use the edit sketch in Tool B after creating a feature with Tool A, the polygon that I create to use as a selector is added as a new feature to Feature Class A.  It's as if the double click event that finishes the sketch in Tool A is still hooked to the event, even though the editor has been stopped and a (supposedly) new edit sketch has been started.

Does anyone have any insight into why this is happening, and maybe a solution?
0 Kudos
1 Solution

Accepted Solutions
SeanJones
Esri Regular Contributor
ok. Make sure you are also unsubscribing from the finish sketch event in the tool's deactivate method.

public override bool Deactivate()   {     // Unsubscribe events     m_editEvents.OnSketchFinished -= m_editEvents_OnSketchFinished;     return base.Deactivate();   }

View solution in original post

0 Kudos
4 Replies
SeanJones
Esri Regular Contributor
Steven,

When you activate tool B your edit task may still be set to create feature with the edit target set to layer A.
When you finish the sketch in tool B the editor will do whatever the current task is, using the current sketch geometry.

When you activate tool B you can set the editors current task to null and then do your selection code in the finish sketch event.
_editor.CurrentTask = null;


Back in tool A, if your creating your own feature and storing it in the finish sketch event, you should set the edit task to null when you activate the tool to prevent the editor from creating two features.
0 Kudos
StevenHill1
New Contributor
Hello Sean:
Thanks for the suggestion, but unfortunately it did not solve the problem.  Here is the code that sets up the edit sketch.  It's the same for both Tool A and Tool B.

                  

                    m_editSketch = m_editor as IEditSketch2;
                    m_editSketch.GeometryType = esriGeometryType.esriGeometryPolygon;
                    m_editEvents = (IEditEvents_Event)m_editor;
                    m_editEvents.OnSketchFinished += new IEditEvents_OnSketchFinishedEventHandler(m_editEvents_OnSketchFinished);
                    m_editor.CurrentTask = null;


A little more information that might be helpful: if I put a breakpoint on the OnSketchFinished event for tool B, on entry to the event handler the editor and the edit sketch are null items, so the edit sketch geometry is null as well - as if the editor and edit sketch have been consumed by some event handler left over from Tool A.
0 Kudos
SeanJones
Esri Regular Contributor
ok. Make sure you are also unsubscribing from the finish sketch event in the tool's deactivate method.

public override bool Deactivate()   {     // Unsubscribe events     m_editEvents.OnSketchFinished -= m_editEvents_OnSketchFinished;     return base.Deactivate();   }

View solution in original post

0 Kudos
StevenHill1
New Contributor
Thanks so much for replying Sean, that fixed the problem.
0 Kudos