<?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: script tools, get parameter as text and sql in Select layer by attributes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682193#M75097</link>
    <description>&lt;P&gt;Try using an Add Message to print out that where clause string, I have a feeling your use of a format string with a format method isn't doing what you think it is.&lt;/P&gt;&lt;P&gt;In general you should give your hand-written code a once over. For example, you're using &lt;FONT face="courier new,courier"&gt;pathlib&lt;/FONT&gt; to turn the current workspace into a Path object, but then you convert it into a string at every turn instead of using the native path building methods. Either use Path objects to their fullest or use the &lt;FONT face="courier new,courier"&gt;os.path&lt;/FONT&gt; functions to manipulate string paths (which arcpy prefers anyways). You also do a bunch of environment workspace stuff that goes nowhere, unless you're using functions like &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfeatureclasses.htm" target="_self"&gt;ListFeatureClasses&lt;/A&gt; you don't need to set this variable. Honestly you can probably ask for the feature class directly as one parameter and then peel off the workspace path from a &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/describe.htm" target="_self"&gt;Describe&lt;/A&gt; dictionary if needed.&lt;/P&gt;</description>
    <pubDate>Wed, 04 Feb 2026 20:53:39 GMT</pubDate>
    <dc:creator>DavidSolari</dc:creator>
    <dc:date>2026-02-04T20:53:39Z</dc:date>
    <item>
      <title>script tools, get parameter as text and sql in Select layer by attributes</title>
      <link>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682172#M75094</link>
      <description>&lt;P&gt;ESRI community,&lt;/P&gt;&lt;P&gt;I have the following tool wehere the user can enter in a formation, seam, and then a modifier. There is a feature class with three different fields for each one and I'm trying to tell arcpy to select all the records that have the user defined values in field1 and field2 and field3. I am beating my head against the wall becuase this works great in ArcGIS pro when i use the tool, or as a query defintion but I can't get the string right for the SQL because it seems this advanced logic can only use SQL in arcgis... any suggestions are helpful!!&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;import arcpy
from pathlib import Path
import os
point_layer_location = Path(arcpy.GetParameterAsText(0))
point_layer_name = arcpy.GetParameterAsText(1)
point_layer = str(point_layer_location / "{0}".format(point_layer_name))
fields = ['formation','seam','zone_modifier']
us_formation = arcpy.GetParameterAsText(2)
us_seam = arcpy.GetParameterAsText(3)
us_modifier = arcpy.GetParameterAsText(4)
arcpy.env.workspace = str(point_layer_location)
current_workspace = arcpy.env.workspace
arcpy.AddMessage("Current Workspace: " + str(current_workspace))
arcpy.env.overwriteOutput = True

target_horizon = arcpy.management.SelectLayerByAttribute(
                   in_layer_or_view= point_layer,
                   selection_type="NEW_SELECTION",
                   where_clause=f"formation = '{0}' And seam = '{1}' And zone_modifier = '{2}'".format(us_formation,us_seam,us_modifier),
                   invert_where_clause=None)
arcpy.AddMessage("records selected")
arcpy.management.CopyRows(in_rows= target_horizon,
                            out_table="Selected_Records")
arcpy.management.SelectLayerByAttribute(
                   in_layer_or_view= point_layer,
                   selection_type="CLEAR_SELECTION",
                   where_clause="",
                   invert_where_clause=None)
count1 = int(arcpy.management.GetCount(target_horizon).getOutput(0))
arcpy.AddMessage(f"Total Selected: ".format(count1))

