I'm relatively new to Python coding. I'd like to write a script tool for turning 'label features' on within an ArcGIS model. However, the script I've written won't recieve input data.

Other example scripts for labelling in this forum have specified layer file paths or used 'listLayers' within an mxd to source the input. However, I need this to take an input connection within model builder (so it can be re-used with different data without modifying the code). So I'm using 'GetParameterAsText'.


import arcpy

inputlayer = arcpy.GetParameterAsText(0)
label_field = arcpy.ListFields(inputlayer)[3]
lyr = arcpy.mapping.Layer(inputlayer)

lyr.labelClasses[0].expression = "Abt  + label_field"
lyr.showLabels = True

I've been attempting to use this on polygon features and also lines. Specifically, the problems are:

  • When I run it as a standalone script tool, I cannot drag a layer (feature classes) into the input from the TOC
  • When I put the script into the model builder, it refuses to connect feature classes or feature layers as inputs.

Is there a better option than GetParameterAsText?

Or is the code incorrect or incomplete?

Is it perhaps an issue with how I've set up the script tool within ArcMap?

closed as too broad by Midavalo May 8 '17 at 2:24

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. What is your question? Is it not labelling your features? I'm not sure how your issues relate to turning on labels. Please edit your question to focus on a single specific problem you are having, and include details about how you've set it up. – Midavalo May 8 '17 at 2:24
  • What data type are you using for the first parameter on your tool dialog? – PolyGeo May 8 '17 at 8:37
  • Thanks for the feedback, I've checked out the tour and other pages for guidelines. I've revised the question to hopefully be more specific. Please let me know if you're after something else. – user96805 May 9 '17 at 0:34
  • The data type for the first parameter is a line feature class (I've also tried with polygons) stored in a file geodatabase. – user96805 May 9 '17 at 0:35