<?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: Select Records in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-records/m-p/98562#M7658</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It depends on what you want to do with the selected set, but typically I use the MakeFeatureLayer tool to apply rapid selections (runs faster than the SelectLayerByAttribute tool). The Select tool actually creates a new featureclass on disk, so has the additional overhead of writting to disk... &lt;BR /&gt;&lt;BR /&gt;The MakeFeatureLayer tool creates a "feature layer" that is an in memory reference to the selcted features on disk (but does not actualy store the geometry/attributes in RAM). Then you can use the feature layer for input into other tools just as you would a feature class.&lt;BR /&gt;&lt;BR /&gt;For example: &lt;BR /&gt;&lt;BR /&gt;arcpy.MakeFeatureLayer_management(infeatures, "my_feature_layer", "Job_Num = " + str(userinput))&lt;BR /&gt;arcpy.Clip_analysis("my_feature_layer", ....)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, this seems to be the kind of selection I am looking for.&amp;nbsp; How would I then zoom to the temp feature layer using python?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 09 Sep 2012 12:25:27 GMT</pubDate>
    <dc:creator>NoahHuntington</dc:creator>
    <dc:date>2012-09-09T12:25:27Z</dc:date>
    <item>
      <title>Select Records</title>
      <link>https://community.esri.com/t5/python-questions/select-records/m-p/98560#M7656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am attempting to prepare script which will be used for script tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;First, I am only interested in selecting features then intend on appending zoom to selected routine to the end of code shown here.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Having said that I may not even be using the correct tool (select_analysis) but am unsure of one that allows for selection only. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regardless if I could nail down the syntax I am confident I could switch tools effectively.&amp;nbsp; Could someone suggest a better tool and&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;help with debugging.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;

# This script runs the Select tool. The user supplies the input
import arcpy

# Get the input parameters for the Select tool
infeatures = arcpy.GetParameterAsText(0)
userinput = arcpy.GetParameterAsText(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Run the Select tool
arcpy.Select_analysis(infeatures, "NEW_SELECTION", '\Job_Num\" = %s' % userinput)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Sep 2012 20:30:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-records/m-p/98560#M7656</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-07T20:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Select Records</title>
      <link>https://community.esri.com/t5/python-questions/select-records/m-p/98561#M7657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It depends on what you want to do with the selected set, but typically I use the MakeFeatureLayer tool to apply rapid selections (runs faster than the SelectLayerByAttribute tool). The Select tool actually creates a new featureclass on disk, so has the additional overhead of writting to disk... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The MakeFeatureLayer tool creates a "feature layer" that is an in memory reference to the selcted features on disk (but does not actualy store the geometry/attributes in RAM). Then you can use the feature layer for input into other tools just as you would a feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management(infeatures, "my_feature_layer", "Job_Num = " + str(userinput))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Clip_analysis("my_feature_layer", ....)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Sep 2012 22:12:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-records/m-p/98561#M7657</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-09-07T22:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Select Records</title>
      <link>https://community.esri.com/t5/python-questions/select-records/m-p/98562#M7658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It depends on what you want to do with the selected set, but typically I use the MakeFeatureLayer tool to apply rapid selections (runs faster than the SelectLayerByAttribute tool). The Select tool actually creates a new featureclass on disk, so has the additional overhead of writting to disk... &lt;BR /&gt;&lt;BR /&gt;The MakeFeatureLayer tool creates a "feature layer" that is an in memory reference to the selcted features on disk (but does not actualy store the geometry/attributes in RAM). Then you can use the feature layer for input into other tools just as you would a feature class.&lt;BR /&gt;&lt;BR /&gt;For example: &lt;BR /&gt;&lt;BR /&gt;arcpy.MakeFeatureLayer_management(infeatures, "my_feature_layer", "Job_Num = " + str(userinput))&lt;BR /&gt;arcpy.Clip_analysis("my_feature_layer", ....)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, this seems to be the kind of selection I am looking for.&amp;nbsp; How would I then zoom to the temp feature layer using python?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Sep 2012 12:25:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-records/m-p/98562#M7658</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-09T12:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Select Records</title>
      <link>https://community.esri.com/t5/python-questions/select-records/m-p/98563#M7659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;See this Help topic: &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000051000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000051000000&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;Try using the featurelayer's SQL 1st... You may "have to" use the SelectLayerByAttribute tool though... I am not totally familiar with the arcpy.mapping module.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Sep 2012 18:29:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-records/m-p/98563#M7659</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-09-09T18:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: Select Records</title>
      <link>https://community.esri.com/t5/python-questions/select-records/m-p/98564#M7660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;See this Help topic: &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000051000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000051000000&lt;/A&gt;&lt;BR /&gt;Try using the featurelayer's SQL 1st... You may "have to" use the SelectLayerByAttribute tool though... I am not totally familiar with the arcpy.mapping module.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You have been quite helpful, thanks again.&amp;nbsp; How should the variable syntax (type string?) look in the selectbyattribute tool; similar to what you did in the makefeaturelayer where clause?&amp;nbsp; still not quite there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what I have...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# This script runs the Select tool. The user supplies the input
import arcpy

#Set the workspace
arcpy.env.workspace = "G:\\PRAD\\PRAD_v10.1.gdb"

#Retrieve input
userinput = arcpy.GetParametersAsText(0)

# Make a layer from the feature class based on whereclause from input
arcpy.MakeFeatureLayer_management ("tax_acct", "lyr", "Job_Num = " + str(userinput))

# Select that layer
arcpy.SelectLayerByAttribute_management("lyr", "NEW_SELECTION")

#Zoom to selected
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
df.zoomToSelectedFeatures()
df.scale = df.scale * 1.1
arcpy.RefreshActiveView()

# Clear the selection and refresh the active view
arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
arcpy.RefreshActiveView()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:09:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-records/m-p/98564#M7660</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2021-12-11T06:09:13Z</dc:date>
    </item>
  </channel>
</rss>

