1

I've been using an ArcPy script for a little while now that applies the symbology ('unique values, many fields') from a template layer to a newly uploaded layer to avoid having to set the symbol, font, unicode, and size, every single time I upload a new version of the file.

This code has worked perfectly fine in the past. It creates 9 different values from 2 value fields. However, today I ran into a problem when the data I uploaded needed only 8 of the 9 values. The symbology didn't display at all and I had to manually change the symbology for each of the 8 values.

I was wondering if there was a way to modify the code so that it would check to see if a value needed to be created or not, and didn't create it if it wasn't needed, avoiding this error.

For example: If only 6 values were needed, the symbology for 6 values would be applied rather than all 9 (thus breaking the symbology for the layer).

I'm not sure if you need my code but I'll provide it anyway. It's pretty simple:

addLayer = arcpy.mapping.Layer("symbology template layer")
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")

symbLayer = r"smybology template layer"

arcpy.ApplySymbologyFromLayer_management("layer that needs symbology", symbLayer)

for lyr in arcpy.mapping.ListLayers(mxd, "", df):
  if lyr.name.lower() == "symbology template layer":
    arcpy.mapping.RemoveLayer(df, lyr)
1

I created a new template with the correct symbology for each of the 9 categories and a single data point to fit into each category. I then merged the symbology of this new template with multiple data sets containing different values (5,6,8) and the symbology was properly applied for each.

I'm not sure what the issue with my first template was, but I'll look into it and edit my post if I definitively find the reason it wasn't working.

0

I'm not sure of your data structure but you could use a search cursor (using if condition logic and possibly a set() and a list to pull out all unique values) to check the value number before applying the related layer file. For this method you'll need a template layer file for each possible value count to use based off the results of the search cursor.

  • Thank you for your comment. I seem to have found a solution with a single new template. I had your solution as a backup, but I wanted to avoid doing it as it would require the creation of 27 template layer files. Thank you for your contribution. – Daniel Mutton May 15 '18 at 19:44

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.