ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / ElementFactory Class / CreatePredefinedShapeGraphicElement Method / CreatePredefinedShapeGraphicElement(IElementContainer,PredefinedShape,MapPoint,Double,Double,CIMPolygonSymbol,String,Boolean,ElementInfo) Method
The parent element container
The shape type of the graphic
The location of the graphic
The width of the graphic bounding box (optional)
The height of the graphic bounding box (optional)
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 Version

CreatePredefinedShapeGraphicElement(IElementContainer,PredefinedShape,MapPoint,Double,Double,CIMPolygonSymbol,String,Boolean,ElementInfo) Method
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

Parameters

elementContainer
The parent element container
shapeType
The shape type of the graphic
location
The location of the graphic
width
The width of the graphic bounding box (optional)
height
The height of the graphic bounding box (optional)
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
Remarks
If neither a width or height is provided, the dimensions of the graphic bounding box will use a predefined system default. If only one of width or height is provided then the dimensions will be assumed to be equal. Negative width and height values will be treated the same as if they were missing. When generating a circle (i.e. PredefinedShape.Circle) width is used as the circle diameter. When generating an ellipse (i.e. PredefinedShape.Ellipse) width and height are assumed to be the length of the two axis - major/minor depending on which dimension is the longest.
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 symbology, 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

ArcGIS Pro version: 3 or higher.
See Also