0

I'm trying to apply symbology to my dataset after it is populated to the map display, but I am getting the following error. Have I placed the ApplySymbologyFromLayer code incorrectly?

Traceback (most recent call last):
  File "C:\script\script.py", line 61, in <module>
    arcpy.ApplySymbologyFromLayer_management (Output_Feature_Class, in_symbology_layer)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6004, in ApplySymbologyFromLayer
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Layer: Dataset C:/data/cluster_outlier_fieldname.shp does not exist or is not supported
Failed to execute (ApplySymbologyFromLayer).

My script:

for fieldName in fieldList.split(';'):

    # Iterate
    Output_Feature_Class = "C:/data/cluster_outlier_" + fieldName + ".shp"
    outCluster = arcpy.ClustersOutliers_stats(inPointFeatures, fieldName, Output_Feature_Class,
                                              Conceptualization_of_Spatial_Relationships, Distance_Method,
                                              Standardization, Distance_Band_or_Threshold_Distance,
                                              Weights_Matrix_File, Apply_False_Discovery_Rate_FDR_Correction)

    # Add layers to map
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
    addLayer = arcpy.mapping.Layer(Output_Feature_Class)
    arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")

    # Symbolize
    in_symbology_layer = "C:/data/reference/design.lyr"
    arcpy.ApplySymbologyFromLayer_management (Output_Feature_Class, in_symbology_layer)
    arcpy.RefreshActiveView()
    arcpy.RefreshTOC() 
    del mxd, df, addLayer    
1
  • Try arcpy.mapping.Layer() around your *.lyr file - I think that will fix it.
    – PolyGeo
    Oct 25, 2014 at 6:50

1 Answer 1

0

I think this code is a bit sloppy, but it gets the job done:

# Adjust layer symbology
out_layer = "shape.lyr"
layer = "shape.lyr"
arcpy.MakeFeatureLayer_management(Output_Feature_Class, out_layer)
arcpy.SaveToLayerFile_management(out_layer, layer, "ABSOLUTE")
arcpy.ApplySymbologyFromLayer_management(out_layer, symbology)
arcpy.SaveToLayerFile_management(out_layer, layer, "ABSOLUTE")

# Add layer to map
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
addLayer = arcpy.mapping.Layer(layer)
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")

I still find that the add layer to map code I'm using works in ArcMap v10.2, but not in v10.0. EDIT: Works in v10.0 with Service Pack 1 installed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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