<?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 from user input variable in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630284#M49064</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;For each field you will need a new parameter added to your tool. There are a couple ways to go about it, and it gets a little more complicated if you want it to be dynamic (eg a user can select any number of fields to put in the query).&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; job_num = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; job_num2 = arcpy.GetParameterAsText(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; job_num3 = arcpy.GetParameterAsText(2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create where clause for selection
&amp;nbsp;&amp;nbsp;&amp;nbsp; query = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; query_list = [("Job_Num", job_num), ("Job_Num2", job_num2), ("Job_Num3", job_num3)]
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field_name, variable in query_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = query + "%s = '%s' " % (field_name, variable)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Something like that should get you on track. May require some tinkering to make it work for you.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok. I will see what I can do with that.&amp;nbsp; Thanks for all your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 02:49:17 GMT</pubDate>
    <dc:creator>NoahHuntington</dc:creator>
    <dc:date>2021-12-12T02:49:17Z</dc:date>
    <item>
      <title>Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630265#M49045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Please help.&amp;nbsp; Unable to make selection.&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="plain" name="code"&gt;# Model selects parcel from user input import arcpy&amp;nbsp; # Assign variable to the feature class featureClass = "G:\\PRAD\\PRAD_v10.1.gdb\\tax_acct"&amp;nbsp; # Assign variable to users input input = arcpy.GetParameterAsText(0)&amp;nbsp; # Make a feature layer from feature class arcpy.MakeFeatureLayer_management(featureClass, "layer") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Apply a selection to the feature layer&amp;nbsp; arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", '"'+str(input)+'"') &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 15:27:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630265#M49045</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-10T15:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630266#M49046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The last line shouldn't be indented. Are you getting a syntax error or some other error? Also, what is the value of your input variable? Try using AddMessage to see if it is passing how you would expect it to.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 15:38:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630266#M49046</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-09-10T15:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630267#M49047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The last line shouldn't be indented. Are you getting a syntax error or some other error? Also, what is the value of your input variable? Try using AddMessage to see if it is passing how you would expect it to.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The input is a 6 or 7 digit &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;text&lt;/SPAN&gt;&lt;SPAN&gt; field found in the feature class.&amp;nbsp; The script is run as a tool where the input parameter is set to string.&amp;nbsp; Here is what I currently have...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Selects from user input in tool dialog.&amp;nbsp; 

import arcpy

