<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python Toolbox Issues: using ArcPy Select by Location in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-toolbox-issues-using-arcpy-select-by/m-p/1175359#M64579</link>
    <description>&lt;P&gt;Oh weird.&lt;/P&gt;&lt;P&gt;My guess is that it's not honoring the selection by Location when you run Delete Rows.&lt;/P&gt;&lt;P&gt;Maybe try setting the select by Location as a new variable, and passing that variable into DeleteRows?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;FishSelect= arcpy.management.SelectLayerByLocation("yadda yadda yadda")

arcpy.management.DeleteRows(FishSelect)&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 18 May 2022 21:57:44 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2022-05-18T21:57:44Z</dc:date>
    <item>
      <title>Python Toolbox Issues: using ArcPy Select by Location</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-issues-using-arcpy-select-by/m-p/1175343#M64578</link>
      <description>&lt;P&gt;Hi there. I am fairly new to Python and I am struggling to get my first Python Toolbox to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DPG_0-1652909592119.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/41670i1292089EB5664B90/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DPG_0-1652909592119.png" alt="DPG_0-1652909592119.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DPG_1-1652909838762.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/41671i2DD69FE619CFB93E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DPG_1-1652909838762.png" alt="DPG_1-1652909838762.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The boundary shapefile has been set up to be a selectable parameter inside the tool. My current script looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- 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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 22:31:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-issues-using-arcpy-select-by/m-p/1175343#M64578</guid>
      <dc:creator>DPG</dc:creator>
      <dc:date>2022-05-18T22:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox Issues: using ArcPy Select by Location</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-issues-using-arcpy-select-by/m-p/1175359#M64579</link>
      <description>&lt;P&gt;Oh weird.&lt;/P&gt;&lt;P&gt;My guess is that it's not honoring the selection by Location when you run Delete Rows.&lt;/P&gt;&lt;P&gt;Maybe try setting the select by Location as a new variable, and passing that variable into DeleteRows?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;FishSelect= arcpy.management.SelectLayerByLocation("yadda yadda yadda")

arcpy.management.DeleteRows(FishSelect)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 18 May 2022 21:57:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-issues-using-arcpy-select-by/m-p/1175359#M64579</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-05-18T21:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox Issues: using ArcPy Select by Location</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-issues-using-arcpy-select-by/m-p/1175360#M64580</link>
      <description>&lt;P&gt;I'm not in a position to test out your specific code at the moment and I'm not personally that familiar with the CreateFishnet tool, but just from a brief review, it looks like CreateFishnet outputs a feature class.&amp;nbsp; You are then trying to use that feature class as the input to SelectLayerByLocation.&amp;nbsp; However, SelectLayerByLocation does not actually allow feature classes as an input, only layers (of feature classes).&amp;nbsp; So, while there may or may not be other problems causing the issue, at the very least you should consider adding Make Feature Layer tool (&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/make-feature-layer.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/make-feature-layer.htm&lt;/A&gt;)&amp;nbsp;before SelectLayerByLocation.&amp;nbsp; And use that newly created layer as the input to SelectLayerByLocation and DeleteRows.&amp;nbsp; Then, to keep from having a bunch of temporary layers in memory (which can cause issues if you have multiple layers with the same exact name), I would add Delete tool (&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/delete.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/delete.htm&lt;/A&gt;) after DeleteRows to delete the temporarily created layer.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 22:01:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-issues-using-arcpy-select-by/m-p/1175360#M64580</guid>
      <dc:creator>John_S</dc:creator>
      <dc:date>2022-05-18T22:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox Issues: using ArcPy Select by Location</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-issues-using-arcpy-select-by/m-p/1175370#M64581</link>
      <description>&lt;P&gt;Thank you! I added this right after creating the fishnet and it worked like a treat:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;        arcpy.management.MakeFeatureLayer("UKFishNet", "UKFishNet_lyr")


        arcpy.management.SelectLayerByLocation(
        "UKFishNet_lyr",
        "INTERSECT",
        input1,
        None,
        "NEW_SELECTION",
        "INVERT")

        arcpy.management.DeleteRows("UKFishNet_lyr")


        return&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 18 May 2022 22:28:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-issues-using-arcpy-select-by/m-p/1175370#M64581</guid>
      <dc:creator>DPG</dc:creator>
      <dc:date>2022-05-18T22:28:17Z</dc:date>
    </item>
  </channel>
</rss>

