Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Has anyone modified UniqueValuesSymbology’s Lyr.symbology.classLabels successfull?

$
0
0
Hi every guys,I want to modify a mxd file’s ”Lyr.symbology.classLabels”(see in Figure1),The main steps as follows:
First,According to Layer‘s name and
Checks whether the property of the Layer is UniqueValuesSymbology, Then assign the value list ‘lyr.symbology.classValues’ to customized ‘Values’ List;

Figure 1 Layer’s UniqueValuesSymbology
Attachment 26627

Second,For each value in ‘Values’ List,We reads the corresponding Label form a pre-defined dictionary named ‘value_label’(see in Figure2,such as '2101010414' corresponding to' ground River (single) '),and append it to the ‘upt_Labels’ List;

Figure 2 value_label dictionary
Attachment 26628

Third,I use the ‘upt_Labels’ List to modify a mxd file’s ”Lyr.symbology.classLabels”,And I want the result like this(see in Figure3):

Figure 3 Expect layers appear’s UniqueValuesSymbology
Attachment 26629

But '' lyr.symbology.classLabels = upt_Labels ''cannot affect after i check the labelList in ArcMap10.1(Also no error info appears when i debug),in fact,there was not any change in mxd, The main code as follow(The script was runing in ArcGIS10.1 SP1 ,Windows7 64bit Ultimate):
Code:

'''
#According mxd's LayerName to modify symbology.classLabels
'''
def EditLyrSymInfo(mxd,lyrName):
    lyr = arcpy.mapping.ListLayers(mxd, lyrName)[0]
    if lyr.symbologyType == "UNIQUE_VALUES":
        Labels=lyr.symbology.classLabels
        Values=lyr.symbology.classValues
        #use this upt_Labels List to update Layer's symbology.classLabels 
        upt_Labels=[]
        for value in Values:
            #value_label dictionary's value in Figure 2
            upt_label=label_value[value]
            upt_Labels.append(upt_label)
            print u'Labels:{0}, Values:{1};'.format(upt_label,value)
        lyr.symbology.classLabels=upt_Labels
        arcpy.RefreshActiveView()
        arcpy.RefreshTOC()

Attachment 26630

What's wrong? I wonder if the property ‘symbology.classLabels’can not modified ,but I read ESRI’s online help document (UniqueValuesSymbology (arcpy.mapping))and know it can read and write ,and there is an Example in the topic.
Has anyone modified UniqueValuesSymbology’s property ‘symbology.classLabels’ successfull? Any help will be appreciated ! Thank you very much!
Attached Thumbnails
Click image for larger version

Name:	fg1.png‎
Views:	N/A
Size:	7.1 KB
ID:	26627   Click image for larger version

Name:	fg2.png‎
Views:	N/A
Size:	12.4 KB
ID:	26628   Click image for larger version

Name:	fg3.png‎
Views:	N/A
Size:	9.3 KB
ID:	26629   Click image for larger version

Name:	fg4.png‎
Views:	N/A
Size:	18.9 KB
ID:	26630  

Viewing all articles
Browse latest Browse all 2485

Trending Articles