ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / ElementFactory Class / CreatePredefinedShapeGraphicElement Method / CreatePredefinedShapeGraphicElement(IElementContainer,PredefinedShape,Envelope,CIMPolygonSymbol,String,Boolean,ElementInfo) Method
The parent element container
The shape type of the graphic
The graphic bounding box
The symbol to be used with the graphic (optional)
An element name (optional)
Select after create flag (default is true) (optional)
Additional element properties (optional)
Example

In This Topic
    CreatePredefinedShapeGraphicElement(IElementContainer,PredefinedShape,Envelope,CIMPolygonSymbol,String,Boolean,ElementInfo) Method
    In This Topic
    Create a polygon graphic of the specified PredefinedShape using the provided location, optional size dimensions, and symbol. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Function CreatePredefinedShapeGraphicElement( _
       ByVal elementContainer As IElementContainer, _
       ByVal shapeType As PredefinedShape, _
       ByVal bounds As Envelope, _
       Optional ByVal polySymbol As CIMPolygonSymbol, _
       Optional ByVal elementName As String, _
       Optional ByVal select As Boolean, _
       Optional ByVal elementInfo As ElementInfo _
    ) As GraphicElement

    Parameters

    elementContainer
    The parent element container
    shapeType
    The shape type of the graphic
    bounds
    The graphic bounding box
    polySymbol
    The symbol to be used with the graphic (optional)
    elementName
    An element name (optional)
    select
    Select after create flag (default is true) (optional)
    elementInfo
    Additional element properties (optional)

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    empty or null geometry
    Example
    Create rectangle graphic with simple symbology
    //Create a simple 2D rectangle graphic and apply simple fill and
    //outline symbols.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D envelope geometry
      Coordinate2D rec_ll = new Coordinate2D(1.0, 4.75);
      Coordinate2D rec_ur = new Coordinate2D(3.0, 5.75);
      //At 2.x - Envelope rec_env = EnvelopeBuilder.CreateEnvelope(rec_ll, rec_ur);
      Envelope rec_env = EnvelopeBuilderEx.CreateEnvelope(rec_ll, rec_ur);
    
      //Set symbolology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
        ColorFactory.Instance.BlackRGB, 5.0, SimpleLineStyle.Solid);
      CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
        ColorFactory.Instance.GreenRGB, SimpleFillStyle.DiagonalCross, outline);
    
      //At 2.x - GraphicElement recElm =
      //           LayoutElementFactory.Instance.CreateRectangleGraphicElement(
      //                                                  layout, rec_env, polySym);
      //         recElm.SetName("New Rectangle");
      //
      GraphicElement recElm = ElementFactory.Instance.CreateGraphicElement(
        container, rec_env, polySym, "New Rectangle");
      //Or use Predefined shape
      GraphicElement recElm2 = ElementFactory.Instance.CreatePredefinedShapeGraphicElement(
                                container, PredefinedShape.Rectangle, rec_env, polySym, 
                                "New Rectangle2");
    });
    Create Predefined Shape Graphic Element
    //Must be on QueuedTask.Run(() => { ...
    
    //PredefinedShape shapeType =
    //              PredefinedShape.Circle | Cloud | Cross |Circle | Triangle | ... ;
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(4, 2.5);
    Coordinate2D ur = new Coordinate2D(6, 4.5);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    var outline = SymbolFactory.Instance.ConstructStroke(
                    ColorFactory.Instance.BlueRGB, 2);
    var poly_sym = SymbolFactory.Instance.ConstructPolygonSymbol(
                     null, outline);
    
    var ge = ElementFactory.Instance.CreatePredefinedShapeGraphicElement(
                           container, shapeType, env.Center, env.Width, env.Height, 
                            poly_sym, shapeType.ToString(), true);
    
    Create Predefined Shape Graphic Element
    //Must be on QueuedTask.Run(() => { ...
    
    //PredefinedShape shapeType =
    //              PredefinedShape.Circle | Cloud | Cross |Circle | Triangle | ... ;
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(4, 2.5);
    Coordinate2D ur = new Coordinate2D(6, 4.5);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    var outline = SymbolFactory.Instance.ConstructStroke(
                    ColorFactory.Instance.BlueRGB, 2);
    var poly_sym = SymbolFactory.Instance.ConstructPolygonSymbol(
                     null, outline);
    
    var ge = ElementFactory.Instance.CreatePredefinedShapeGraphicElement(
                           container, shapeType, env.Center, env.Width, env.Height, 
                            poly_sym, shapeType.ToString(), true);
    
    Create Predefined Shape Graphic Element
    //Must be on QueuedTask.Run(() => { ...
    
    //PredefinedShape shapeType =
    //              PredefinedShape.Circle | Cloud | Cross |Circle | Triangle | ... ;
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(4, 2.5);
    Coordinate2D ur = new Coordinate2D(6, 4.5);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    var outline = SymbolFactory.Instance.ConstructStroke(
                    ColorFactory.Instance.BlueRGB, 2);
    var poly_sym = SymbolFactory.Instance.ConstructPolygonSymbol(
                     null, outline);
    
    var ge = ElementFactory.Instance.CreatePredefinedShapeGraphicElement(
                           container, shapeType, env.Center, env.Width, env.Height, 
                            poly_sym, shapeType.ToString(), true);
    
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also