Hi there. I am fairly new to Python and I am struggling to get my first Python Toolbox to work.
The purpose of the tool is to create a fishnet over a set area, before selecting cells within the fishnet that intersect a boundary shapefile. Cells that do not intersect the boundary are deleted. See this example below which uses the UK:


The boundary shapefile has been set up to be a selectable parameter inside the tool. My current script looks like this:
# -*- coding: utf-8 -*-
import arcpy
class Toolbox(object):
def __init__(self):
self.label = "Toolbox"
self.alias = "toolbox"
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
self.label = "Tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
# Param 0 = UK Boundary
param0 = arcpy.Parameter(
displayName="Input Feature Class",
name="Parameter0",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
param0.filter.list=["POLYGON"]
params = [param0]
return params
def isLicensed(self):
return True
def updateParameters(self, parameters):
return
def updateMessages(self, parameters):
return
def execute(self, parameters, messages):
# Overwrite existing file of the same name
arcpy.env.overwriteOutput = True
# Reference Parameters
input1 = parameters[0].valueAsText
arcpy.management.CreateFishnet(
"UKFishNet",
"-13.6913900375366 49.8654174804687",
"-13.6913900375366 59.8654174804687",
1, 1, None, None,
"1.76416802406319 61.527084350586",
"NO_LABELS",
"-13.6913900375366 49.8654174804687 1.76416802406319 61.527084350586",
"POLYGON")
arcpy.management.SelectLayerByLocation(
"UKFishNet",
"INTERSECT",
input1,
None,
"NEW_SELECTION",
"INVERT")
arcpy.management.DeleteRows("UKFishNet")
return
However, when I run the script - although I get no errors - I simply get an empty shapefile ("UKFishNet") sent to my geodatabase. Can anybody provide some guidance on what I'm doing wrong? Any pointers would be very much appreciated!