Select to view content in your preferred language

Get results from ArcMap's built-in measure tool.

1168
2
04-02-2014 08:38 AM
EvanBlaisdell
Occasional Contributor
Does anyone have a clue how to programmatically access the results of ArcMap's built-in measure tool (the little ruler) via ArcObjects? 

I have a custom button on a form to launch the tool.  Ideally, upon double-clicking at the end of a measurement operation I would grab the result behind the scenes and populate a field in a specified feature class.  I just need to know how to get the result.  I'm developing an add-in using C# .NET.

Thanks,
Evan.
0 Kudos
2 Replies
KevinYanuk
Deactivated User
Does anyone have a clue how to programmatically access the results of ArcMap's built-in measure tool (the little ruler) via ArcObjects? 

I have a custom button on a form to launch the tool.  Ideally, upon double-clicking at the end of a measurement operation I would grab the result behind the scenes and populate a field in a specified feature class.  I just need to know how to get the result.  I'm developing an add-in using C# .NET.

Thanks,
Evan.


I tried this once before, and was unsuccessful in getting any result from this tool.  So I rewrote it for an arc engine application .. basically you'd want to:


1. Wire an OnMouseDown event for the map document (not sure of this off the top of my head, the arcengine application has this built in)
2. Wire a "Complete" method for an OnDoubleClick
3. establish a PointArrayClass and PolylineClass, as well as a "last clicked location" point, in my case, I used a selected feature as my first point:

var measureDistancePoints = new PointArrayClass();
var measureDistanceMeasureLine = new PolylineClass();
var measureDistanceMeasureLine.AddPoint((IPoint)_selectedFeature.ShapeCopy);
var measureDistanceLastPoint = (IPoint)_selectedFeature.ShapeCopy;


4. your OnMouseDown method will handle each click , which can draw a new line from the last clicked point to the current clicked location:

          this.ActiveView.ScreenDisplay.StartDrawing(this.ActiveView.ScreenDisplay.hDC, System.Convert.ToInt16(esriScreenCache.esriNoScreenCache));
            var mouseClick = this.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

            var lineColor = new RgbColor();
            var currentLine = new PolylineClass();
            var simpleLineSymbol = new SimpleLineSymbolClass();
            var symbol = (ISymbol)simpleLineSymbol;

            currentLine.FromPoint = measureDistanceLastPoint;
            currentLine.ToPoint = mouseClick;
            lineColor.RGB = 70;
            simpleLineSymbol.Color = lineColor;

            this.ActiveView.ScreenDisplay.SetSymbol(symbol);
            this.ActiveView.ScreenDisplay.DrawPolyline(currentLine);

            measureDistanceLastPoint = mouseClick;
            measureDistanceMeasureLine.AddPoint(mouseClick);
            this.ActiveView.ScreenDisplay.FinishDrawing();



5. last, your double click finishes the measurement, and measures the drawn line:

 var dist = Math.Round(((IPolyline)measureDistanceMeasureLine).Length, 2);
0 Kudos
EvanBlaisdell
Occasional Contributor
I tried this once before, and was unsuccessful in getting any result from this tool.  So I rewrote it for an arc engine application .. basically you'd want to:


1. Wire an OnMouseDown event for the map document (not sure of this off the top of my head, the arcengine application has this built in)
2. Wire a "Complete" method for an OnDoubleClick
3. establish a PointArrayClass and PolylineClass, as well as a "last clicked location" point, in my case, I used a selected feature as my first point:

var measureDistancePoints = new PointArrayClass();
var measureDistanceMeasureLine = new PolylineClass();
var measureDistanceMeasureLine.AddPoint((IPoint)_selectedFeature.ShapeCopy);
var measureDistanceLastPoint = (IPoint)_selectedFeature.ShapeCopy;


4. your OnMouseDown method will handle each click , which can draw a new line from the last clicked point to the current clicked location:

          this.ActiveView.ScreenDisplay.StartDrawing(this.ActiveView.ScreenDisplay.hDC, System.Convert.ToInt16(esriScreenCache.esriNoScreenCache));
            var mouseClick = this.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

            var lineColor = new RgbColor();
            var currentLine = new PolylineClass();
            var simpleLineSymbol = new SimpleLineSymbolClass();
            var symbol = (ISymbol)simpleLineSymbol;

            currentLine.FromPoint = measureDistanceLastPoint;
            currentLine.ToPoint = mouseClick;
            lineColor.RGB = 70;
            simpleLineSymbol.Color = lineColor;

            this.ActiveView.ScreenDisplay.SetSymbol(symbol);
            this.ActiveView.ScreenDisplay.DrawPolyline(currentLine);

            measureDistanceLastPoint = mouseClick;
            measureDistanceMeasureLine.AddPoint(mouseClick);
            this.ActiveView.ScreenDisplay.FinishDrawing();



5. last, your double click finishes the measurement, and measures the drawn line:

 var dist = Math.Round(((IPolyline)measureDistanceMeasureLine).Length, 2);


Thank you.  I may try to implement that if I need some finer control.  What I did was use the TrackNew method on IRubberBand:

IScreenDisplay screenDisplay = av.ScreenDisplay;
IRubberBand rubberBand = new RubberLineClass();
IGeometry geometry = rubberBand.TrackNew(screenDisplay, null);
IPolyline polyline = (ESRI.ArcGIS.Geometry.IPolyline)geometry;


Then project the polyline and get the length.
0 Kudos