ArcGIS Pro 3.7 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 Overridable Sub SetDefinition( _
       ByVal cimElement As CIMElement _
    ) 
    public virtual void SetDefinition( 
       CIMElement cimElement
    )

    Parameters

    cimElement
    CIMElement
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run.
    Example
    Set halo property of north arrow
    {
      //Set the CIM halo properties of a north arrow.
    
      //Reference the first selected north arrow element
      var northArrow = LayoutView.Active.GetSelectedElements().OfType<NorthArrow>().First();
    
      //Note: Must be on 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);
    }
    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.
      //Note: Must be on QueuedTask.Run
    
      //Reference an element 
      if (element != null)
      {
        // Modify the Locked property via the CIM
        CIMElement CIMElement = element.GetDefinition() as CIMElement;
        CIMElement.Locked = true;
        element.SetDefinition(CIMElement);
      }
    }
    Apply a Background Color to a MapFrame
    {
      //Apply a background color to the map frame element using the CIM.
      //Note: Must be on QueuedTask.Run
      //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);
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also