<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Draw graphics in ArcMap from standalone application in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/draw-graphics-in-arcmap-from-standalone/m-p/174405#M4522</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I suggest you have a look at this article:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001nn000000"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001nn000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem I see, if you are creating geometries, symbols and graphic elements in the memory space of the process of your application and trying to add them into the map which is running in a different memory space in the ArcMap.exe process.&amp;nbsp; You need to use the objectFactory if you want to do that sort of thing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 May 2011 13:19:58 GMT</pubDate>
    <dc:creator>AlexanderGray</dc:creator>
    <dc:date>2011-05-17T13:19:58Z</dc:date>
    <item>
      <title>Draw graphics in ArcMap from standalone application</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/draw-graphics-in-arcmap-from-standalone/m-p/174404#M4521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to highlight features in an running ArcMap instance by drawing graphics on the map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is what I put together so far:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;public IElement AddGraphicToMap(IMap map, IGeometry geometry, IRgbColor rgbColor, IRgbColor outlineRgbColor)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; IGraphicsContainer graphicsContainer = (IGraphicsContainer)map; // Explicit Cast

&amp;nbsp;&amp;nbsp;&amp;nbsp; IElement element = null;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((geometry.GeometryType) == esriGeometryType.esriGeometryPoint)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Marker symbols
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleMarkerSymbol.Color = rgbColor;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleMarkerSymbol.Outline = true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleMarkerSymbol.OutlineColor = outlineRgbColor;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleMarkerSymbol.OutlineSize = 1.5;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleMarkerSymbol.Size = 10;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IMarkerElement markerElement = new MarkerElementClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; markerElement.Symbol = simpleMarkerSymbol;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element = (IElement)markerElement; // Explicit Cast
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; else if ((geometry.GeometryType) == esriGeometryType.esriGeometryPolyline)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;nbsp; Line elements
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleLineSymbol.Color = rgbColor;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDot;&amp;nbsp;&amp;nbsp; //.esriSLSSolid;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleLineSymbol.Width = 1;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ILineElement lineElement = new LineElementClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lineElement.Symbol = simpleLineSymbol;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element = (IElement)lineElement; // Explicit Cast
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; else if ((geometry.GeometryType) == esriGeometryType.esriGeometryPolygon)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Polygon elements
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleFillSymbol.Color = rgbColor;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSForwardDiagonal;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IFillShapeElement fillShapeElement = new PolygonElementClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fillShapeElement.Symbol = simpleFillSymbol;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element = (IElement)fillShapeElement; // Explicit Cast
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!(element == null))
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element.Geometry = geometry;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphicsContainer.AddElement(element, 0);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return element;
}

private void button_Click(object sender, EventArgs e)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; //get running arcmap-instance
&amp;nbsp;&amp;nbsp;&amp;nbsp; IApplication application = null;
&amp;nbsp;&amp;nbsp;&amp;nbsp; IAppROT appRot = new AppROTClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; appRot.Count; i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (appRot.get_Item(i) is IMxApplication)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; application = appRot.get_Item(i);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; //get document handle
&amp;nbsp;&amp;nbsp;&amp;nbsp; IMxDocument mxDocument = (IMxDocument)application.Document;

&amp;nbsp;&amp;nbsp;&amp;nbsp; //create points
&amp;nbsp;&amp;nbsp;&amp;nbsp; IPoint fromPoint = new PointClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp; IPoint toPoint = new PointClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp; fromPoint.X = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; fromPoint.Y = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp; toPoint.X = 9999999;
&amp;nbsp;&amp;nbsp;&amp;nbsp; toPoint.Y = 9999999;

&amp;nbsp;&amp;nbsp;&amp;nbsp; //create line
&amp;nbsp;&amp;nbsp;&amp;nbsp; IPolyline line = new PolylineClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp; line.FromPoint = fromPoint;
&amp;nbsp;&amp;nbsp;&amp;nbsp; line.ToPoint = toPoint;

