If you are an ArcMap user and you export your map layouts into images or
arcpy, you may have noticed that the selection symbol stays always the same (the default light green color). I was looking recently for a way to change the selection color that would be respected when exporting map layouts programmatically using
Changing a selection color in ArcMap (
Selection menu >
Selection Options) does change the selection color but it is only respected when exporting the layout manually from the
File menu or when exporting the layout in the Python window (it respects the selection color set in ArcMap since I am inside a live ArcMap session). Exporting a layout using
arcpy though always uses the default light green color for selection.
I have found out that the
arcpy.mapping.Layer object does not expose the selection symbol property according to the docs of the
Not all layer properties are accessible through the Layer object. There are many properties available in the ArcMap Layer Properties dialog box that are not exposed to the arcpy scripting environment (for example, display properties, field aliases, selection symbology, and so on).
Adding duplicate layers pointing to the same data source and setting the definition queries manually sounds really cumbersome, particularly when I don’t know beforehand what layers I will need to run selection on.
I have solved it in another way.
- I pre-create three layers for each of the shape types (point, polyline, and polygon) using the necessary selection symbology (done manually).
- Before the export of the map document’s layout, I duplicate the layer that I will run selections on and update its symbology using the
- Then I set definition query on the dummy layer that will serve as a selection symbol layer only.
All of this is done programmatically, so the only thing I really need to supply is the name of the layer that selections will run on. It works great and gives me flexibility to use a custom color for selections on any layer inside any map document.
The script source code: