ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Map Class / SetDefinition Method
The map definition to set
Example

In This Topic
    SetDefinition Method (Map)
    In This Topic
    Sets the map definition. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void SetDefinition( 
       CIMMap mapDefinition
    )
    Public Sub SetDefinition( _
       ByVal mapDefinition As CIMMap _
    ) 

    Parameters

    mapDefinition
    The map definition to set
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Create Abbreviation Dictionary in the Map Definition to a layer
    {
      await QueuedTask.Run(() =>
      {
      //Get the map's definition
      var mapDefn = map.GetDefinition();
      //Get the Map's Maplex labelling engine properties
      var mapDefnPlacementProps = mapDefn.GeneralPlacementProperties as CIMMaplexGeneralPlacementProperties;
    
      //Define the abbreviations we need in an array
      List<CIMMaplexDictionaryEntry> abbreviationDictionary = new List<CIMMaplexDictionaryEntry>
          {
              new CIMMaplexDictionaryEntry {
              Abbreviation = "Hts",
              Text = "Heights",
              MaplexAbbreviationType = MaplexAbbreviationType.Ending
    
           },
              new CIMMaplexDictionaryEntry
              {
                  Abbreviation = "Ct",
                  Text = "Text",
                  MaplexAbbreviationType = MaplexAbbreviationType.Ending
    
              }
              //etc
          };
      //The Maplex Dictionary - can hold multiple Abbreviation collections
      var maplexDictionary = new List<CIMMaplexDictionary>
          {
              new CIMMaplexDictionary {
                  Name = "NameEndingsAbbreviations",
                  MaplexDictionary = abbreviationDictionary.ToArray()
              }
    
          };
      //Set the Maplex Label Engine Dictionary property to the Maplex Dictionary collection created above.
      mapDefnPlacementProps.Dictionaries = maplexDictionary.ToArray();
      //Set the Map definition
      map.SetDefinition(mapDefn);
      });
    }
    Change the active map's labeling engine from Standard to Maplex or vice versa
    {
      var map = MapView.Active?.Map;
      if (map == null)
        return;
    
      await QueuedTask.Run(() =>
      {
        //Get the active map's definition - CIMMap.
        var cimMap = map.GetDefinition();
        //Get the labeling engine from the map definition
        var cimGeneralPlacement = cimMap.GeneralPlacementProperties;
    
        if (cimGeneralPlacement is CIMMaplexGeneralPlacementProperties)
        {
          //Current labeling engine is Maplex labeling engine
          //Create a new standard label engine properties
          var cimStandardPlacementProperties = new CIMStandardGeneralPlacementProperties();
          //Set the CIMMap's GeneralPlacementProperties to the new label engine
          cimMap.GeneralPlacementProperties = cimStandardPlacementProperties;
        }
        else
        {
          //Current labeling engine is Standard labeling engine
          //Create a new Maplex label engine properties
          var cimMaplexGeneralPlacementProperties = new CIMMaplexGeneralPlacementProperties();
          //Set the CIMMap's GeneralPlacementProperties to the new label engine
          cimMap.GeneralPlacementProperties = cimMaplexGeneralPlacementProperties;
        }
        //Set the map's definition
        map.SetDefinition(cimMap);
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also