It is possible to save custom symbology to a style file within the Format Symbol pane, but is there an ArcPy command to save symbology to a style file?

I have rich symbology which needs to be transferred to another project and would like to loop over all feature layers (each feature layer has a unique value symbology) which are in a Map, and save each symbol to style.

Below is example symbology of just one feature layer.

Symbology of just one FL


You could get and loop through a list of the layers in your table of contents, and then use the SaveToLayerFile_management (in_layer, out_layer, {is_relative_path}, {version}) tool to save a layer file of each listed layer.

  1. Get a list of layers in the table of contents.
  2. Loop/iterate through the list of layers.
  3. Run SaveToLayerFile_management on each layer in the loop.

Here is a working/tested code sample...

import arcpy
aprx = arcpy.mp.ArcGISProject(r'C:\Users\your_name\Documents\ArcGIS\Projects\Proj_123\Proj_123.aprx')
m = aprx.listMaps("Map1")[0]
for lyr in m.listLayers():
    out_dir = r'C:\\Users\\your_name\\Documents\\ArcGIS\\Projects\\Proj_123\\Layers\\'
    out_suffix = r'.lyrx'
    out_layer = out_dir + str(lyr) + out_suffix
    arcpy.SaveToLayerFile_management (lyr, out_layer, "RELATIVE") 
del aprx
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.