&amp;nbsp;&amp;nbsp;&amp;nbsp; //define color
&amp;nbsp;&amp;nbsp;&amp;nbsp; IRgbColor colorGreen = new RgbColorClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp; colorGreen.Green = 200;

&amp;nbsp;&amp;nbsp;&amp;nbsp; //draw points and lines on the map
&amp;nbsp;&amp;nbsp;&amp;nbsp; AddGraphicToMap(mxDocument.ActiveView.FocusMap, fromPoint, colorGreen, colorGreen);
&amp;nbsp;&amp;nbsp;&amp;nbsp; AddGraphicToMap(mxDocument.ActiveView.FocusMap, line, colorGreen, colorGreen);
&amp;nbsp;&amp;nbsp;&amp;nbsp; AddGraphicToMap(mxDocument.ActiveView.FocusMap, toPoint, colorGreen, colorGreen);
&amp;nbsp;&amp;nbsp;&amp;nbsp; //refresh map to make changes visible
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxDocument.ActiveView.Refresh();
}&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't get any errors, it just happens nothing at all.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I used the AddGraphicToMap-snippet (&lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000067000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000067000000&lt;/A&gt;&lt;SPAN&gt;) before when building an add-in without any problems. So I assume there is something wrong with the handle mxDocument. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I racked my brain and I fear, I do not to see the wood for the trees. Could someone of the experts tell a noob what he is overlooking? &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any hint will be appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanx in advance,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Fossi&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:00:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/draw-graphics-in-arcmap-from-standalone/m-p/174404#M4521</guid>
      <dc:creator>FossiG_</dc:creator>
      <dc:date>2021-12-11T09:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Draw graphics in ArcMap from standalone application</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/draw-graphics-in-arcmap-from-standalone/m-p/174405#M4522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I suggest you have a look at this article:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001nn000000"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000001nn000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem I see, if you are creating geometries, symbols and graphic elements in the memory space of the process of your application and trying to add them into the map which is running in a different memory space in the ArcMap.exe process.&amp;nbsp; You need to use the objectFactory if you want to do that sort of thing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 May 2011 13:19:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/draw-graphics-in-arcmap-from-standalone/m-p/174405#M4522</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-05-17T13:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Draw graphics in ArcMap from standalone application</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/draw-graphics-in-arcmap-from-standalone/m-p/174406#M4523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Alexander,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanx for the clarification. This explains, why nothings seems to happen at all. I'm still trying to understand the idea of ObjectFactory. :confused:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;But before digging deeper into this - would it be a possibility to trigger an add-in from an external program?&lt;/STRONG&gt;&lt;SPAN&gt; From my limited understanding an add-in would not have this problem, since it is in the same memory space, which explains why the code worked when using it as an add-in.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So can add-in code be called from an external program?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;TIA,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Fossi&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2011 07:48:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/draw-graphics-in-arcmap-from-standalone/m-p/174406#M4523</guid>
      <dc:creator>FossiG_</dc:creator>
      <dc:date>2011-05-18T07:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Draw graphics in ArcMap from standalone application</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/draw-graphics-in-arcmap-from-standalone/m-p/174407#M4524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Fossi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have done this, triggering code inside ArcMap from outside.&amp;nbsp; I didn't use an addin, I used the old way of writing code registering the dll but I think it would be the same.&amp;nbsp; The way I did it was to write a command, then from the external process, through the approt, get the arcmap instance, then through application's document commandbars, you can find the command by classid and invoke it (call onclick.)&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you need to pass in data to make whatever you need to happen, that is a little trickier.&amp;nbsp; I made an extension (extension instances are unique to the arcmap process) got a reference to extension from the external process through the application, set the values (literals only: string, integer, double..., no geometry, extent, etc.)&amp;nbsp; Then invoke the command, and the command retrieves the values from the extension and does its thing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Trying the put the code in the extension and invoking a method on the extension, even by raising a custom event on the extension always caused me problems with the process memory space.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2011 12:41:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/draw-graphics-in-arcmap-from-standalone/m-p/174407#M4524</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-05-18T12:41:18Z</dc:date>
    </item>
  </channel>
</rss>

