ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / GraphicElement Class / SetGraphic Method
CIMGraphic
Example

In This Topic
    SetGraphic Method (GraphicElement)
    In This Topic
    Applies the changes made to a CIMGraphic back to the GraphicElement. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Sub SetGraphic( _
       ByVal cimGraphic As CIMGraphic _
    ) 
    public void SetGraphic( 
       CIMGraphic cimGraphic
    )

    Parameters

    cimGraphic
    CIMGraphic
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run.
    Example
    Create Rectangle Paragraph Text Element 1
    {
      //Note: Must be on QueuedTask.Run
      //Create rectangle text with background and border symbology.  
      //Build 2D polygon geometry
      List<Coordinate2D> plyCoords = new List<Coordinate2D>();
      plyCoords.Add(new Coordinate2D(3.5, 7));
      plyCoords.Add(new Coordinate2D(4.5, 7));
      plyCoords.Add(new Coordinate2D(4.5, 6.7));
      plyCoords.Add(new Coordinate2D(5.5, 6.7));
      plyCoords.Add(new Coordinate2D(5.5, 6.1));
      plyCoords.Add(new Coordinate2D(3.5, 6.1));
      Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
      //Set symbology, create and add element to layout
      //Also notice how formatting tags are using within the text string.
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                        ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular");
      string text = "Some Text String that is really long and is " +
                    "<BOL>forced to wrap to other lines</BOL> so that " +
                    "we can see the effects." as String;
    
      GraphicElement polyTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
        layout, TextType.RectangleParagraph, poly, sym, text, "Polygon Paragraph");
    
      //(Optionally) Modify paragraph border 
      CIMGraphic polyTxtGra = polyTxtElm.GetGraphic();
      CIMParagraphTextGraphic cimPolyTxtGra = polyTxtGra as CIMParagraphTextGraphic;
      cimPolyTxtGra.Frame.BorderSymbol = new CIMSymbolReference();
      cimPolyTxtGra.Frame.BorderSymbol.Symbol =
                   SymbolFactory.Instance.ConstructLineSymbol(
                              ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
      polyTxtElm.SetGraphic(polyTxtGra);
    }
    Create a new picture element with advanced symbol settings
    {
      //Create a picture element and also set background and border symbology.
    
      //Note: Must be on QueuedTask.Run
    
      //Build 2D envelope geometry
      Coordinate2D pic_ll = new Coordinate2D(6, 1);
      Coordinate2D pic_ur = new Coordinate2D(8, 2);
      Envelope env = EnvelopeBuilderEx.CreateEnvelope(pic_ll, pic_ur);
    
      //Create and add element to layout
      string picPath = @"C:\Temp\WhitePass.jpg";
    
      GraphicElement picElm = ElementFactory.Instance.CreatePictureGraphicElement(
                                           layout, env, picPath, "New Picture");
    
      //(Optionally) Modify the border and shadow 
      CIMGraphic picGra = picElm.GetGraphic();
      CIMPictureGraphic cimPicGra = picGra as CIMPictureGraphic;
      cimPicGra.Frame.BorderSymbol = new CIMSymbolReference();
      cimPicGra.Frame.BorderSymbol.Symbol =
            SymbolFactory.Instance.ConstructLineSymbol(
                   ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid);
    
      cimPicGra.Frame.ShadowSymbol = new CIMSymbolReference();
      cimPicGra.Frame.ShadowSymbol.Symbol =
                  SymbolFactory.Instance.ConstructPolygonSymbol(
                        ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid);
    
      //Update the element
      picElm.SetGraphic(picGra);
    }
    Update an elements transparency
    {
      //Update an element's transparency using the CIM.
    
      //Note: Must be on QueuedTask.Run
    
      // Reference a element by name
      GraphicElement graphicElement = layout.FindElement("MyElement") as GraphicElement;
      if (graphicElement != null)
      {
        // Modify the Transparency property that exists only in the CIMGraphic class.
        CIMGraphic CIMGraphic = graphicElement.GetGraphic() as CIMGraphic;
        CIMGraphic.Transparency = 50; // mark it 50% transparent
        graphicElement.SetGraphic(CIMGraphic);
      }
    }
    Modify symbology of a Graphic Element
    {
      // Note: must be called on the QueuedTask
      {
        //within a queued Task
        //get the first line element in the layer
        var ge = graphicsLayer.FindElement("Line 10") as GraphicElement;
        var graphic = ge.GetGraphic();
        if (graphic is CIMLineGraphic lineGraphic)
        {
          //change its symbol
          lineGraphic.Symbol =
           SymbolFactory.Instance.ConstructLineSymbol(
             SymbolFactory.Instance.ConstructStroke(
         ColorFactory.Instance.BlueRGB, 2, SimpleLineStyle.DashDot)).MakeSymbolReference();
          //apply the change
          ge.SetGraphic(lineGraphic);
        }
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also