Python Toolbox: Issue saving an edited input parameter as a layer file

05-20-2022 04:15 AM
New Contributor II

Hi there. This is a follow-on question from my previous post. If you would like more context, please visit the post here:


I have previously created a python toolbox script that will create a fishnet and select the cells that intersect a boundary defined by a parameter. Cells that do not intersect the boundary are deleted.




I now want to change the script so that the fishnet is not created in the script - instead it is defined as a parameter. Following this, I want the script to select the cells that intersect the boundary and then save them as a new layer file. param0 is defined as the boundary and param1 as the fishnet. The 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 = [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",

        # Param 1 = Fishnet
        param1 = arcpy.Parameter(

        params = [param0,param1]
        return params

    def isLicensed(self):

        return True

    def updateParameters(self, parameters):


    def updateMessages(self, parameters):


    def execute(self, parameters, messages):

        # Overwrite existing file of the same name
        arcpy.env.overwriteOutput = True

        # Reference Parameters
        input1 = parameters[0].valueAsText
        inputgrid1 = parameters[1].valueAsText

        # Convert inputgrid1 to feature class,"inputgrid1_lyr")

        # Select by Location"inputgrid1_lyr", "INTERSECT", input1, None, "NEW_SELECTION", "NOT_INVERT")

        # Save to layer file,"NewGrid.lyr")



Upon completion of the script, I receive no errors. However, no new layer file (NewGrid.lyr) appears in my geodatabase. I have a feeling that the solution here is simple - so apologies in advance for my poor understanding of Python toolboxes. Is anybody able to offer any guidance? 


0 Kudos
1 Reply
MVP Regular Contributor

Does it appear if you tell the lyr to save to a folder instead of a GDB? I think lyr files are only visible in folders.

I'm also not 100% sure a lyr is what you want in this case; it doesn't alter any data so much as tell it how to present itself.

That is, you're not making any permanent changes here. It seems like your original idea of deleting rows would be better; it'll make sure the changes you want are actually permanent, so you don't accidentally click the wrong button and have the entire grid appear all over again.

0 Kudos