arcpy.ApplySymbologyFromLayer_management does not define symbology within stand-alone script

11-07-2017 08:01 AM
New Contributor

I have a python script that was initially running with ArcGIS Desktop 10.0. The script runs a bunch of analysis and then creates maps and exports to jpeg images. Prior to exporting ot jpeg, the script also defines the symbology of the map layers from some pre-defined saved layer files (.lyr). Recently, the ArcGIS license was upgraded to 10.4. The scripts works fine without any errors and produces all results. However, the symbology does not render in the new maps and ArcMAP sets some default color symbologies. Also, I checked the part (arcpy.ApplySymbologyFromLayer_management) which imports the symbologies within the ArcMAP python built-in window and it works correctly. I cannot figure out where the disconnect is in my stand alone script. Please help.

Note: Due to company policy I cannot share the code here, but any insight into the matter will be helpful.


0 Kudos
4 Replies
MVP Regular Contributor

Are you running the script in the Python window in ArcMap?  If so, are you refreshing the view before exporting your jpeg?

New Contributor

Sorry for the delay in replying.

The script works when I run in Python window in ArcMap. It renders the symbology correctly. The stand alone script does not render the symbology correctly.

0 Kudos
MVP Esteemed Contributor

That is because the standalone script knows nothing about resetting the symbology unless you are using the mapping module and saving changes to the *.mxd

MVP Regular Contributor

You mention that a "bunch of analysis" is done.  Would ArcMap be creating layers where the name changes with each run, and if so, is the script adapting to this change? Print statements would help identify this problem.

This is a sample of the code that I use with ApplySymbologyFromLayer.

import os
import arcpy # if outside ArcMap

# inside ArcMap, use "CURRENT" for document name
mxd = arcpy.mapping.MapDocument(r"C:\Path\To\map.mxd")
# layer file is in directory with mxd map document; this will be the workspace
arcpy.env.workspace = os.path.dirname(mxd.filePath)

# dictonary matches map layer with symbology layer file
symbols = {'SymbolTest':'LayerSymbology.lyr'}

for layer in arcpy.mapping.ListLayers(mxd):
  if in symbols:
    print "Applying symbology to layer '{}' using '{}'.".format(, symbols[])
    arcpy.ApplySymbologyFromLayer_management(layer, symbols[])
    print "Layer '{}' not in map.".format(

# may need to refresh map
# arcpy.RefreshTOC()
# arcpy.RefreshActiveView()

# save exported jpg in directory with mxd file using mxd name

del mxd‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