0

This has been really hard to debug, as I had no idea where to look at first, but I have made an attempt to access the "valueField" property of a layer file.

This layer file is of the UNIQUE_VALUES symbology type (although I knew it, also successfully tested with code), and thus must have a read/write valueField property associated with it according to the Help (http://resources.arcgis.com/en/help/main/10.2/index.html#//00s30000005s000000).

However, as soon as I try to access it like:

valField = lyr.symbology.valueField

the script stops dead in its track. Not knowing exactly how to access it (there is only a write example in the Help), I also tried:

valField = lyr.symbology.valueField()

to no avail.

I then noticed in PyScripter, after further configuration of Pyscripter to allow auto-completion with arcpy, that there is no valueField property / method shown... See the first screenshot (no, it's not down the scrollable list). The second screenshot shows I have configured PyScripter properly, as you can see the arcpy auto-completion at work.

What am I missing? I am able to successfully access other properties like labelClasses.

ArcGIS 10.2.0 by the way...

lyr.symbology.valueField

lyr.symbology

2 Answers 2

1

This way it worked fine for me:

enter image description here

Try to get symbology in a separate line?

6
  • Thanks. I had actually tried it this way too, but now noticed I had another issue going on: I actually was processing a small list of layers, and one, although strictly speaking "unique values", actually uses two fields, and registers as "OTHER" symbology type because of that. That type unfortunately doesn't support accessing the valueField property (of course, there are multiple in this case). Skipping it, and implementing your code, made it work.
    – Marco_B
    Commented Feb 25, 2015 at 22:06
  • 2
    I think it is always best to include code as text rather than pictures to aid searches and tests by future visitors.
    – PolyGeo
    Commented Feb 25, 2015 at 22:17
  • Glad it works for you
    – FelixIP
    Commented Feb 25, 2015 at 22:17
  • PolyGeo: I wasn't trying to show code, I was trying to illustrate a possible issue with auto-completion / property presence that I thought relevant. FelixIP: yes, I am glad it now worked out, cost me a day though as I was on some sidetracks before suspecting the problem with the failed script, and model chain it was part of, was in the symbology related code...
    – Marco_B
    Commented Feb 25, 2015 at 23:00
  • Your lyr and mxd objects are created in a different than expected order. Did you create your original mxd object in an identical way to the way you overwrote it?
    – PolyGeo
    Commented Feb 26, 2020 at 4:57
0

I could manage to do this by the help of: ArcPy (ArcMap): Modify Layer Symbology, Expanded. But I'm still interested about the normal approach

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")

lyr =arcpy.mapping.ListLayers(mxd, "LayerName")[0] # Layer object, typically 
from arcpy.mapping.ListLayers (arcpy._mapping.Layer)

# Example 1a: Modifying single-field renderer using undocumented _arc_object.renderer
old_field = "JOINEDTABLENAME.GRAFIKA" # New field name for 
symbolizing layer
new_field = "FeatureClassname.GRAFIKA" # Old field name for symbolizing layer 

sym_xml = lyr._arc_object.renderer
lyr._arc_object.renderer = sym_xml.replace(old_field, new_field)
arcpy.RefreshActiveView()
2
  • Welcome to GIS SE. Is this an answer or question?
    – Aaron
    Commented Feb 25, 2020 at 19:14
  • Hello! This is a good answer for the original question. But i'm still interested about how can be the first answer correct. I get error with that. Probably i'm messing up something. I would rather use the "symbology.valueField" method, not the "_arc_object.renderer".
    – gregi1991
    Commented Feb 25, 2020 at 19:20

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.