0

How do I specify which field acts as resource for labeling a layer using ArcPy?

Following code is some settings that I am doing on a standalone ArcPy snippet and as you can see I added layer.showLabels = True but assuming I have a field named name I do not know how to add it to the code.

layer = arcpy.mapping.Layer("Primary")
layer.minScale = 10000
layer.showLabels = True
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Oct 22, 2018 at 23:00
0

2 Answers 2

1

Once you have the label class object set the expression using the expression property:

expression: Provides the ability to get or set a layer's individual label class expression. This can be as simple as a single field or more advanced using either a VBScript, JScript or Python expression.

for lblClass in lyr.labelClasses:
 if lblClass.showClassLabels:
 lblClass.expression = lblClass.expression = "\"<FNT name='Arial' size='12'>\" & [MyFieldNameHere] & \"</FNT>\""
answered Jan 22, 2019 at 12:54
1

As commented by @MichaelStimson:

You need to specify a labelClass object https://resources.arcgis.com/en/help/main/10.2/index.html#/LabelClass/00s30000002t000000/ - even if you have only one class, look at the example in the link.

answered Oct 25, 2018 at 21:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.