HOW TO
In ArcGIS Pro, an extent indicator can be manually added to a layout that contains at least two 2D map frames. To streamline the process for multiple layouts, ArcPy can be used to programmatically add extent indicators to each map frame by accessing and modifying the Cartographic Information Model (CIM) through Python CIM access.
Note: Avoid pressing Enter between lines, as this creates indentation errors. The entire script must be run at once.
import arcpy
for lyt in p.listLayouts():
mf_list = lyt.listElements('MapFrame_Element', '<Main MF>')
if not mf_list:
continue
mf = mf_list[0]
lyt_cim = lyt.getDefinition('V3')
stroke_color = arcpy.cim.CreateCIMObjectFromClassName('CIMRGBColor', 'V3')
stroke_color.values = [255, 0, 0, 100]
fill_color = arcpy.cim.CreateCIMObjectFromClassName('CIMRGBColor', 'V3')
fill_color.values = [0, 0, 0, 0]
stroke = arcpy.cim.CreateCIMObjectFromClassName('CIMSolidStroke', 'V3')
stroke.width = 1
stroke.color = stroke_color
fill = arcpy.cim.CreateCIMObjectFromClassName('CIMSolidFill', 'V3')
fill.color = fill_color
symbol = arcpy.cim.CreateCIMObjectFromClassName('CIMPolygonSymbol', 'V3')
symbol.symbolLayers = [stroke, fill]
symbol_ref = arcpy.cim.CreateCIMObjectFromClassName('CIMSymbolReference', 'V3')
symbol_ref.symbol = symbol
ei_cim = arcpy.cim.CreateCIMObjectFromClassName('CIMExtentIndicator', 'V3')
ei_cim.sourceMapFrame = mf.name
ei_cim.extentIndicatorType = "Frame"
ei_cim.isVisible = True
ei_cim.name = "extent_indicator"
ei_cim.symbol = symbol_ref
for elm in lyt_cim.elements:
if elm.name == '<Locator MF>':
if not elm.extentIndicators:
elm.extentIndicators = []
elm.extentIndicators.insert(0, ei_cim)
lyt.setDefinition(lyt_cim)
The code below shows the full sample script.
import arcpy
p = arcpy.mp.ArcGISProject('current')
for lyt in p.listLayouts():
mf_list = lyt.listElements('MapFrame_Element', '<Main MF>')
if not mf_list:
continue
mf = mf_list[0]
lyt_cim = lyt.getDefinition('V3')
stroke_color = arcpy.cim.CreateCIMObjectFromClassName('CIMRGBColor', 'V3')
stroke_color.values = [255, 0, 0, 100]
fill_color = arcpy.cim.CreateCIMObjectFromClassName('CIMRGBColor', 'V3')
fill_color.values = [0, 0, 0, 0]
stroke = arcpy.cim.CreateCIMObjectFromClassName('CIMSolidStroke', 'V3')
stroke.width = 1
stroke.color = stroke_color
fill = arcpy.cim.CreateCIMObjectFromClassName('CIMSolidFill', 'V3')
fill.color = fill_color
symbol = arcpy.cim.CreateCIMObjectFromClassName('CIMPolygonSymbol', 'V3')
symbol.symbolLayers = [stroke, fill]
symbol_ref = arcpy.cim.CreateCIMObjectFromClassName('CIMSymbolReference', 'V3')
symbol_ref.symbol = symbol
ei_cim = arcpy.cim.CreateCIMObjectFromClassName('CIMExtentIndicator', 'V3')
ei_cim.sourceMapFrame = mf.name
ei_cim.extentIndicatorType = "Frame"
ei_cim.isVisible = True
ei_cim.name = "extent_indicator"
ei_cim.symbol = symbol_ref
for elm in lyt_cim.elements:
if elm.name == '<Locator MF>':
if not elm.extentIndicators:
elm.extentIndicators = []
elm.extentIndicators.insert(0, ei_cim)
lyt.setDefinition(lyt_cim)
The extent indicator is displayed in the map frame on the layout, as shown below.

Article ID: 000042116
Get help from ArcGIS experts
Start chatting now