Setting Label Class Language - ArcGIS Pro

953
3
Jump to solution
02-05-2019 01:25 PM
OliverCoudert
New Contributor II

How can I set the Language for a Label Class from Python?  The code below works only if the language has been manually set to Python.  I would like to be able to set the language from within the code.

Edit: Asked a different way, is there a way to determine what the current setting is for Language in the Label Class?  With this information, the returned expression format can match the current Language setting.

aprx = arcpy.mp.ArcGISProject('CURRENT')
m = aprx.listMaps()[0]
lyr = m.listLayers()[0]
if lyr.supports('SHOWLABELS'):
    lyr.listLabelClasses()[0].expression = '\'<FNT name="Arial" size="8">\' + str([targetMap_STATEFP]) + \'</FNT>\''
    lyr.listLabelClasses()[0].visible = True
m.listLayers()[0].showLabels = True
‍‍‍‍‍‍‍
0 Kudos
2 Solutions

Accepted Solutions
WendyHarrison
Esri Contributor

Hi Oliver,

At Pro 2.3 it is not possible to determine the parser or change it using ArcPy.  We are working on these items for upcoming releases.

thanks

Wendy

View solution in original post

WendyHarrison
Esri Contributor

Hi Aneta

It's not available through the arcpy.mp api, but there is a workaround you can use through the cim module.

Help topic: https://pro.arcgis.com/en/pro-app/arcpy/mapping/python-cim-access.htm

Video: https://www.youtube.com/watch?v=8wgt8bKD0Ww&feature=youtu.be

The change parser expression code below is also in the help topic link above. 

 

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Map')[0]
l = m.listLayers('States_WithRegions')[0]

l_cim = l.getDefinition('V2')

lc = l_cim.labelClasses[0]
lc.expressionEngine = 'Python' #From 'Arcade'
lc.expression = '[STATE_NAME]' #From '$feature.STATE_NAME'

l.setDefinition(l_cim)

View solution in original post

3 Replies
WendyHarrison
Esri Contributor

Hi Oliver,

At Pro 2.3 it is not possible to determine the parser or change it using ArcPy.  We are working on these items for upcoming releases.

thanks

Wendy

anyry
by
New Contributor III

Hello,

is it this possible in current version Pro? 

Thanks

0 Kudos
WendyHarrison
Esri Contributor

Hi Aneta

It's not available through the arcpy.mp api, but there is a workaround you can use through the cim module.

Help topic: https://pro.arcgis.com/en/pro-app/arcpy/mapping/python-cim-access.htm

Video: https://www.youtube.com/watch?v=8wgt8bKD0Ww&feature=youtu.be

The change parser expression code below is also in the help topic link above. 

 

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Map')[0]
l = m.listLayers('States_WithRegions')[0]

l_cim = l.getDefinition('V2')

lc = l_cim.labelClasses[0]
lc.expressionEngine = 'Python' #From 'Arcade'
lc.expression = '[STATE_NAME]' #From '$feature.STATE_NAME'

l.setDefinition(l_cim)