# Get the layer.
featureClass = "G:\\PRAD\\PRAD_v10.1.gdb\\tax_acct"
input = arcpy.GetParameterAsText(0)

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a feature layer from feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(featureClass, "layer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Apply a selection to the feature layer
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", '"'+str(input)+'"')

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:48:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630267#M49047</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2021-12-12T02:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630268#M49048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You need to print out the actual value of the variable the tool is reading to make sure it is a valid query.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 16:03:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630268#M49048</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-09-10T16:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630269#M49049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You need to print out the actual value of the variable the tool is reading to make sure it is a valid query.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry I must be slow.&amp;nbsp; I am not sure I am following you.&amp;nbsp; Can I see an example?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 16:07:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630269#M49049</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-10T16:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630270#M49050</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Depending on your data type it could look something like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;input = "\"CITY_NAME\" = 'Chicago'"&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;You can see more examples here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 16:11:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630270#M49050</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-09-10T16:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630271#M49051</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Depending on your data type it could look something like this.&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;input = "\"CITY_NAME\" = 'Chicago'"&lt;/PRE&gt;&lt;BR /&gt;You can see more examples here.&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Right. I can see now that something is missing.&amp;nbsp; What does the syntax look like for whereclause when field name is Job_Num and variable is input.&amp;nbsp; Similar to...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;..."Job_Num = " + str(input))&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 17:10:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630271#M49051</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-10T17:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630272#M49052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This should work. You may need to add quotes around your field name, or use the add field delimiters tool to create them for dynamic data sources.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Model selects parcel from user input
import arcpy

# Assign variable to the feature class
featureClass = "G:\\PRAD\\PRAD_v10.1.gdb\\tax_acct"

# Assign variable to users input
input = arcpy.GetParameterAsText(0)

# Make a feature layer from feature class
arcpy.MakeFeatureLayer_management(featureClass, "layer")

# Build selection query
query = "Job_Num = '%s'" % (input)&amp;nbsp; # May need change to "\"Job_Num\" = '%s'"

# Apply a selection to the feature layer
arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", query)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:48:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630272#M49052</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T02:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630273#M49053</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This should work. You may need to add quotes around your field name, or use the add field delimiters tool to create them for dynamic data sources.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Model selects parcel from user input
import arcpy

# Assign variable to the feature class
featureClass = "G:\\PRAD\\PRAD_v10.1.gdb\\tax_acct"

# Assign variable to users input
input = arcpy.GetParameterAsText(0)

# Make a feature layer from feature class
arcpy.MakeFeatureLayer_management(featureClass, "layer")

# Build selection query
query = "Job_Num = '%s'" % (input)&amp;nbsp; # May need change to "\"Job_Num\" = '%s'"

# Apply a selection to the feature layer
arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", query)&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This runs without error but nothing gets selected?&amp;nbsp; I have tested with attributes in the Job_Num field that I have checked to exist. What do you think?&amp;nbsp; Thanks again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:48:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630273#M49053</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2021-12-12T02:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630274#M49054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try adding these lines at the end of your script. This will print how many features are selected, and then refresh the view to make those selections visible.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;selection = int(arcpy.GetCount_management("layer").getOutput(0))
arcpy.AddMessage("%s features selected" % (selection))
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:48:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630274#M49054</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T02:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630275#M49055</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try adding these lines at the end of your script. This will print how many features are selected, and then refresh the view to make those selections visible.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;selection = int(arcpy.GetCount_management("layer").getOutput(0))
arcpy.AddMessage("%s features selected" % (selection))
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I can see 1 selected in results window but still no effect on dataframe? See attached...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:49:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630275#M49055</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2021-12-12T02:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630276#M49056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;[ATTACH=CONFIG]17579[/ATTACH]&lt;/SPAN&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try adding these lines at the end of your script. This will print how many features are selected, and then refresh the view to make those selections visible.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;selection = int(arcpy.GetCount_management("layer").getOutput(0))
arcpy.AddMessage("%s features selected" % (selection))
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I can see 1 selected in results window but still no effect on dataframe? See attached...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:49:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630276#M49056</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2021-12-12T02:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630277#M49057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;[ATTACH=CONFIG]17579[/ATTACH]&lt;BR /&gt; &lt;BR /&gt;I can see 1 selected in results window but still no effect on dataframe? See attached...&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That is because you create a temporary layer called "layer" that you are basing your selections on. I don't see that layer in your TOC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe you should describe what you want to accomplish since it looks like you are going about this the wrong way.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 18:22:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630277#M49057</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-09-10T18:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630278#M49058</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That is because you create a temporary layer called "layer" that you are basing your selections on. I don't see that layer in your TOC.&lt;BR /&gt;&lt;BR /&gt;Maybe you should describe what you want to accomplish since it looks like you are going about this the wrong way.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to create a simple tool to collect user input and zoom to selected feature.&amp;nbsp; ideally would like to select from fc in toc.&amp;nbsp; Any suggestions? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...maybe a search cursor?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 18:25:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630278#M49058</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-10T18:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630279#M49059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I am trying to create a simple tool to collect user input and zoom to selected feature.&amp;nbsp; ideally would like to select from fc in toc.&amp;nbsp; Any suggestions?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Well first of all you don't have feature classes in your TOC, you have layers pointing to your feature classes on disk. These are the objects you make selections on, you cannot make selections on feature classes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try running this as your script. You could also add another input parameter to select the layer manually.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Starting")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get and set variables
&amp;nbsp;&amp;nbsp;&amp;nbsp; job_num = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; layer_name = "tax_acct"
&amp;nbsp;&amp;nbsp;&amp;nbsp; df_name = "Layers"

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(job_num)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Define mxd, df and lyr objects
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, df_name)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.ListLayers(mxd, layer_name, df)[0]

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(lyr.name)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create where clause for selection
&amp;nbsp;&amp;nbsp;&amp;nbsp; query = "Job_Num = '%s'" % (job_num)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(query)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", query)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get number of selected features
&amp;nbsp;&amp;nbsp;&amp;nbsp; selection = int(arcpy.GetCount_management(layer_name).getOutput(0))

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("%s features selected" % (selection))

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set df extent to layer selection
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = lyr.getSelectedExtent()
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Completed")

