ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / ElementFactory Class / CreateGraphicElements Method
The parent element container
The input graphic collection
Element names (optional)
Select after create flag (default is true) (optional)
Additional element properties (optional)
Example

In This Topic
    CreateGraphicElements Method (ElementFactory)
    In This Topic
    Create GraphicElement based on the input ArcGIS.Core.CIM.CIMGraphic collection and element properties. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    elementContainer
    The parent element container
    cimGraphics
    The input graphic collection
    elementNames
    Element names (optional)
    select
    Select after create flag (default is true) (optional)
    elementInfos
    Additional element properties (optional)

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Value cannot be null: graphic
    Number of elementNames does not match the number of graphics
    Number of elementInfos does not match the number of graphics
    Remarks
    The number of Element names and ElementInfos must either match the input number of CIMGraphics or be null. Refer to GraphicFactory for creating ArcGIS.Core.CIM.CIMGraphic
    Example
    Create Graphic Elements
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    List<Coordinate2D> plyCoords = new List<Coordinate2D>();
    plyCoords.Add(new Coordinate2D(1, 7));
    plyCoords.Add(new Coordinate2D(2, 7));
    plyCoords.Add(new Coordinate2D(2, 6.7));
    plyCoords.Add(new Coordinate2D(3, 6.7));
    plyCoords.Add(new Coordinate2D(3, 6.1));
    plyCoords.Add(new Coordinate2D(1, 6.1));
    Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(1.0, 4.75);
    Coordinate2D ur = new Coordinate2D(3.0, 5.75);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    //Build geometry
    Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);
    
    var g1 = GraphicFactory.Instance.CreateSimpleGraphic(poly);
    var g2 = GraphicFactory.Instance.CreateSimpleGraphic(env);
    var g3 = GraphicFactory.Instance.CreateSimpleGraphic(coord2D.ToMapPoint());
    
    var ge = ElementFactory.Instance.CreateGraphicElements(
      container, new List<CIMGraphic>() { g1, g2, g3 },
      new List<string>() { "Poly", "Envelope", "MapPoint" },
      true);
    Bulk Element creation
    //Must be on QueuedTask.Run(() => { ...
    
    //List of Point graphics
    var listGraphics = new List<CIMPointGraphic>();
    var listGraphics2 = new List<CIMPointGraphic>();
    //Symbol
    var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(
                                        ColorFactory.Instance.BlackRGB);
    //Define size of the array
    int dx = 5;
    int dy = 5;
    MapPoint point = null;
    //Create the List of graphics for the array
    for (int row = 0; row <= dx; ++row)
    {
      for (int col = 0; col <= dy; ++col)
      {
        //At 2.x - point = MapPointBuilder.CreateMapPoint(col, row);
        point = MapPointBuilderEx.CreateMapPoint(col, row);
        //create a CIMGraphic 
        var graphic = new CIMPointGraphic()
        {
          Symbol = pointSymbol.MakeSymbolReference(),
          Location = point
        };
        listGraphics.Add(graphic);
        //Or use GraphicFactory
        var graphic2 = GraphicFactory.Instance.CreateSimpleGraphic(
                                      point, pointSymbol) as CIMPointGraphic;
        listGraphics2.Add(graphic2);
      }
    }
    //Draw the array of graphics
    //At 2.x - var bulkgraphics =
    //              LayoutElementFactory.Instance.CreateGraphicElements(
    //                                              layout, listGraphics, null);
    
    var bulkgraphics = ElementFactory.Instance.CreateGraphicElements(
                                                       container, listGraphics);
    var bulkgraphics2 = ElementFactory.Instance.CreateGraphicElements(
                                                       container, listGraphics2);
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also