ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Layout Class / SetMapSeries Method
Example

In This Topic
    SetMapSeries Method
    In This Topic
    Sets the map series for a layout. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void SetMapSeries( 
       MapSeries mapSeries
    )
    Public Sub SetMapSeries( _
       ByVal mapSeries As MapSeries _
    ) 

    Parameters

    mapSeries
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run.
    Remarks
    This will either associate a new map series to a layout or override an existing map series already associated with the layout because a layout can only have one map series active at a time. This method will automatically call RefreshMapSeries.
    Example
    Layout_SetMapSeries
    //Change the properities of a spacial map series.
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      layout.SetMapSeries(SMS);
    });
    MapSeries_GetSetDefinition
    //Get and modify a map series CIM definition and set the changes back to the layout
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      MapSeries MS = layout.MapSeries as MapSeries;
      CIMMapSeries CIM_MS = MS.GetDefinition();
      CIM_MS.Enabled = false;
      MS.SetDefinition(CIM_MS);
      layout.SetMapSeries(MS);
    });
    Modify an existing map series
    //Modify the currently active map series and changes its sort field and page number field.
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      SpatialMapSeries SMS = layout.MapSeries as SpatialMapSeries; //cast as spatial map seris for additional members
      SMS.SortField = "State_Name";
      SMS.SortAscending = true;
      SMS.PageNumberField = "PageNum";
    
      //Overwrite the current map series with these new settings
      layout.SetMapSeries(SMS); 
    });
    Create a new spatial map series
    // This example create a new spatial map series and then applies it to the active layout. This will automatically 
    // overwrite an existing map series if one is already present.
    
    //Reference map frame and index layer
    MapFrame mf = layout.FindElement("Map Frame") as MapFrame;
    Map m = mf.Map;
    BasicFeatureLayer indexLyr = m.FindLayers("Countries").FirstOrDefault() as BasicFeatureLayer;
    
    //Construct map series on worker thread
    await QueuedTask.Run(() =>
    {
      //SpatialMapSeries constructor - required parameters
      SpatialMapSeries SMS = MapSeries.CreateSpatialMapSeries(layout, mf, indexLyr, "Name");
      
      //Set optional, non-default values
      SMS.CategoryField = "Continent";
      SMS.SortField = "Population";
      SMS.ExtentOptions = ExtentFitType.BestFit;
      SMS.MarginType = ArcGIS.Core.CIM.UnitType.PageUnits;
      SMS.MarginUnits = ArcGIS.Core.Geometry.LinearUnit.Centimeters;
      SMS.Margin = 1;
      SMS.ScaleRounding = 1000;
      layout.SetMapSeries(SMS);  //Overwrite existing map series.
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also