main()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:49:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630279#M49059</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T02:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630280#M49060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Well first of all you don't have feature classes in your TOC, you have layers pointing to your feature classes on disk. These are the objects you make selections on, you cannot make selections on feature classes.&lt;BR /&gt;&lt;BR /&gt;Try running this as your script. You could also add another input parameter to select the layer manually.&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; def main(): &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Starting")&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Get and set variables &amp;nbsp;&amp;nbsp;&amp;nbsp; job_num = arcpy.GetParameterAsText(0) &amp;nbsp;&amp;nbsp;&amp;nbsp; layer_name = "tax_acct" &amp;nbsp;&amp;nbsp;&amp;nbsp; df_name = "Layers"&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(job_num)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Define mxd, df and lyr objects &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT") &amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, df_name)[0] &amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.ListLayers(mxd, layer_name, df)[0]&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(lyr.name)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Create where clause for selection &amp;nbsp;&amp;nbsp;&amp;nbsp; query = "Job_Num = '%s'" % (job_num)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(query)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", query)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Get number of selected features &amp;nbsp;&amp;nbsp;&amp;nbsp; selection = int(arcpy.GetCount_management(layer_name).getOutput(0))&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("%s features selected" % (selection))&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Set df extent to layer selection &amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = lyr.getSelectedExtent() &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Completed")&amp;nbsp; main()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That was perfect!!!&amp;nbsp; Your fast too!&amp;nbsp; Just a couple questions?&amp;nbsp; What was going on with the addmessages methods? Also some of these features have 1, 2, or 3 possible job numbers associated with them, as in fields Job_Num2, Job_Num3, so on.... Would there be a way add multiple fields to the query?&amp;nbsp; Job_Num, or Job_Num2, or Job_Num3..&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 18:54:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630280#M49060</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-10T18:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630281#M49061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That was perfect!!!&amp;nbsp; Your fast too!&amp;nbsp; Just a couple questions?&amp;nbsp; What was going on with the addmessages methods? Also some of these features have 1, 2, or 3 possible job numbers associated with them, as in fields Job_Num2, Job_Num3, so on.... Would there be a way add multiple fields to the query?&amp;nbsp; Job_Num, or Job_Num2, or Job_Num3..&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The addmessages are there just to check your variables to make sure they are what you are expecting. They are unnecessary for the script itself and more for trouble shooting.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are selecting from multiple fields, are they all the same value from these fields? Or do you want unique values from each field?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Eg&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Job_Num = "first" and Job_Num2 = "first"
# or
Job_Num = "first" and Job_Num2 = "second"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:49:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630281#M49061</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T02:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630282#M49062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The addmessages are there just to check your variables to make sure they are what you are expecting. They are unnecessary for the script itself and more for trouble shooting.&lt;BR /&gt;&lt;BR /&gt;If you are selecting from multiple fields, are they all the same value from these fields? Or do you want unique values from each field?&lt;BR /&gt;Eg&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Job_Num = "first" and Job_Num2 = "first"
# or
Job_Num = "first" and Job_Num2 = "second"
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;They exist b/c we have revisited parcels sometimes multiple times each with a new job number.&amp;nbsp; Added field to table to handle new job number.&amp;nbsp; I am not sure the following is correct, where should this query take place.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get and set variables
&amp;nbsp;&amp;nbsp;&amp;nbsp; Job_Num = "first" and Job_Num2 = "second" = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; layer_name = "tax_acct"
&amp;nbsp;&amp;nbsp;&amp;nbsp; df_name = "Layers"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:49:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630282#M49062</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2021-12-12T02:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630283#M49063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For each field you will need a new parameter added to your tool. There are a couple ways to go about it, and it gets a little more complicated if you want it to be dynamic (eg a user can select any number of fields to put in the query).&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; job_num = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; job_num2 = arcpy.GetParameterAsText(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; job_num3 = arcpy.GetParameterAsText(2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create where clause for selection
&amp;nbsp;&amp;nbsp;&amp;nbsp; query = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; query_list = [("Job_Num", job_num), ("Job_Num2", job_num2), ("Job_Num3", job_num3)]
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field_name, variable in query_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if query == "":&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = "%s = '%s'" % (field_name, variable)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = query + " and %s = '%s'" % (field_name, variable)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Something like that should get you on track. May require some tinkering to make it work for you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:49:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630283#M49063</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T02:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Select from user input variable</title>
      <link>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630284#M49064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;For each field you will need a new parameter added to your tool. There are a couple ways to go about it, and it gets a little more complicated if you want it to be dynamic (eg a user can select any number of fields to put in the query).&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; job_num = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; job_num2 = arcpy.GetParameterAsText(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; job_num3 = arcpy.GetParameterAsText(2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create where clause for selection
&amp;nbsp;&amp;nbsp;&amp;nbsp; query = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; query_list = [("Job_Num", job_num), ("Job_Num2", job_num2), ("Job_Num3", job_num3)]
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field_name, variable in query_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = query + "%s = '%s' " % (field_name, variable)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Something like that should get you on track. May require some tinkering to make it work for you.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok. I will see what I can do with that.&amp;nbsp; Thanks for all your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:49:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-from-user-input-variable/m-p/630284#M49064</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2021-12-12T02:49:17Z</dc:date>
    </item>
  </channel>
</rss>

