<?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 Setting an error message in a script tool for an existing feature class name with Validation in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/setting-an-error-message-in-a-script-tool-for-an/m-p/1189807#M64936</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have collaborated to the creation of a tool that transforms feature layer's coordinates from an unknown coordinate system to ETRS89. The tool allows the user to set the name of the newly transformed feature class through a string Parameter. If the name of the newly transformed feature already exist in the chosen dataset, the tool will return an error, however no error message appears before running the tool. I am aware that this error message can be set with validation from the script properties, as previously I have already set a similar message for another tool for an excising field name however, I am finding it difficult to do the same for this tool.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I set the error message for the field name I used the following commands, where params[0] is the Input Feature Class and Params[1] is the Newly created field in the input feature class:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;import arcpy&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;import os&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;class ToolValidator(object):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Class for validating a tool's parameter values and controlling&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;the behavior of the tool's dialog."""&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def __init__(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Setup arcpy and the list of tool parameters."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params = arcpy.GetParameterInfo()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;def initializeParameters(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Refine the properties of a tool's parameters. This method is&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;called when the tool is opened."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def updateParameters(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Modify the values and properties of parameters before internal&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;validation is performed. This method is called whenever a parameter&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;has been changed."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;desc = arcpy.Describe(self.params[0])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;flist = desc.fields&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;if self.params[1].valueAsText in [x.name for x in flist]:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params[1].setErrorMessage('Field name already exists')&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def updateMessages(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Modify the messages created by internal validation for each tool&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;parameter. This method is called after internal validation."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;desc = arcpy.Describe(self.params[0])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;flist = desc.fields&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;if self.params[1].valueAsText in [x.name for x in flist]:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params[1].setErrorMessage('Field name already exists')&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I am trying to do something similar for the feature layer name, as this time I am trying to describe the children of the dataset and then list their names. Here Params[2] is the input Dataset at which the transformed feature layer is saved, and Params[3] is an input string parameter that corresponds&amp;nbsp;to the name of the transformed feature layer:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;import arcpy&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;class ToolValidator(object):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Class for validating a tool's parameter values and controlling&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;the behavior of the tool's dialog."""&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def __init__(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Setup arcpy and the list of tool parameters."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params = arcpy.GetParameterInfo()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def initializeParameters(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Refine the properties of a tool's parameters. This method is&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;called when the tool is opened."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def updateParameters(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Modify the values and properties of parameters before internal&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;validation is performed. This method is called whenever a parameter&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;has been changed."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;desc = arcpy.Describe(self.params[2].children)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;flist = desc.name&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;if self.params[3].valueAsText in [x.name for x in flist]:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params[3].setErrorMessage('Feature class name already exists')&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def updateMessages(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Modify the messages created by internal validation for each tool&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;parameter. This method is called after internal validation."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;desc = arcpy.Describe(self.params[2].children)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;flist = desc.name&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;if self.params[3].valueAsText in [x.name for x in flist]:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params[3].setErrorMessage('Feature class name already exists')&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;However since no error is given when I test it I am obviously missing something, or am probably giving a totally wrong command. Any ideas are greatly appreciated!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jul 2022 13:35:10 GMT</pubDate>
    <dc:creator>KalinaStoycheva</dc:creator>
    <dc:date>2022-07-06T13:35:10Z</dc:date>
    <item>
      <title>Setting an error message in a script tool for an existing feature class name with Validation</title>
      <link>https://community.esri.com/t5/python-questions/setting-an-error-message-in-a-script-tool-for-an/m-p/1189807#M64936</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have collaborated to the creation of a tool that transforms feature layer's coordinates from an unknown coordinate system to ETRS89. The tool allows the user to set the name of the newly transformed feature class through a string Parameter. If the name of the newly transformed feature already exist in the chosen dataset, the tool will return an error, however no error message appears before running the tool. I am aware that this error message can be set with validation from the script properties, as previously I have already set a similar message for another tool for an excising field name however, I am finding it difficult to do the same for this tool.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I set the error message for the field name I used the following commands, where params[0] is the Input Feature Class and Params[1] is the Newly created field in the input feature class:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;import arcpy&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;import os&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;class ToolValidator(object):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Class for validating a tool's parameter values and controlling&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;the behavior of the tool's dialog."""&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def __init__(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Setup arcpy and the list of tool parameters."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params = arcpy.GetParameterInfo()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;def initializeParameters(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Refine the properties of a tool's parameters. This method is&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;called when the tool is opened."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def updateParameters(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Modify the values and properties of parameters before internal&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;validation is performed. This method is called whenever a parameter&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;has been changed."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;desc = arcpy.Describe(self.params[0])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;flist = desc.fields&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;if self.params[1].valueAsText in [x.name for x in flist]:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params[1].setErrorMessage('Field name already exists')&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def updateMessages(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Modify the messages created by internal validation for each tool&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;parameter. This method is called after internal validation."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;desc = arcpy.Describe(self.params[0])&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;flist = desc.fields&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;if self.params[1].valueAsText in [x.name for x in flist]:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params[1].setErrorMessage('Field name already exists')&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I am trying to do something similar for the feature layer name, as this time I am trying to describe the children of the dataset and then list their names. Here Params[2] is the input Dataset at which the transformed feature layer is saved, and Params[3] is an input string parameter that corresponds&amp;nbsp;to the name of the transformed feature layer:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;import arcpy&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;class ToolValidator(object):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Class for validating a tool's parameter values and controlling&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;the behavior of the tool's dialog."""&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def __init__(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Setup arcpy and the list of tool parameters."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params = arcpy.GetParameterInfo()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def initializeParameters(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Refine the properties of a tool's parameters. This method is&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;called when the tool is opened."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def updateParameters(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Modify the values and properties of parameters before internal&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;validation is performed. This method is called whenever a parameter&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;has been changed."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;desc = arcpy.Describe(self.params[2].children)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;flist = desc.name&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;if self.params[3].valueAsText in [x.name for x in flist]:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params[3].setErrorMessage('Feature class name already exists')&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;def updateMessages(self):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;"""Modify the messages created by internal validation for each tool&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;parameter. This method is called after internal validation."""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;desc = arcpy.Describe(self.params[2].children)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;flist = desc.name&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;if self.params[3].valueAsText in [x.name for x in flist]:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;self.params[3].setErrorMessage('Feature class name already exists')&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#808080"&gt;return&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;However since no error is given when I test it I am obviously missing something, or am probably giving a totally wrong command. Any ideas are greatly appreciated!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 13:35:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-an-error-message-in-a-script-tool-for-an/m-p/1189807#M64936</guid>
      <dc:creator>KalinaStoycheva</dc:creator>
      <dc:date>2022-07-06T13:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Setting an error message in a script tool for an existing feature class name with Validation</title>
      <link>https://community.esri.com/t5/python-questions/setting-an-error-message-in-a-script-tool-for-an/m-p/1189838#M64938</link>
      <description>&lt;P&gt;I think it would error on 'x.name' since the string 'f' doesn't have a method of .name.&amp;nbsp; Since .desc returns a string, doing [x for x in flist] iterates over the characters in the name. i.e, if the flist is 'fcname',&amp;nbsp; you are checking&amp;nbsp; x.name against 'f','c','n','a','m','e'.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;flist = desc.name