arcpy.AddMessage("Process Complete and Selection Cleared")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 20:14:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682172#M75094</guid>
      <dc:creator>dcaESRIwvges</dc:creator>
      <dc:date>2026-02-04T20:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: script tools, get parameter as text and sql in Select layer by attributes</title>
      <link>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682182#M75095</link>
      <description>&lt;P&gt;Your where clause is wrong. It prints to&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;formation = '0' And seam = '1' And zone_modifier = '2'&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I think mixing the f-string with --.format() is messing things up. Removing the f fixed it for me.&lt;/P&gt;&lt;P&gt;That being said, copyrows() gives you a table, not a feature class. idk if that was intended, but that's what you're getting.&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 20:35:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682182#M75095</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2026-02-04T20:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: script tools, get parameter as text and sql in Select layer by attributes</title>
      <link>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682188#M75096</link>
      <description>&lt;P&gt;it's funny, i took out the f in front, closed arcgis pro, reopened it and ran the tool again and it worked. so this is what the where clause should be.&lt;/P&gt;&lt;PRE&gt;"formation = '{0}' And seam = '{1}' And zone_modifier = '{2}'".format(us_formation,us_seam,us_modifier),&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and it worked. but i still need to work on the count part as it never printed the count of the results&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 20:45:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682188#M75096</guid>
      <dc:creator>dcaESRIwvges</dc:creator>
      <dc:date>2026-02-04T20:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: script tools, get parameter as text and sql in Select layer by attributes</title>
      <link>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682193#M75097</link>
      <description>&lt;P&gt;Try using an Add Message to print out that where clause string, I have a feeling your use of a format string with a format method isn't doing what you think it is.&lt;/P&gt;&lt;P&gt;In general you should give your hand-written code a once over. For example, you're using &lt;FONT face="courier new,courier"&gt;pathlib&lt;/FONT&gt; to turn the current workspace into a Path object, but then you convert it into a string at every turn instead of using the native path building methods. Either use Path objects to their fullest or use the &lt;FONT face="courier new,courier"&gt;os.path&lt;/FONT&gt; functions to manipulate string paths (which arcpy prefers anyways). You also do a bunch of environment workspace stuff that goes nowhere, unless you're using functions like &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfeatureclasses.htm" target="_self"&gt;ListFeatureClasses&lt;/A&gt; you don't need to set this variable. Honestly you can probably ask for the feature class directly as one parameter and then peel off the workspace path from a &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/describe.htm" target="_self"&gt;Describe&lt;/A&gt; dictionary if needed.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 20:53:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682193#M75097</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2026-02-04T20:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: script tools, get parameter as text and sql in Select layer by attributes</title>
      <link>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682201#M75098</link>
      <description>&lt;P&gt;THat's because your print message doesn't contain the place for the value. I missed that earlier&lt;/P&gt;&lt;P&gt;Should be&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;count1 = int(arcpy.management.GetCount(target_horizon).getOutput(0))
arcpy.AddMessage("Total Selected: {0}".format(count1))

#Or

arcpy.AddMessage(f"Total Selected: {count1}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an aside, you can use the outputCount property instead of having to do getOutput, getCount&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 21:03:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682201#M75098</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2026-02-04T21:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: script tools, get parameter as text and sql in Select layer by attributes</title>
      <link>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682212#M75099</link>
      <description>&lt;P&gt;Thank you for your critique. I'm still learning and those are very helpful suggestions. I need to understand the difference. I did it this way so someone could change the workspace if they needed to.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 21:13:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1682212#M75099</guid>
      <dc:creator>dcaESRIwvges</dc:creator>
      <dc:date>2026-02-04T21:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: script tools, get parameter as text and sql in Select layer by attributes</title>
      <link>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1683334#M75101</link>
      <description>&lt;P&gt;Another aside, you can just use square bracket notation and retrieve the derived output from the Result object.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;count1 = int(arcpy.management.GetCount(target_horizon)[0])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The documentation says the derived output is a Long, but it's really a String, hence the need to cast.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;count1 = arcpy.management.GetCount(target_horizon)

print(count1) # this will print the number just fine
print(type(count1) # shows that it is a Result object
print(int(count1)) # will fail because you cant cast a Result object to an int
print(int(count1[0])) # will cast the string to an int&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But also no need to cast if using formatting&lt;/P&gt;&lt;LI-CODE lang="python"&gt;count1 = arcpy.management.GetCount(target_horizon)

print(f"This is the count: {count1}")
print("This is the count: {0}".format(count1))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Feb 2026 13:50:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1683334#M75101</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2026-02-10T13:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: script tools, get parameter as text and sql in Select layer by attributes</title>
      <link>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1683336#M75102</link>
      <description>&lt;P&gt;The real sin here is that so many arcpy functions return Results objects instead of anything actually useful.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Feb 2026 13:49:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-tools-get-parameter-as-text-and-sql-in/m-p/1683336#M75102</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2026-02-10T13:49:25Z</dc:date>
    </item>
  </channel>
</rss>

