<?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: ToolValidator code - script tool output type dataset force .dbf extension in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/toolvalidator-code-script-tool-output-type-dataset/m-p/673581#M52100</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;No clue, but perhaps it interprets != "Table" as being true if a shapefile is the input, is there anyway you can check to see whether a *.shp or shapefile or featureclass is checked rather than a table?&amp;nbsp; &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, it's definitely seeing shapefiles as features. &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.Describe("polygon_Diss").dataType
u'FeatureLayer'
&amp;gt;&amp;gt;&amp;gt; arcpy.Describe(r"D:\Users\cprice\work\polygon_Diss.shp").dataType
u'ShapeFile'&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I debug the validation code, I can see that the path IS getting calcualted. The issue is with the internal validation of the output, which is changing the extension back from ".shp" to ".dbf" after I painstakingly change it!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:25:15 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2021-12-12T04:25:15Z</dc:date>
    <item>
      <title>ToolValidator code - script tool output type dataset force .dbf extension</title>
      <link>https://community.esri.com/t5/python-questions/toolvalidator-code-script-tool-output-type-dataset/m-p/673579#M52098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a tool that takes a table view as input and outputs either a feature class or table, depending on the input. Of course the parameter data type is read only so I can't change that in the ToolValidator class&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I set the input data type is "Table View" and the output data type to "Dataset", and this seems to work. The problem I'm having is that the validator always adds a .dbf extension for folder workspaces (the output still makes a shapefile and adds the shapefile feature class to the map). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can change the path to .shp manually in the tool dialog and that seems to work fine. But I'd like it to go to .shp if the output workspace is a folder and the input is a feature layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my validation code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
&amp;nbsp; def updateParameters(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the values and properties of parameters before internal
&amp;nbsp;&amp;nbsp;&amp;nbsp; validation is performed.&amp;nbsp; This method is called whenever a parameter
&amp;nbsp;&amp;nbsp;&amp;nbsp; has been changed."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; if self.params[0].value and self.params[1].value:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ds =&amp;nbsp; self.params[0].value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Describe(ds).dataType[:5] != "Table":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out = str(self.params[1].value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.splitext(out)[1] == ".dbf":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[1].value = os.path.splitext(out)[0] + ".shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # the above change does not "stick" - the internal validation
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # switches it back to .dbf
&amp;nbsp;&amp;nbsp;&amp;nbsp; return

&amp;nbsp; def updateMessages(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the messages created by internal validation for each tool
&amp;nbsp;&amp;nbsp;&amp;nbsp; parameter.&amp;nbsp; This method is called after internal validation."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; # I needed add this because the default validation
&amp;nbsp;&amp;nbsp;&amp;nbsp; # was not finding existing data and warning me.
&amp;nbsp;&amp;nbsp;&amp;nbsp; if self.params[1].value:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(self.params[1].value):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[1].setIDMessage("Error",1251)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Screen shot: [ATTACH=CONFIG]30603[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jan 2014 14:27:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolvalidator-code-script-tool-output-type-dataset/m-p/673579#M52098</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-01-17T14:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: ToolValidator code - script tool output type dataset force .dbf extension</title>
      <link>https://community.esri.com/t5/python-questions/toolvalidator-code-script-tool-output-type-dataset/m-p/673580#M52099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No clue, but perhaps it interprets != "Table" as being true if a shapefile is the input, is there anyway you can check to see whether a *.shp or shapefile or featureclass is checked rather than a table?&amp;nbsp; I tend to do this thing at the tool level in ArcToolbox rather than using validator scripts.&amp;nbsp; There may be some order of prescedence on how things are run within Arctoolbox&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jan 2014 19:39:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolvalidator-code-script-tool-output-type-dataset/m-p/673580#M52099</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-01-17T19:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: ToolValidator code - script tool output type dataset force .dbf extension</title>
      <link>https://community.esri.com/t5/python-questions/toolvalidator-code-script-tool-output-type-dataset/m-p/673581#M52100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;No clue, but perhaps it interprets != "Table" as being true if a shapefile is the input, is there anyway you can check to see whether a *.shp or shapefile or featureclass is checked rather than a table?&amp;nbsp; &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, it's definitely seeing shapefiles as features. &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.Describe("polygon_Diss").dataType
u'FeatureLayer'
&amp;gt;&amp;gt;&amp;gt; arcpy.Describe(r"D:\Users\cprice\work\polygon_Diss.shp").dataType
u'ShapeFile'&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I debug the validation code, I can see that the path IS getting calcualted. The issue is with the internal validation of the output, which is changing the extension back from ".shp" to ".dbf" after I painstakingly change it!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:25:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/toolvalidator-code-script-tool-output-type-dataset/m-p/673581#M52100</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-12T04:25:15Z</dc:date>
    </item>
  </channel>
</rss>

