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 OnDoubleClick3. 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);
var measureDistancePoints = new PointArrayClass(); var measureDistanceMeasureLine = new PolylineClass(); var measureDistanceMeasureLine.AddPoint((IPoint)_selectedFeature.ShapeCopy); var measureDistanceLastPoint = (IPoint)_selectedFeature.ShapeCopy;
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();
var dist = Math.Round(((IPolyline)measureDistanceMeasureLine).Length, 2);
IScreenDisplay screenDisplay = av.ScreenDisplay; IRubberBand rubberBand = new RubberLineClass(); IGeometry geometry = rubberBand.TrackNew(screenDisplay, null); IPolyline polyline = (ESRI.ArcGIS.Geometry.IPolyline)geometry;
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.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.