arcpy unique values many fields symbology

450
4
02-19-2020 06:51 AM
PSGeo
by
New Contributor II

Hi there,

I am doing a very simple python script. That should run for ARCGIS 10.5.1.

The goal is to switch the symbols categories of several FCs (layers in TOC) from "Unique values" to "Unique values, many fields". where the first value is the existing "value field" and the second would be "NGI". I cannot find a way of having the second value for symbolizing my layers...

I just put the code part where i have the doubt, before bellow there is a connection to the mxd and then to the layers:

(...)

if lyr.isFeatureLayer==True:

   lSymbol=lyr.symbology

   lExisting = lSymbol.valueField

   lExisting = str(lExisting)   

   lSymbol.valueField=lExisting

   lSymbol.addAllValues() ## until this point it does only for one value field

   ## the problem is if i do the next part it overwrites the above...

   lSymbol.valueField="NGI"

   lSymbol.addAllValues()

(...)

mxd=Save()

I have 27 mxds pointing to the same GDB ... in each there are more than 100 Layers. Each layer has a definition query that defines the location (states in US and Europe) that is stored in "NGI"... but if i want to edit anything the templates are not showing nothing, because the templates do not work with definition queries unless manually we had the "NGI" of the location of the mxd. The work around i though of is to the above... still not working.

Cheers and thanks for the help

PS

0 Kudos
4 Replies
DavidPike
MVP Frequent Contributor

Pass your fields in as a list in the renderer

0 Kudos
PSGeo
by
New Contributor II

hi,

something like this?:

(...)

l_lists = ["NGI"]

if lyr.isFeatureLayer==True:

   lSymbol=lyr.symbology

   lExisting = lSymbol.valueField

   lExisting = str(lExisting) 

   l_lists.append(lExisting)  

   lSymbol.valueField=l_lists

   lSymbol.addAllValues() ## until this point it does only for one value field

(...)

mxd=Save()

didn't work. 

ValueError: ['ITC','NGI']

0 Kudos
DavidPike
MVP Frequent Contributor

It seems it's not possible  I was looking at the pro documentation.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If you are using ArcMap/ArcCatalog, and don't mind using undocumented ArcPy methods, you can use lyr._arc_object.getsymbology() to dump a JSON definition of the symbology and then use Apply Symbology From Layer—Help | Documentation to apply changes.