<?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: Model builder get count and delete in ModelBuilder Questions</title>
    <link>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824024#M3411</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; &lt;BR /&gt;followed by error 000732 input rows for my "target shapfile"&amp;nbsp; does not exist or is not supported failed to execute (getcount)&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It's very important that you use this syntax to pass dataset model elements to Calculate Value so the pathname will get through to Python correctly:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Courier New;"&gt;r + " + % + elementname + % + " &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 style="font-family:Courier New;"&gt;r"%Output shapefile%"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's also very important that you spell the element name correctly, otherwise the variable isn't recognized and passed on to the code block; and the function then will see something like "%Target Shapfile%". This is so easy to do that my usual method to do this is to a) right click the model element, b) pick Rename, c) copy, cancel, d) open the Calculate Value tool and paste the name between the %%'s in the expression field.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Mar 2013 20:21:41 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2013-03-14T20:21:41Z</dc:date>
    <item>
      <title>Model builder get count and delete</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824020#M3407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've built a model that should work as far as I can tell.&amp;nbsp; I'm using the get count to check a shape file for entries. Then using the calculate value to serve as a precondition to the delete tool.&amp;nbsp; The calculate value tool takes in the Row Count and puts out a false if there are values and a true if there are zero values.&amp;nbsp; This breaks the iteration before the delete tool if values exist&amp;nbsp; Essentially I'm iterating through a directory and want to delete any shape files that have 0 features in them.&amp;nbsp; When I run the model features with 0 rows are still created and in the dialogue box it says all the inputs are not current when it runs over a feature that's supposed to be deleted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My calculate value code is&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fn("%Row Count%")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;block&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def fn(rowcount):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rowcount == 0:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "true"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "false"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;data type&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;boolean&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What am I missing?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Mar 2013 20:16:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824020#M3407</guid>
      <dc:creator>leewinslow1</dc:creator>
      <dc:date>2013-03-13T20:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Model builder get count and delete</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824021#M3408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Edit--&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i figured out the not all inputs are current error.&amp;nbsp; setting the get count as pre condition to calculate vale tool caused the error.&amp;nbsp; When a feature with that returned a zero count was run the get count puts out a zero which causes the pre condition to fail before it ever reached the calculate value or delete tool.&amp;nbsp; I've got that changed&amp;nbsp; now but my calculate value is still returning a false value when zero features are present. This means the shapfile never gets deleted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 12:40:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824021#M3408</guid>
      <dc:creator>leewinslow1</dc:creator>
      <dc:date>2013-03-14T12:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Model builder get count used as precondition</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824022#M3409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Yes, this will get you!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The trick here is to do the GetCount inside the calculate value. A little Python goes a long way in ModelBuilder!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"Output feature class" is the model element for your shapefile that you want to delete if it is empty.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You should have Output feature class be precondition for this Calculate Value tool so it will run at the right time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;expression:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN&gt;DeleteIfZeroCount(r"%Output feature class%")&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;code block:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def DeleteIfZeroCount(inFC):
&amp;nbsp; import arcpy
&amp;nbsp; if int(arcpy.GetCount_management(inFC).getOutput(0)) == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(inFC)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return True
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return False&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:48:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824022#M3409</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-12T09:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Model builder get count and delete</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824023#M3410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Running into an error now.&amp;nbsp; Getting error code 00539 error running expression failed to execute parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;followed by error 000732 input rows for my "target shapfile"&amp;nbsp; does not exist or is not supported failed to execute (getcount)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 18:17:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824023#M3410</guid>
      <dc:creator>leewinslow1</dc:creator>
      <dc:date>2013-03-14T18:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Model builder get count and delete</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824024#M3411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; &lt;BR /&gt;followed by error 000732 input rows for my "target shapfile"&amp;nbsp; does not exist or is not supported failed to execute (getcount)&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It's very important that you use this syntax to pass dataset model elements to Calculate Value so the pathname will get through to Python correctly:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Courier New;"&gt;r + " + % + elementname + % + " &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 style="font-family:Courier New;"&gt;r"%Output shapefile%"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's also very important that you spell the element name correctly, otherwise the variable isn't recognized and passed on to the code block; and the function then will see something like "%Target Shapfile%". This is so easy to do that my usual method to do this is to a) right click the model element, b) pick Rename, c) copy, cancel, d) open the Calculate Value tool and paste the name between the %%'s in the expression field.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 20:21:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824024#M3411</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-03-14T20:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Model builder get count and delete</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824025#M3412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Curtis&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I ended up having someone explain some python to me and we weren't able to get the calculate value tool to work.&amp;nbsp; Instead we created a python script doing the same thing and added that to the model.&amp;nbsp; Now it works like a charm.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Python script was&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

invalue = arcpy.Getparameter (0)

if inValue == 0:
&amp;nbsp; outValue = True
Else:
&amp;nbsp; out Value = False

Arcpy.SetParameter(1, outValue)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help though&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:48:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824025#M3412</guid>
      <dc:creator>leewinslow1</dc:creator>
      <dc:date>2021-12-12T09:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Model builder get count and delete</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824026#M3413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lee&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know it's been a long time since you posted this question and solution, but do you mind sending a picture of your model? -If you still have it?&lt;/P&gt;&lt;P&gt;I am having the same problem as you where I am not able to delete empty feature classes created by my model. I've tried many things and contacting you is sort of my last resort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Andreas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 13:26:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824026#M3413</guid>
      <dc:creator>AndreasElmelund_Hass1</dc:creator>
      <dc:date>2015-04-08T13:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Model builder get count and delete</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824027#M3414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think the easiest way may be to do the delete inside the Calculate Value tool. This is up-thread, but here's another shot at it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I said above it's very important that you use the "r" and quotes and percent signs as shown - and that the name matches the name of the model element exactly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Expression:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;DeleteIfEmpty(r"%Shapefile output%")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code block:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
def DeleteIfEmpty(ds):
&amp;nbsp; fcount =&amp;nbsp; int(arcpy.GetCount_management(ds).getOutput(0))
&amp;nbsp; if fcount == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(ds)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:48:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/model-builder-get-count-and-delete/m-p/824027#M3414</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-12T09:48:29Z</dc:date>
    </item>
  </channel>
</rss>

