pythonparametersbufferarcgisarcpy

Buffer Parameters for Python Toolbox


I'm trying to create a buffer tool python script for ArcGIS. My input, output, and buffer distance parameters work fine. However, I can not get the method parameter to work. I'm wanting to have to option of either PLANAR or GEODESIC.

My Code:

import arcpy

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

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


class Tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = "Tool creates a buffer"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        # First parameter
        param0 = arcpy.Parameter(
            displayName = "Input Feature Class",
            name = "in_features",
            datatype = "GPFeatureLayer",
            parameterType = "Required",
            direction = "Input")
        
        # Second parameter
        param1 = arcpy.Parameter(
            displayName = "Output Feature Class",
            name = "out_features",
            datatype = "GPFeatureLayer",
            parameterType = "Required",
            direction = "Output")
        
        # Third parameter
        param2 = arcpy.Parameter(
            displayName = "Buffer Distance",
            name = "bf_distance",
            datatype = "GPLinearUnit",
            parameterType = "Required",
            direction = "Input")
        param2.parameterDependencies = [param0.name]
        
        # Fourth parameter
        param3 = arcpy.Parameter(
            displayName = "Method",
            name = "bf_method",
            datatype = "GPString",
            parameterType = "Optional",
            direction = "Input")
        
        param3.filter.type = "Value List"
        param3.filter.list = ["PLANAR", "GEODESIC"]
        
        param3.parameterDependencies = [param0.name]
        
        
        # List of parameter
        params = [param0, param1, param2, param3]
        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        in_features = parameters[0].valueAsText
        out_features = parameters[1].valueAsText
        bf_distance = parameters[2].valueAsText
        bf_method = parameters[3].valueAsText
        
        arcpy.Buffer_analysis(in_features, out_features, bf_distance, bf_method)
        return

    def postExecute(self, parameters):
        """This method takes place after outputs are processed and
        added to the display."""
        return

The error message I get is :

ERROR 000800: The value is not a member of Full | Left | Right.Failed to execute (Buffer).

Not sure how to proceed to fix this.


Solution

  • Buffer tool asks for other parameters before the method parameter. Therefore, the 'method' keyword should be specified:

    arcpy.Buffer_analysis(in_features, out_features, bf_distance, method=bf_method)