<?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 Tool issue in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544122#M88726</link>
    <description>&lt;P&gt;Mark,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tested it, and by making the modification that I suggested above it works for me. Only tweak was as below for line 18 in your script:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;            if param1 is True:
                lyr.definitionQuery = ""&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2024 06:58:42 GMT</pubDate>
    <dc:creator>RichardHowe</dc:creator>
    <dc:date>2024-10-01T06:58:42Z</dc:date>
    <item>
      <title>Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1543285#M88647</link>
      <description>&lt;P&gt;I have a script tool which is supposed to apply a definition query to all layers in a feature service in the map and then remove all empty feature layers from the Contents pane.&amp;nbsp; The tool can successfully apply the definition query but fails to remove the empty layers.&amp;nbsp; I put the code to remove the empty layers in a separate script tool and it works! Any idea why that code won't work in the same script as the definition query code?&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;def script_tool(param0, param1,param2):
    """Script code goes below"""
    aprx = arcpy.mp.ArcGISProject("CURRENT")
    m = aprx.activeMap
    
    for lyr in m.listLayers():
        if lyr.supports("DEFINITIONQUERY"):
            
            #If the Clear Queries option is checked:
            if param2:
                lyr.definitionQuery = ""
            
            else:
            #Apply definition query to all layers in the map
                lyr.definitionQuery = param1           
                
                #Remove empty layers
                arcpy.conversion.ExportFeatures(lyr, "temp")
                results = arcpy.GetCount_management("temp")
                count = results.getOutput(0)
                if count == '0':
                    m.removeLayer(lyr)
    aprx.save()
    return


if __name__ == "__main__":

    param0 = arcpy.GetParameterAsText(0)
    param1 = arcpy.GetParameterAsText(1)
    param2 = arcpy.GetParameterAsText(2)

    script_tool(param0, param1,param2)&lt;/LI-CODE&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;</description>
      <pubDate>Mon, 30 Sep 2024 14:39:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1543285#M88647</guid>
      <dc:creator>MarkHammond4</dc:creator>
      <dc:date>2024-09-30T14:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1543331#M88650</link>
      <description>&lt;P&gt;You don't need to run an export to get a count of your layer. GetCount respects a definition query anyway, so you can run it on the original layer, without creating a temp layer. So you can remove line 18 and replace (what was) line 19 target object with lyr instead of "temp". Like this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;            #Remove empty layers
            results = arcpy.GetCount_management(lyr)
            count = results.getOutput(0)
            if count == '0':
                m.removeLayer(lyr)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Without being able to see what parameter 2 is (it's not in your attached toolbox tool), then it's tricky to know what is going on there. Your if statement simply says:&lt;BR /&gt;&lt;BR /&gt;if param2:&lt;BR /&gt;&lt;BR /&gt;Normally you would give that statement a value e.g.:&lt;BR /&gt;&lt;BR /&gt;if param2 is True:&lt;BR /&gt;&lt;BR /&gt;Which should work if your param 2 is a boolean checkbox (as suggested by your comments). All that would happen in that case is all definition queries would be reset&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2024 07:26:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1543331#M88650</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2024-09-27T07:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1543421#M88661</link>
      <description>&lt;P&gt;Hi Richard, thanks for your reply. I thought exporting the view service layer was necessary to use with GetCount but apparently it isn't. Even without exporting the layer, the removeLayer functionality doesn't work when in the same script as the definition query.&amp;nbsp; I also changed the attached tool to the version which has the Boolean checkbox.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2024 16:57:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1543421#M88661</guid>
      <dc:creator>MarkHammond4</dc:creator>
      <dc:date>2024-09-27T16:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1543713#M88687</link>
      <description>&lt;P&gt;The raw text works for me in a python window (without the if/else statement), so I can only assume it has something to do with that. Unfortunately I can't see an attachment at all now. If you reupload it, I'll take a look.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 07:03:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1543713#M88687</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2024-09-30T07:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1543799#M88698</link>
      <description>&lt;P&gt;toolbox is attached. thanks&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 14:38:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1543799#M88698</guid>
      <dc:creator>MarkHammond4</dc:creator>
      <dc:date>2024-09-30T14:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544122#M88726</link>
      <description>&lt;P&gt;Mark,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tested it, and by making the modification that I suggested above it works for me. Only tweak was as below for line 18 in your script:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;            if param1 is True:
                lyr.definitionQuery = ""&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 06:58:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544122#M88726</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2024-10-01T06:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544354#M88749</link>
      <description>&lt;P&gt;So the tool will both apply the definition query and remove the empty layers for you?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 15:58:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544354#M88749</guid>
      <dc:creator>MarkHammond4</dc:creator>
      <dc:date>2024-10-01T15:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544400#M88751</link>
      <description>&lt;P&gt;Yes, it works. Removes the empty one, leaves the one with records once I'd made that change&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 17:02:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544400#M88751</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2024-10-01T17:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544402#M88753</link>
      <description>&lt;P&gt;For some reason the tool won't execute the whole script the first time I click Run. It only applies the definition query. I have to click Run again for it to remove the empty layers!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 17:09:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544402#M88753</guid>
      <dc:creator>MarkHammond4</dc:creator>
      <dc:date>2024-10-01T17:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544620#M88768</link>
      <description>&lt;P&gt;Does it throw any error or warning messages in your geoprocessing history when you've just clicked it once? And have you amended line 18 to match mine?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 06:59:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544620#M88768</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2024-10-02T06:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Script Tool issue</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544831#M88789</link>
      <description>&lt;P&gt;I don't get any error or warning messages.&amp;nbsp; Yes I've amended line 18 to match yours and even tried removing the Clear Queries option and the if/else statement for it but it makes no difference.&amp;nbsp; Another person tested the tool and got the same results I get.&amp;nbsp; What version of ArcPro do you have?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 16:04:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/script-tool-issue/m-p/1544831#M88789</guid>
      <dc:creator>MarkHammond4</dc:creator>
      <dc:date>2024-10-02T16:04:13Z</dc:date>
    </item>
  </channel>
</rss>

