labels python

37
0
07-12-2019 05:15 AM
samsinson
New Contributor

Hi community,

I would like to use this on a python script that I made:

def FindLabel ( [FIRST_DENO] 😞
if 'ONF OFFICE NATIONAL DES FORETS' in([FIRST_DENO] 😞
return [FIRST_DENO] .replace('ONF OFFICE NATIONAL DES FORETS', 'ONF')
elif 'GROUPEMENT FORESTIER' in([FIRST_DENO] 😞
return [FIRST_DENO] .replace('GROUPEMENT FORESTIER', 'GF')
else :
return [FIRST_DENO]

This actually runs fine In the ArcGis environment (label expression) , but I've been struggling to find the way to do it within the python script. 

I have this in python at first :

# labels
for out_layer_dissolve in arcpy.mapping.ListLayers(mxd):

if out_layer_dissolve.name == out_table +"\\"+ "dissolve2_"+dept+".lyr":
out_layer_dissolve.name = "localisant_tampon_"+ dept + "_" + Buffer + "m"
out_layer_dissolve.transparency = 60
out_layer_dissolve.showLabels = True

if out_layer_dissolve.supports("LABELCLASSES"):

for label in out_layer_dissolve.labelClasses:

label.expression = '"{}" + [FIRST_DENO] + "{}"'.format("<CLR red = '0' green = '0' blue = '0'><FNT size = '5'>","</FNT></CLR>")

I couldn't  succeed when I tried to use the function and I had the message that [FIRST_DENO] isn't iterable. 

I'm just an amateur in scripting but I feel that this is going to be more complicated than I thought. 

I wish someone could help me find the way to do it.

Many thanks

0 Kudos
0 Replies