1

I'm quite new to Python and so my knowledge is limited, but I'm trying to create a script that changes the symbology of a group of layers within an mxd. the feature classes are saved in a gdb, and each feature class needs a unique symbology. I have layer files stored in a folder that correspond to each feature class. I'm able to symbolize each feature class using the following

NOGO12_Hab="NOGO2012_Habitat"
Symbol_2012Hab = r"C:Field_Data\Symbology Layers\2012_Habitat.lyr"
arcpy.ApplySymbologyFromLayer_management(NOGO12_Hab,Symbol_2012Hab)

I've then duplicated this for each feature class and its required symbology. I'm running into problems where the feature class in the TOC is blank or doesn't exist, and returns an error. Is there a way to have the script skip the blank or missing feature classes?

1 Answer 1

1

Have a look at error handling with Python and error handling in ArcGIS.

In the example below if ApplySymbolFromLayer_management fails because the layer does not exist the code skips to the except block and simply passes and carries on.

NOGO12_Hab="NOGO2012_Habitat"
Symbol_2012Hab = r"C:Field_Data\Symbology Layers\2012_Habitat.lyr"
try:
    arcpy.ApplySymbologyFromLayer_management(NOGO12_Hab,Symbol_2012Hab)
except:
    pass

Alternatively you could get a list of the layers inside of your MXD. The check the list and if your layer exists inside of that mxd apply symbologies.

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.