Export Styles

04-26-2017 11:53 PM
New Contributor


I want to export the symbol styles of all layers in an mxd file (or alternatively lyr file) into a style file. But I want to automate it to use it on a huge amount of mxd files. Is this somehow possible using a python script?

I allready tried the style manager and the "Export Map Styles" after customizing the command menu. But I cannot automate this.

Has anyone an idea how to do this?

Best Regards,


0 Kudos
4 Replies
MVP Esteemed Contributor

arcpy-mapping liststyleitems   references existing styles. alternately, you can examine individual layer symbology neither of which I think will allow you to automate what you want to do I suspect

0 Kudos
MVP Regular Contributor

I've been experimenting with the following code to assist with symbology using layer files.  It might give you some ideas.

# list of layer names to work with
names = ['MyLayer']

mxd = arcpy.mapping.MapDocument("CURRENT")

df = arcpy.mapping.ListDataFrames(mxd)[0]
layers = arcpy.mapping.ListLayers(mxd, "*", df)

for layer in layers:
  if layer.name in names:
    print layer.name, layer.dataSource

    # may want to check this value to see if symbology can be used
    print layer.symbologyType

    # save as a layer file
    # http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/save-to-layer-file.htm
    # SaveToLayerFile_management (in_layer, out_layer, {is_relative_path}, {version})

    # apply symbology (if symbology is not too complex)
    # http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/apply-symbology-from-layer....
    # ApplySymbologyFromLayer_management (in_layer, in_symbology_layer)

0 Kudos
MVP Regular Contributor

Have you checked out ListStyleItems?

0 Kudos
New Contributor


thank you for your quick responses.

The idea of Randy is interesting, but not really the solution I had in mind... I really need the style file to be written to disc, something like arcpy.write_style('C:\symbols.style'), if it would exist...

I also checked the ListStyleItems function, but with this I only can read the styles, not write them to disc, can't I?

Maybe I could somehow run the "Export Map Styles" function from the command menu using some kind of macro?

Best regards,


0 Kudos