0

I am trying to add polyline in ArcMap by using tool for this I have written some code, but the polyline is not adding in the proper extent.

How can I change my code to draw a polyline?

public override void OnClick()
 {
 IMxDocument mxd = m_application.Document as IMxDocument;
 ESRI.ArcGIS.Carto.IActiveView activeView = mxd.ActiveView;
 IScreenDisplay sd = activeView.ScreenDisplay;
 DrawPolyline(activeView);
 }
 private void DrawPolyline(ESRI.ArcGIS.Carto.IActiveView activeView)
 {
 if (activeView == null)
 {
 return;
 }
 ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;
 // Constant
 screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
 ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
 rgbColor.Red = 255;
 ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast
 ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
 simpleLineSymbol.Color = color;
 ESRI.ArcGIS.Display.ISymbol symbol = (ESRI.ArcGIS.Display.ISymbol)simpleLineSymbol; // Explicit Cast
 ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberLineClass();
 ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol);
 screenDisplay.SetSymbol(symbol);
 screenDisplay.DrawPolyline(geometry);
 screenDisplay.FinishDrawing();
 }
Hornbydd
44.9k5 gold badges43 silver badges84 bronze badges
asked Feb 14, 2017 at 6:22

1 Answer 1

1

Your code is drawing the geometry to the screen display and as soon as that refreshes you will lose the display of it. It is unclear what you mean by "...not adding in the proper extent."? If you want your polyline that you have just drawn on the screen to be permanent you need to write it to a featureclass. If that is not what you mean and you simply want it to stay on the screen then you need to store it as a graphic in the IGraphicsContainer for the Map. Here is a blog that shows an example of adding a graphic using VB.

answered Feb 14, 2017 at 16:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.