Select to view content in your preferred language

Turn on label with arcpy to create script tool

06-23-2022 01:33 AM
Labels (3)
New Contributor

Hi! I want to create a script tool that will start the label for certain layers, that is to add the parameters with the layer to which I want to activate the label and what field I want to display it that I need.. I used this script

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
layer = arcpy.mapping.ListLayers(mxd, "")[0]
if layer.supports("LABELCLASSES"):
for lblclass in layer.labelClasses:
lblclass.showClassLabels = True
lblclass.expression = " [Layer]"
layer.showLabels = True

but it doesn't work to create a script tool, it only works in python windows. Do you have any suggestions?

Tags (3)
0 Kudos
1 Reply
MVP Notable Contributor

You need to read the help file and understand how to turn your script into a script tool. Its all in the help file here.

0 Kudos