I am working on a tool for our Planning team. What this tool needs to do is take input parcel account numbers and a buffer distance before it selects the input parcels, creates a buffer, selects all parcels in the buffer, and then runs a bunch of calculations. Normally, a single parcel is used as the input, but on rare occasions multiple parcels are used as the input.
I've set up a model in ArcGIS Pro and exported to python to help me get started. Here's what I've got so far:
import arcpy
from sys import argv
temp = r"\\\\Workspace\Location"
arcpy.env.scratchWorkspace = temp
arcpy.env.workspace = temp
arcpy.env.overwriteOutput = True
arcpy.AddMessage(arcpy.env.workspace)
arcpy.overwriteOutput = True
class Toolbox:
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = "toolbox"
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool:
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Zoning Maps Tool"
self.description = ""
def getParameterInfo(self):
"""Define the tool parameters."""
params = [
arcpy.Parameter(displayName="Account",
name="account_numbers",
datatype="GPString",
parameterType="Required",
direction="Input",
multiValue= True),
arcpy.Parameter(displayName="Buffer (Feet)",
name="buffer",
datatype="Double",
parameterType="Required",
direction="Input")
]
return params
def isLicensed(self):
"""Set whether the tool is licensed to execute."""
return True
Below is a picture of the input before I run the tool.
Is this the correct way to handle multiple input parcels? How should I set up the select tool to handle multiple parcels?
def execute(self, parameters, messages):
"""The source code of the tool."""
account_numbers = parameters[0].valueAsText
buffer = parameters[1].valueAsText
Seems alright to me. Remember a multi-value comes back as semi-colon separated, so first thing I tend to do split it into a list. You can add the following line to your execute function to get an idea of what is returned.
arcpy.AddMessage(account_numbers.split(";"))