<?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: Selecting multiple subsets in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132810#M10311</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;[ATTACH=CONFIG]17781[/ATTACH][ATTACH=CONFIG]17782[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Successful in first run...Second returned no selections when the first two parameters clearly exist?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Sep 2012 20:15:39 GMT</pubDate>
    <dc:creator>NoahHuntington</dc:creator>
    <dc:date>2012-09-18T20:15:39Z</dc:date>
    <item>
      <title>Selecting multiple subsets</title>
      <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132806#M10307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;[ATTACH=CONFIG]17770[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Zooming to full extent when optional parameter values&amp;nbsp; are not entered.&amp;nbsp; Can anybody tell me why this is?&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;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; sub = arcpy.GetParameterAsText(0) &amp;nbsp;&amp;nbsp;&amp;nbsp; unit = arcpy.GetParameterAsText(1) &amp;nbsp;&amp;nbsp;&amp;nbsp; blk = arcpy.GetParameterAsText(2) &amp;nbsp;&amp;nbsp;&amp;nbsp; lot = arcpy.GetParameterAsText(3) &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;&amp;nbsp; arcpy.AddMessage(sub) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(unit) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(blk) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(lot) &amp;nbsp;&amp;nbsp;&amp;nbsp;&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 = "SUBDIVISIO = '%s'" % (sub) &amp;nbsp;&amp;nbsp;&amp;nbsp; query1 = "UNIT_NUMBE = '%s'" % (unit) &amp;nbsp;&amp;nbsp;&amp;nbsp; query2 = "BLOCK_NUMB = '%s'" % (blk) &amp;nbsp;&amp;nbsp;&amp;nbsp; query3 = "LOT_NUMBER = '%s'" % (lot)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(query) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(query1) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(query2) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(query3)&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; arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", query) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "SUBSET_SELECTION", query1) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "SUBSET_SELECTION", query2) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "SUBSET_SELECTION", query3) &amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp; main()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 17:34:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132806#M10307</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-18T17:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple subsets</title>
      <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132807#M10308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If nothing was selcted, what would you want the tool to do?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Perhaps you could have something check if any records/features were selected?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Like GetCount_mangement()&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 17:51:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132807#M10308</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-09-18T17:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple subsets</title>
      <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132808#M10309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Its true.&amp;nbsp; I definitely need to add some error handling to the script.&amp;nbsp; I am just confused b/c I am sure there are records for SLEEPY HOLLOW and unit 4 (the default values)? Infact when all parameters are filled it works fine.&amp;nbsp; What do you think?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 18:00:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132808#M10309</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-18T18:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple subsets</title>
      <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132809#M10310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I guess my suggestion was to just make sure the queries are being executed correctly...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, insert something like this after the SelectlayerByAttribute tools run:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.AddMessage("Query selected " + str(arcpy.GetCount_management(lyr).getoutput(0) + " records...")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 19:38:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132809#M10310</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-09-18T19:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple subsets</title>
      <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132810#M10311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;[ATTACH=CONFIG]17781[/ATTACH][ATTACH=CONFIG]17782[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Successful in first run...Second returned no selections when the first two parameters clearly exist?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 20:15:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132810#M10311</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-18T20:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple subsets</title>
      <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132811#M10312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Successful in first run...Second returned no selections when the first two parameters clearly exist?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]17784[/ATTACH][ATTACH=CONFIG]17785[/ATTACH][ATTACH=CONFIG]17786[/ATTACH][ATTACH=CONFIG]17787[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 20:21:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132811#M10312</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-18T20:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple subsets</title>
      <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132812#M10313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay I get what you are doing... Here's what's wrong:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If one of your query parameters is left blank, then you need to not execute that query. Blank parametrs are pased back to the script as a blank string. So for example if param3 and param4 are blank:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;param1 = "Dog"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;param2 = "3"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;param3 = ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;param4 = ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then in your query, when the query for param3 (a subset) is executed, basically you are saying "take my current selection, and from thoss records select the records where "MYFIELD = ''". Which correctly returns 0 records, becasue you don't have any subset records with '' (blank) values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What you need to do is if any of the query parameters is blank (i.e. ''), then don't execute that particular query. The logic of this may be a bit longwinded.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", query) if unit != "": &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "SUBSET_SELECTION", query1) if blk != "": &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "SUBSET_SELECTION", query2) if lot != "": &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "SUBSET_SELECTION", query3)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 20:29:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132812#M10313</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-09-18T20:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple subsets</title>
      <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132813#M10314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Works great now!!! Thanks Chris.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 21:02:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132813#M10314</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-18T21:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple subsets</title>
      <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132814#M10315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If alright I'd like to take this opportunity to pick your brain abit more?&amp;nbsp; If I wanted to swap parameter #1 (currently arcpy.GetParameterAsText(0)) with a combobox populated with unique attributes from a field.&amp;nbsp; What might that look like?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2012 14:50:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132814#M10315</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2012-09-19T14:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple subsets</title>
      <link>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132815#M10316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Combo Box:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. The simplest way is to set the parameters "MultiValue" property to Yes, and then provide some optional parameters.... which involves manually typing them all in to the Toolbox GUI when you set up the script tool: &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Setting_script_tool_parameters/00150000000n000000/"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/Setting_script_tool_parameters/00150000000n000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Another way is to dynamically read the possible combo box field values from some existing table or some sort of script logic. This would be accomlished with a "tool validator class": &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Customizing_script_tool_behavior/00150000000t000000/"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/Customizing_script_tool_behavior/00150000000t000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Yet another way (new in v10.1) is a "Python Toolbox", which I think has a different flavor of a "tool validator": &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Creating_a_new_Python_toolbox/001500000034000000/"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/Creating_a_new_Python_toolbox/001500000034000000/&lt;/A&gt;&lt;SPAN&gt;. I havn't messed with that one yet.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2012 16:04:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-multiple-subsets/m-p/132815#M10316</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-09-19T16:04:59Z</dc:date>
    </item>
  </channel>
</rss>

