Export Styles

3250
5
04-26-2017 11:53 PM
GISAdminChemnitz
New Contributor

Hi,

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,

Ron

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

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
RandyBurton
MVP Alum

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})
    arcpy.SaveToLayerFile_management(layer.name,"C:/Path/"+layer.name+".lyr")

    # 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)
    arcpy.ApplySymbologyFromLayer_management(layer.name,"C:/Path/"+layer.name+".lyr")

arcpy.RefreshTOC()
arcpy.RefreshActiveView()
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
RandyBurton
MVP Alum

Have you checked out ListStyleItems?

0 Kudos
GISAdminChemnitz
New Contributor

Hi,

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,

Ron

0 Kudos
RoseF
by
Occasional Contributor

If you haven't already, please see the following thread. Esri announced (informally?) that they would try to add this capability to Pro. But kudos, subscriptions, and comments will help them know it's important!

https://community.esri.com/t5/arcgis-pro-ideas/arcgis-pro-quot-export-map-styles-quot-for-bulk/idc-p...

 

0 Kudos