This should be so simple, I feel, but I cannot get it to work. The issue I'm having right now is making a feature layer in this python toolbox. When I try to create boxLayer I consistently get an error that the input is not supported or does not exist. I would like it to create a feature layer based on the name and number of the box requested in the tool's parameters. There are a couple of other mistakes here, but this one issue is the one I really need solved. Is there a better way to pass the box number parameter to help make a feature layer of that particular box?

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Fire Department Tools"
        self.alias = "fdept"

        # List of tool classes associated with this toolbox
        self.tools = [BoxBldgCount]

    class BoxBldgCount(object):
        def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Box Zone Building Count"
        self.description = "The user will enter a box number and a 
        building     type." + \
        " The tool will add a field and store the building count for  
        selected type."
        self.canRunInBackground = False

This is where I'm setting the parameters

    def getParameterInfo(self):
        """Define parameter definitions"""
        param0 = arcpy.Parameter(
        displayName = "Enter the box number",
        name = "inBox",
        datatype = "GPLong",
        parameterType = "Required",
        direction = "Input")

        param1 = arcpy.Parameter(
        displayName = "Select a building type",
        name = "bldgType",
        datatype = "GPString",
        parameterType = "Required",
        direction = "Input")
        param1.filter.type = "ValueList"
        param1.filter.list = ["Single Family","Multi-Family","Commercial","Industrial",\
        "City Property","Storage Sheds","Schools","Church"]

        params = [param0,param1]
        return params

        boxNumber = parameters[0]
        buildingType = parameters[1]

        # Make feature layers from the user input.

And this is where I'm having the error. Why does that input not create the layer by concatenating the box number to the FireBoxMap? For example, FireBoxMap_202 exists in the geodatabase, but when I enter 202 as input I receive an error.

        boxLayer = arcpy.MakeFeatureLayer_management(r"C:\EsriPress 
        \GISTPython\Data\City of Oleander.gdb\FireBoxMaps\FireBoxMap_"   
        + str(boxNumber), "layer")
  • Please edit your code snippet to be the minimum required to reproduce the error. We don't need to see all your code, so to test trim it down to just whatever produces the error and (if required) the parameter passed to it, and the post that snippet with the error message in full
    – Midavalo
    Commented Oct 8, 2016 at 23:15
  • See Writing code snippets to get quicker answers?
    – Midavalo
    Commented Oct 8, 2016 at 23:17

1 Answer 1


Without debugging your entire script, you haven't told your python toolbox to retrieve the parameter value.

boxNumber = parameters[0]
buildingType = parameters[1]

You need to suffix these with .valueAsText

boxNumber = parameters[0].valueAsText
buildingType = parameters[1].valueAsText

See Accessing parameters within a Python toolbox

  • Great, that did it. Thanks so much. I cannot believe how simple that was! I was all over the documentation and didn't see that one.
    – Alex R
    Commented Oct 8, 2016 at 23:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.