0

I am running ArcGIS 10.2.2 Version 10.2.2.3552, using ArcMap.

I am creating a python script and one of the things i need to do is apply symbology from layer to a shapefile in my mxd that is maintained outside of the mxd. It works fine in model builder but when i run it in python i get multiple errors.

Code:

# Import arcpy module
import arcpy


# Local variables:
Tioga = "Tioga\\Tioga"
Tioga_lyr = "C:\\Users\\jcarl\\Desktop\\Dynamic LH Map\\Symbology\\Tioga.lyr"

# Process: Apply Symbology From Layer
arcpy.ApplySymbologyFromLayer_management(Tioga, Tioga_lyr)

Model

Runtime error Traceback (most recent call last): File "", line 10, in File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6004, in ApplySymbologyFromLayer raise e ExecuteError: ERROR 000966: The input layer is not valid Failed to execute (ApplySymbologyFromLayer).

  • Are you running this in the python window within ArcMap? – Erica Mar 6 '15 at 18:17
  • Yes. My main goal is to run outside of arcmap – Joey Carl Mar 6 '15 at 19:33
2

EDIT: I realized my first answer was incorrect, this is an update (I forgot that the function needs a Layer object, not a dataset path).

I think the issue is that the you are passing "Tioga\Tioga" (which is a technically a string) but the Apply Symbology function needs a Layer object. You can create the layer object like this:

mxd = arcpy.mapping.MapDocument("CURRENT")
Tioga = arcpy.mapping.ListLayers(mxd,"Tioga1")[0]

arcpy.management.ApplySymbologyFromLayer(Tioga,symbologylayerpath)

Before trying this, rename your layer "Tioga1" in the table of contents, otherwise it'll grab the group layer and not work.

Apologies for the misdirection earlier.

  • This is the way to go. To run it outside ArcMap, simply change the mxd variable: mxd = arcpy.mapping.MapDocument(r"C:\gis\mymap.mxd") – Erica Mar 6 '15 at 19:35
  • Can somebody tell me the difference from ApplySymbology and Update symbology? Do they accomplish the same task, or when is a situation when i would use update opposed to apply? – Joey Carl Mar 9 '15 at 19:17
  • Hmm, I've never used update layer before, but it looks like it'll pull more info over, like a definition query and alias. I wouldn't expect that there's any difference between using Update Layer with symbology_only=True and using Apply Symbology From Layer. – mr.adam Mar 9 '15 at 19:45
  • ok, apply layer from symbology seems to be working great so I'm not going to mess with a good thing! – Joey Carl Mar 9 '15 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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