ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Element Class / SetDefinition Method
CIMElement
Example

In This Topic
    SetDefinition Method (Element)
    In This Topic
    Applies the changes made to a modified CIMElement back to the element on the page layout. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void SetDefinition( 
       CIMElement cimElement
    )
    Public Sub SetDefinition( _
       ByVal cimElement As CIMElement _
    ) 

    Parameters

    cimElement
    CIMElement
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run.
    Example
    Element_GetSetDefinition
    //Modify an element's CIM properties.
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      CIMElement CIMElm = element.GetDefinition();
    
      //Modify a CIM value
    
      element.SetDefinition(CIMElm);
    });
    TableFrame_ModifyExisting
    //Modify an existing tableframe using CIM properties.
    
    //Reference the active layout
    Layout layout = LayoutView.Active.Layout;
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      //Reference table frame
      TableFrame TF = layout.FindElement("Table Frame") as TableFrame;
    
      //Modify CIM properties
      CIMTableFrame cimTF = TF.GetDefinition() as CIMTableFrame;
      cimTF.Alternate1RowBackgroundCount = 1;
      cimTF.Alternate2RowBackgroundCount = 1;
    
      //Apply the changes
      TF.SetDefinition(cimTF);
    });
    Set halo property of north arrow
    //Set the CIM halo properties of a north arrow.
    
    //Reference the first selected element (assumption is it is a north arrow)
    Element northArrow = LayoutView.Active.GetSelectedElements().First();
    
    //Perform on the worker thread
    QueuedTask.Run(() =>
    {
      //Get definition of north arrow...
      var cim = northArrow.GetDefinition() as CIMMarkerNorthArrow;
      
      //this halo symbol is 50% transparent, no outline (i.e. 0 width)
      //First construct a polygon symbol to use in the Halo
      //Polygon symbol will need a fill and a stroke
      var polyFill = SymbolFactory.Instance.ConstructSolidFill(ColorFactory.Instance.CreateRGBColor(0, 0, 0, 50));
      var polyStroke = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 0);
      var haloPoly = SymbolFactory.Instance.ConstructPolygonSymbol(polyFill, polyStroke);
      
      //Set the north arrow definition of HaloSymbol and HaloSize 
      ((CIMPointSymbol)cim.PointSymbol.Symbol).HaloSymbol = haloPoly;
      ((CIMPointSymbol)cim.PointSymbol.Symbol).HaloSize = 3;//size of the halo
        
      //Apply the CIM changes back to the element
      northArrow.SetDefinition(cim);
    });
    Apply a Background Color to a MapFrame
    //Apply a background color to the map frame element using the CIM.
    
    //Perform on the worker thread
    QueuedTask.Run(() =>
    {
      //Get the layout
      var myLayout = Project.Current.GetItems<LayoutProjectItem>()?.First().GetLayout();
      if (myLayout == null) return;
    
      //Get the map frame in the layout
      MapFrame mapFrame = myLayout.FindElement("New Map Frame") as MapFrame;
      if (mapFrame == null)
      {
        //TODO Handle null mapframe
        return;
      }
    
      //Get the map frame's definition in order to modify the background.
      var mapFrameDefn = mapFrame.GetDefinition() as CIMMapFrame;
    
      //Construct the polygon symbol to use to create a background
      var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(
                     ColorFactory.Instance.BlueRGB, SimpleFillStyle.Solid);
    
      //Set the background
      mapFrameDefn.GraphicFrame.BackgroundSymbol =
                                       polySymbol.MakeSymbolReference();
    
      //Set the map frame definition
      mapFrame.SetDefinition(mapFrameDefn);
    });
    Lock an element
    // The Locked property is displayed in the TOC as a lock symbol next
    // to each element.  If locked the element can't be selected in the layout
    // using the graphic selection tools.
    
    //Perform on the worker thread
    QueuedTask.Run(() =>
    {
      // Reference and load the layout associated with the layout item
      Layout layout = layoutItem.GetLayout();
      if (layout != null)
      {
        //Reference an element by name
        Element element = layout.FindElement("MyElement");
        if (element != null)
        {
          // Modify the Locked property via the CIM
          CIMElement CIMElement = element.GetDefinition() as CIMElement;
          CIMElement.Locked = true;
          element.SetDefinition(CIMElement);
        }
      }
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also