if self.params[3].valueAsText in [x.name for x in flist]:&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try this:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if self.params[3].valueAsText == flist:&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 13:46:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-an-error-message-in-a-script-tool-for-an/m-p/1189838#M64938</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-07-06T13:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Setting an error message in a script tool for an existing feature class name with Validation</title>
      <link>https://community.esri.com/t5/python-questions/setting-an-error-message-in-a-script-tool-for-an/m-p/1189841#M64939</link>
      <description>&lt;P&gt;Solved it! The validation should be as followed:&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;class ToolValidator(object):&lt;BR /&gt;"""Class for validating a tool's parameter values and controlling&lt;BR /&gt;the behavior of the tool's dialog."""&lt;/P&gt;&lt;P&gt;def __init__(self):&lt;BR /&gt;"""Setup arcpy and the list of tool parameters."""&lt;BR /&gt;self.params = arcpy.GetParameterInfo()&lt;/P&gt;&lt;P&gt;def initializeParameters(self):&lt;BR /&gt;"""Refine the properties of a tool's parameters. This method is&lt;BR /&gt;called when the tool is opened."""&lt;BR /&gt;return&lt;/P&gt;&lt;P&gt;def updateParameters(self):&lt;BR /&gt;"""Modify the values and properties of parameters before internal&lt;BR /&gt;validation is performed. This method is called whenever a parameter&lt;BR /&gt;has been changed."""&lt;BR /&gt;desc = arcpy.Describe(self.params[2])&lt;BR /&gt;flist = desc.children&lt;BR /&gt;if self.params[3].valueAsText in [child.name for child in flist]:&lt;BR /&gt;self.params[3].setErrorMessage('Feature class name already exists')&lt;BR /&gt;return&lt;/P&gt;&lt;P&gt;def updateMessages(self):&lt;BR /&gt;"""Modify the messages created by internal validation for each tool&lt;BR /&gt;parameter. This method is called after internal validation."""&lt;BR /&gt;desc = arcpy.Describe(self.params[2])&lt;BR /&gt;flist = desc.children&lt;BR /&gt;if self.params[3].valueAsText in [child.name for child in flist]:&lt;BR /&gt;self.params[3].setErrorMessage('Feature class name already exists')&lt;BR /&gt;return&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 13:51:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-an-error-message-in-a-script-tool-for-an/m-p/1189841#M64939</guid>
      <dc:creator>KalinaStoycheva</dc:creator>
      <dc:date>2022-07-06T13:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Setting an error message in a script tool for an existing feature class name with Validation</title>
      <link>https://community.esri.com/t5/python-questions/setting-an-error-message-in-a-script-tool-for-an/m-p/1189844#M64940</link>
      <description>&lt;P&gt;Thank you, yeah the problem was with x.name for x, I changed the validation to:&lt;/P&gt;&lt;P&gt;desc = arcpy.Describe(self.params[2])&lt;BR /&gt;flist = desc.children&lt;BR /&gt;if self.params[3].valueAsText in [child.name for child in flist]:&lt;BR /&gt;self.params[3].setErrorMessage('Feature class name already exists')&lt;BR /&gt;return&lt;/P&gt;&lt;P&gt;and it worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 13:54:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-an-error-message-in-a-script-tool-for-an/m-p/1189844#M64940</guid>
      <dc:creator>KalinaStoycheva</dc:creator>
      <dc:date>2022-07-06T13:54:04Z</dc:date>
    </item>
  </channel>
</rss>

