<?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: Group graphic elements so they move together in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1253101#M9372</link>
    <description>&lt;P&gt;Right, I admitted that I was currently adding the two items separately.&amp;nbsp; Because I can't get them combined into one item.&lt;/P&gt;&lt;P&gt;The one element is a polygon with text, the&amp;nbsp;CreatePolygonParagraphGraphicElement.&lt;/P&gt;&lt;P&gt;Things I was trying kept telling me I was using the wrong type of object.&lt;/P&gt;&lt;P&gt;However... the last line you gave works!&lt;BR /&gt;The symLayer.GroupElements&lt;/P&gt;&lt;P&gt;Obviously, I had no idea it was that simple.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;BR /&gt;Andy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Jan 2023 21:56:57 GMT</pubDate>
    <dc:creator>AndrewAlexander1</dc:creator>
    <dc:date>2023-01-30T21:56:57Z</dc:date>
    <item>
      <title>Group graphic elements so they move together</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1252476#M9361</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm creating two (for now) graphic elements, one is a polygon, using PolygonBuilder.CreatePolygon.&lt;/P&gt;&lt;P&gt;And then a CIMCharacterMarker using SymbolFactory.Instance.ConstructMarker().&lt;/P&gt;&lt;P&gt;I need to be able to group those two so that when moving the polygon with the mouse, both those elements move together as one element.&lt;/P&gt;&lt;P&gt;I initially place the marker inside the polygon and would like it to stay there when the polygon is moved.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;Andy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 19:13:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1252476#M9361</guid>
      <dc:creator>AndrewAlexander1</dc:creator>
      <dc:date>2023-01-27T19:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: Group graphic elements so they move together</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1252625#M9363</link>
      <description>&lt;P&gt;Sometimes to solve these kinds of things see if u can make the symbol first and then deconstruct it. Usually, if u cant make a symbol via the UI then the symbol probably can't be made via the api either (not always but in most cases).&lt;/P&gt;&lt;P&gt;So in the Pro help we have&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/mapping/layer-properties/position-and-place-marker-symbol-layers.htm" target="_self"&gt;Position and place marker symbol layers&lt;/A&gt;&amp;nbsp;.which contains an "At Center" placement for markers in polys.&lt;/P&gt;&lt;P&gt;A bit of fiddling with the symbology UI gives:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="symbol_properties2.jpg" style="width: 376px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61530i6D8C6A4B3E0BE4D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="symbol_properties2.jpg" alt="symbol_properties2.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The last bit is deconstructing the symbol which involves a bit of trial and error. There are three symbol layers - the marker, a stroke, and a fill. The marker has a placement set to position it "At Center".&lt;/P&gt;&lt;P&gt;Note: I notice that Pro removes the stroke from the char marker to have it scale correctly when it is resized.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class LayoutTool1 : LayoutTool {

  private CIMPolygonSymbol _polygonSymbol = null;

  public LayoutTool1() {
    SketchType = SketchGeometryType.Polygon;
  }
  protected override Task OnToolActivateAsync(bool active) {
    return base.OnToolActivateAsync(active);
  }
  protected override Task&amp;lt;bool&amp;gt; OnSketchCompleteAsync(Geometry geometry) {
    return QueuedTask.Run(() =&amp;gt; {
      if (_polygonSymbol == null)
         _polygonSymbol = MakePolySymbol();
      ElementFactory.Instance.CreateGraphicElement(
          this.ActiveElementContainer, geometry, _polygonSymbol);
      return true;
    });
  }

  private CIMPolygonSymbol MakePolySymbol() {
    var char_index = 80;
    var font = "ESRI Default Marker";
    var char_marker = SymbolFactory.Instance.ConstructMarker(
  	  char_index, font) as CIMCharacterMarker;

    char_marker.Size = 16;
    var grey = ColorFactory.Instance.CreateRGBColor(110, 110, 110);
    var violet = ColorFactory.Instance.CreateRGBColor(236, 212, 252);
    var purple = ColorFactory.Instance.CreateRGBColor(132, 0, 168);

    //change the fill
    //also, for some reason the stroke must be removed to have
    //the symbol scaled correctly
    foreach (var layer in char_marker.Symbol.SymbolLayers)
    {
  	if (layer is CIMSolidFill)
  	{
          ((CIMSolidFill)layer).Color = purple;
  	}
  	else if (layer is CIMSolidStroke)
  	{
          ((CIMSolidStroke)layer).Width = 0.0;
  	}
    }
    //set the placement for the marker within the poly
    var center_placement = new CIMMarkerPlacementPolygonCenter()
    {
       Method = PlacementPolygonCenterMethod.OnPolygon
    };
    //assign the marker placement
    char_marker.MarkerPlacement = center_placement;

    //make the poly outline and fill
    var stroke = SymbolFactory.Instance.ConstructStroke(grey, 2.0);
    var fill = SymbolFactory.Instance.ConstructSolidFill(violet);

    //make the final symbol
    return new CIMPolygonSymbol()
    {
       SymbolLayers = new List&amp;lt;CIMSymbolLayer&amp;gt;()
       {
          char_marker, stroke, fill
       }.ToArray()
    };
  }
}&lt;/LI-CODE&gt;&lt;P&gt;Final symbol:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="char_marker_in_poly.jpg" style="width: 446px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61531i66225BD7312191A5/image-size/large?v=v2&amp;amp;px=999" role="button" title="char_marker_in_poly.jpg" alt="char_marker_in_poly.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jan 2023 18:57:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1252625#M9363</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2023-01-28T18:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: Group graphic elements so they move together</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1253042#M9370</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;I'm still having trouble. I'm putting things together differently and especially when making the polygon, I don't seem to be able to do it that way, and keep the other properties I have for it.&lt;/P&gt;&lt;P&gt;I can definitely create both items in the API.&amp;nbsp; I also don't need to sketch anything. I'd like them to be grouped in the API when they are created.&lt;/P&gt;&lt;P&gt;To summarize the code I have now:&lt;BR /&gt;var polygon = PolygonBuilder.CreatePolygon(listPoints, MapView.Active.Map.SpatialReference);&lt;BR /&gt;&lt;BR /&gt;CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 10, "Arial", "Regular");&lt;BR /&gt;&lt;BR /&gt;(attaching text to the polygon)&lt;BR /&gt;GraphicElement polyTxtElm = LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(newLayout, polygon, text, sym);&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;//create marker from the Font, char index,size,color&lt;BR /&gt;var cimMarker = SymbolFactory.Instance.ConstructMarker(213, "ESRI Geometric Symbols", "Regular", 25, ColorFactory.Instance.GreenRGB) as CIMCharacterMarker;&lt;BR /&gt;var polygonMarker = cimMarker.Symbol;&lt;/P&gt;&lt;P&gt;CIMGraphic polyTxtGra = polyTxtElm.GetGraphic();&lt;/P&gt;&lt;P&gt;var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(cimMarker);&lt;/P&gt;&lt;P&gt;MapPoint symPt = null;&lt;BR /&gt;Coordinate2D newCoord = new Coordinate2D(pX1, pY1+110);&lt;BR /&gt;symPt = MapPointBuilder.CreateMapPoint(newCoord);&lt;/P&gt;&lt;P&gt;var symPtGraphic = new CIMPointGraphic()&lt;BR /&gt;{&lt;BR /&gt;Symbol = pointSymbol.MakeSymbolReference(),&lt;BR /&gt;Location = symPt&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;symLayer.AddElement(polyTxtGra);&lt;/P&gt;&lt;P&gt;symLayer.AddElement(symPtGraphic);&lt;/P&gt;&lt;P&gt;That looks like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AndrewAlexander1_0-1675109311249.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61643i2C86BAFA350F7250/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AndrewAlexander1_0-1675109311249.png" alt="AndrewAlexander1_0-1675109311249.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But of course, moving the polygon or the green element with the mouse does not bring them both together.&lt;/P&gt;&lt;P&gt;I know that's because I'm adding them to the layer separately, but I haven't been able to group them in the code.&amp;nbsp; I've tried the pertinent elements in your code, but my elements seem to be of different types that don't allow it.&lt;/P&gt;&lt;P&gt;But I'm sure I am putting the whole thing together not in the right way.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;Andy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 20:19:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1253042#M9370</guid>
      <dc:creator>AndrewAlexander1</dc:creator>
      <dc:date>2023-01-30T20:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Group graphic elements so they move together</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1253050#M9371</link>
      <description>&lt;P&gt;if I am understanding your code snippet correctly, u are adding _two_ elements to your graphics layer (one with some text and another with a marker symbol)?&lt;/P&gt;&lt;P&gt;Namely:&lt;/P&gt;&lt;P&gt;symLayer.AddElement(polyTxtGra);&lt;/P&gt;&lt;P&gt;symLayer.AddElement(symPtGraphic);&lt;/P&gt;&lt;P&gt;Is that right?&lt;/P&gt;&lt;P&gt;Therefore, can you not simply group the two elements together (into a group element) to achieve the same thing....or must this all be combined into a single symbol (as I was illustrating)?&lt;/P&gt;&lt;P&gt;Creating a group element would look like this:&lt;/P&gt;&lt;P&gt;var elem1 =&amp;nbsp;symLayer.AddElement(polyTxtGra);&lt;/P&gt;&lt;P&gt;var elem2 =&amp;nbsp;symLayer.AddElement(symPtGraphic);&lt;/P&gt;&lt;P&gt;symLayer.GroupElements(new List&amp;lt;Element&amp;gt;() { elem1, elem2 });&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic29336.html" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic29336.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 20:38:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1253050#M9371</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2023-01-30T20:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Group graphic elements so they move together</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1253101#M9372</link>
      <description>&lt;P&gt;Right, I admitted that I was currently adding the two items separately.&amp;nbsp; Because I can't get them combined into one item.&lt;/P&gt;&lt;P&gt;The one element is a polygon with text, the&amp;nbsp;CreatePolygonParagraphGraphicElement.&lt;/P&gt;&lt;P&gt;Things I was trying kept telling me I was using the wrong type of object.&lt;/P&gt;&lt;P&gt;However... the last line you gave works!&lt;BR /&gt;The symLayer.GroupElements&lt;/P&gt;&lt;P&gt;Obviously, I had no idea it was that simple.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;BR /&gt;Andy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 21:56:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/group-graphic-elements-so-they-move-together/m-p/1253101#M9372</guid>
      <dc:creator>AndrewAlexander1</dc:creator>
      <dc:date>2023-01-30T21:56:57Z</dc:date>
    </item>
  </channel>
</rss>

