<?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: checking for existence of input data in toolvalidator crashes arcmap in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39144#M3109</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Even if you put the entire validation code in a try/except?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 25 Aug 2011 16:51:54 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2011-08-25T16:51:54Z</dc:date>
    <item>
      <title>checking for existence of input data in toolvalidator crashes arcmap</title>
      <link>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39143#M3108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to write a toolvalidator which auto-fills various parameters with field names from the selected input feature layer, if the relevant fields exist in the feature layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Trouble is, if the user enters the name of a non-existant input feature layer, it crashes all of arcmap!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I safely check that the data exists?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried variants on arcpy.Exists and arcpy.Describe (surrounded by try/catch) - all lead to the crash.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; defaultnames = {1:"default_name_1",
&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; 2:"default_name_2"}

&amp;nbsp;&amp;nbsp;&amp;nbsp; fcname = self.params[0].value
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fcname and arcpy.Exists(fcname):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(fcname)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datatype = desc.dataType
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if datatype=="FeatureClass" or datatype=="FeatureLayer":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldnames = [f.name for f in desc.fields]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for param_index,name in defaultnames.iteritems():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if name in fieldnames:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[param_index].value = name
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Aug 2011 10:45:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39143#M3108</guid>
      <dc:creator>CrispinCooper</dc:creator>
      <dc:date>2011-08-25T10:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: checking for existence of input data in toolvalidator crashes arcmap</title>
      <link>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39144#M3109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Even if you put the entire validation code in a try/except?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Aug 2011 16:51:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39144#M3109</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2011-08-25T16:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: checking for existence of input data in toolvalidator crashes arcmap</title>
      <link>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39145#M3110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, even if it's all in a try/except block.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Aug 2011 14:59:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39145#M3110</guid>
      <dc:creator>CrispinCooper</dc:creator>
      <dc:date>2011-08-30T14:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: checking for existence of input data in toolvalidator crashes arcmap</title>
      <link>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39146#M3111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, some progress on this one.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The crash only happens when the input param type is set to 'layer' rather than 'feature class'.&amp;nbsp; Some of the other parameters have type 'field' obtained for the initial input param.&amp;nbsp; Maybe the internal validation code is crashing when trying to list fields in a layer instead of a feature class?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, put input param type back to 'feature class' and all is well, except the tool is a pain in the backside to use now.&amp;nbsp; I have started a different thread on how to use layers as inputs.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 12:24:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39146#M3111</guid>
      <dc:creator>CrispinCooper</dc:creator>
      <dc:date>2011-09-07T12:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: checking for existence of input data in toolvalidator crashes arcmap</title>
      <link>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39147#M3112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For anyone watching - after dialog with support, it turns out upgrading to arc 10 service pack 3 fixes this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/content/patches-and-service-packs?fa=viewPatch&amp;amp;PID=17&amp;amp;MetaID=1807#install-winSteps"&gt;http://resources.arcgis.com/content/patches-and-service-packs?fa=viewPatch&amp;amp;PID=17&amp;amp;MetaID=1807#install-winSteps&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The line causing the crash was the first one where I read self.params[0].value.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Nov 2011 13:19:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-for-existence-of-input-data-in/m-p/39147#M3112</guid>
      <dc:creator>CrispinCooper</dc:creator>
      <dc:date>2011-11-03T13:19:44Z</dc:date>
    </item>
  </channel>
</rss>

