Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm building an Add-in solution in ArcGIS 10 that contains a custom tool. I'd like to borrow the functionality of the lasso selection tool without reinventing the wheel. Is there a way to intercept the geometry of the lasso selection area from the mouse up event? I want to pass the geometry of the lasso area to a spatial filter.

I know how to get control of the lasso tool with the following code in my custom tool class:

private ITool m_SelectTool;
protected override void OnActivate()
        {         
            UID uid = new UID();
            uid.Value = "esriArcMapUI.SelectByLassoTool";
            ICommandItem commandItem = ArcMap.Application.Document.CommandBars.Find(uid, false, false);
            ICommand command = commandItem.Command;
            m_SelectTool  = (ITool)command;            
        }
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

I don't think this is possible (intercepting another tool's private data/events), but the good news is that reinventing the wheel is pretty easy when the inventor shows you how to do it.

See the Custom selection extension Add-In Sample, particularly the SelectByLineTool class. You could tweak it to use a NewPolygonFeedback instead of a line feedback, and add points to it in OnMouseMove instead of OnMouseDown, and Stop the feedback in OnMouseDown instead of OnDoubleClick.

share|improve this answer
1  
Thanks for pointing me in the right direction. The example just needed the tweaks you mentioned and I had it up and running really quick. –  Rich Wawrzonek May 24 '12 at 17:56
    
Glad to help! Just a suggestion, but if you would put your solution down as another answer I would gladly upvote it (earning you reputation instead of me :) See also this discussion on meta. If you do I'll rollback your edit it so it's not duplicated. –  blah238 May 24 '12 at 23:36
    
Posted solution as a separate answer. The edit I made to your post can be rolled back. Thanks for pointing out that discussion, I wondered which was the best way to handle the answer. –  Rich Wawrzonek May 29 '12 at 21:40
    
Done! Also think vinayan's suggestion to accept the answer which led to the solution as a courtesy is sound :) –  blah238 May 29 '12 at 21:53
add comment

Here is the code used in my solution based on modifying the Esri custom selection extension Add-in sample:

private bool m_isMouseDown = false;
private ESRI.ArcGIS.Display.INewPolygonFeedback m_polyFeedback;
private IActiveView m_focusMap;

protected override void OnMouseDown(MouseEventArgs arg) 
{
    IMxDocument mxDoc = ArcMap.Document;
    m_focusMap = mxDoc.FocusMap as IActiveView;
    IPoint point = m_focusMap.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y) as IPoint;

    if (m_polyFeedback == null)
    {
        m_polyFeedback = new ESRI.ArcGIS.Display.NewPolygonFeedback();
        m_polyFeedback.Display = m_focusMap.ScreenDisplay;
        m_polyFeedback.Start(point);
    }
    else
    {
        m_polyFeedback.AddPoint(point);
    }

    m_isMouseDown = true;

}
protected override void OnMouseMove(MouseEventArgs arg)
{
    if (!m_isMouseDown) return;

    IMxDocument mxDoc = ArcMap.Document;
    m_focusMap = mxDoc.FocusMap as IActiveView;
    IPoint point = m_focusMap.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y) as IPoint;

    if (m_polyFeedback == null)
    {
        m_polyFeedback = new ESRI.ArcGIS.Display.NewPolygonFeedback();
        m_polyFeedback.Display = m_focusMap.ScreenDisplay;
        m_polyFeedback.Start(point);
    }
    else
    {
        m_polyFeedback.AddPoint(point);
    }

}
protected override void OnMouseUp(MouseEventArgs arg)
{

    if (!m_isMouseDown) return;

    IPolygon polygon = m_polyFeedback.Stop();

    //Do something with the polygon here

    m_isMouseDown = false;
    m_polyFeedback = null;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.