<?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: Older Toolbox Python Script Error (Tool Failed to Open, Tabs/Spaces Syntax) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/older-toolbox-python-script-error-tool-failed-to/m-p/1389780#M70002</link>
    <description>&lt;P&gt;I have an update, while poking around the validate tab on the script properties, I noticed some errors with regards to the spacing and indents:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SimonBV_0-1709333209063.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96565i7FBBA1589E2AC763/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SimonBV_0-1709333209063.png" alt="SimonBV_0-1709333209063.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
class ToolValidator(object):
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""

  def __init__(self):
    """Setup arcpy and the list of tool parameters."""
    self.params = arcpy.GetParameterInfo()

  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    return

  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    inDEM = self.params[0].value
    if self.params[2].value:
	if inDEM: 
            if arcpy.Describe(inDEM).spatialReference.type == "Geographic":
	        self.params[2].value = 9.01248403045503E-06
	    if arcpy.Describe(inDEM).spatialReference.type == "Projected":
		self.params[2].value = 1
    return

  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    inFC = self.params[0].value
    self.params[0].clearMessage()
    if self.params[0].value is None:
        self.params[0].clearMessage()
    else:
        if inFC:
            desc = arcpy.Describe(inFC) 
            sr = desc.spatialReference
            if sr.type == "Geographic":
                self.params[0].setErrorMessage("Data needs to be in a Projected Coordinate System")
            else:
                self.params[0].clearMessage()
    return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the error lies within the validation. It seems that there is an included validation step for "inDEM" to ensure it is in a projected coordinate system, and to convert it to a projection. All I ended up doing was replacing the the updateParameters so that it showed this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    return&lt;/LI-CODE&gt;&lt;P&gt;Instead of this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    inDEM = self.params[0].value
    if self.params[2].value:
        if inDEM: 
            if arcpy.Describe(inDEM).spatialReference.type == "Geographic":
	        self.params[2].value = 9.01248403045503E-06
	    if arcpy.Describe(inDEM).spatialReference.type == "Projected":
		self.params[2].value = 1
    return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Seems to work now, hope this helps people in a similar boat!&lt;/P&gt;</description>
    <pubDate>Fri, 01 Mar 2024 23:02:41 GMT</pubDate>
    <dc:creator>SimonBV</dc:creator>
    <dc:date>2024-03-01T23:02:41Z</dc:date>
    <item>
      <title>Older Toolbox Python Script Error (Tool Failed to Open, Tabs/Spaces Syntax)</title>
      <link>https://community.esri.com/t5/python-questions/older-toolbox-python-script-error-tool-failed-to/m-p/1389759#M70000</link>
      <description>&lt;P&gt;Hello - I have been using the lovely&amp;nbsp;&lt;A href="https://www.arcgis.com/home/item.html?id=4b2ea7c5f87d476a8849c804b81667aa" target="_self"&gt;Terrain Tools&lt;/A&gt;&amp;nbsp;for a spat of recent topographic maps with great success, however I ran into some issues regarding the "Cluster Hillshade" function and can't figure out why.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SimonBV_0-1709326857929.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96546i58BB8472CAC73D34/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SimonBV_0-1709326857929.png" alt="SimonBV_0-1709326857929.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;No specific error code, but opening up the details shows this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;'C:\Users\accov\Documents\ArcGIS\Projects\WatershedsCAD\Terrain Mapping.tbx\ClusterHillshade'&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;isLicensed Syntax Error: File "C:\Users\accov\Documents\ArcGIS\Projects\WatershedsCAD\Terrain Mapping.tbx#ClusterHillshade.InitializeParameters.py", line 21&lt;BR /&gt;if inDEM:&lt;BR /&gt;TabError: inconsistent use of tabs and spaces in indentation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One thing I noticed is there was no alias for the toolbox, and the name had a space. So I created an alias called "TerrainMapping" to see if that changed anything. No such luck. Another thing is the "isLicensed Syntax Error" but I am logged into my organization with a spatial analyst license (among many others).&lt;/P&gt;&lt;P&gt;So I went into VSCode and looked for anything strikingly obvious, and everything looks decent. There were no errors, and the indents were consistent from my general python knowledge:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SimonBV_1-1709326987465.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96547i0DFCAD5B20B9EFFD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SimonBV_1-1709326987465.png" alt="SimonBV_1-1709326987465.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And here is the code sample in its entirety (it's not overly long).&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# ---------------------------------------------------------------------------
# ClusterHillshade.py
#
# Based on a technique developed by:
# Fabio Veronesi and Lorenz Hurni (2014) and used with permission.
# Programmed by Linda Beale, Esri Inc
#
# Description:
# Further details are published in their paper:
# Veronesi, F. and Hurni, L. (2014) Changing the light azimuth in shaded relief
# representation by clustering aspect, The Cartographic Journal, 51, 4 pp291-300
# ---------------------------------------------------------------------------

import math
import arcpy
from arcpy import env
from arcpy.sa import *

def clusterHillshade(inDEM, outRaster, zFactor, majFW, meanFW, minL, maxL):
   """
    clusterHillshade: calculates a hillshade raster from a DEM

    Required arguments:
        Inputs:
            inDEM -- Input DEM.
            zFactor -- No. of ground x,y units in one surface z unit.
            majFW -- majority filter smoothing.
            meanFW -- mean filter smoothing.
            minL -- maximum light direction.
            maxL -- minimum light direction.
        Outputs:
            outRaster -- cluster shaded relief.
     """
    try:
        # Check out the Spatial Analyst license
        arcpy.CheckOutExtension("Spatial")

        # Inputs
        zenAngle = 45

        # Degrees to radians calculation
        deg2rad = math.pi / 180

        # Process: Aspect and slope
        AspectDeg = Aspect(inDEM)
        AspectClass = IsoClusterUnsupervisedClassification(AspectDeg, 4, 20, 10)
        # 9.01248403045503E-06
        SlopeDeg = Slope(inDEM, "DEGREE", zFactor)
        SlopeRad = SlopeDeg * deg2rad

        # Process: Zenith and smoothing
        Zenith = Con(SlopeDeg &amp;gt;= 0, (90 - int(zenAngle)) * deg2rad)
        FocalAspect = FocalStatistics(AspectClass, majFW, "MAJORITY")
        MeanCluster = FocalStatistics(FocalAspect, meanFW, "MEAN")

        # Process: Azimuth Calculator
        Azimuth = ((float(maxL) - float(minL)) / 2) * Sin(math.pi * MeanCluster + 1.570796) + (float(maxL) - ((float(maxL) - float(minL)) / 2))

        # Process: Calculate shaded relief
        Shade = ((Cos(Float(Zenith)) * Cos(Float(SlopeRad))) + (Sin(Float(Zenith)) * Sin(Float(SlopeRad)) * Cos((Float(Azimuth) * deg2rad) - Float(AspectDeg * deg2rad))))
        ShadeRelief = Con(Float(Shade) &amp;gt;= 0, 255 * Float(Shade), 0)

        # Process: Save outputs
        ShadeRelief.save(outRaster)
        arcpy.SetParameterAsText(1, outRaster)

    except arcpy.ExecuteError:
        arcpy.AddMessage(arcpy.GetMessages(2))

# End main function

if __name__ == '__main__':
    args = tuple(arcpy.GetParameterAsText(i) for i in range(arcpy.GetArgumentCount()))
    clusterHillshade(*args)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So at the bottom theres the *args that is looking for parameters from clusterHillshade, and I suspect something is going on with the inDEM parameter but that's as far as I can take it. The main hangup appears to be something where "inDEM" is not accessed whereas "inDEM" isn't greyed out for a different script.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SimonBV_2-1709331996897.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96560iFF8D69BE21BD810B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SimonBV_2-1709331996897.png" alt="SimonBV_2-1709331996897.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SimonBV_3-1709332032962.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96561iA9A06DB0F159F441/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SimonBV_3-1709332032962.png" alt="SimonBV_3-1709332032962.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if __name__ == '__main__':
    args = tuple(arcpy.GetParameterAsText(i) for i in range(arcpy.GetArgumentCount()))
    clusterHillshade(*args)&lt;/LI-CODE&gt;&lt;LI-CODE lang="c"&gt;def clusterHillshade(inDEM, outRaster, zFactor, majFW, meanFW, minL, maxL):
   """
    clusterHillshade: calculates a hillshade raster from a DEM

    Required arguments:
        Inputs:
            inDEM -- Input DEM.
            zFactor -- No. of ground x,y units in one surface z unit.
            majFW -- majority filter smoothing.
            meanFW -- mean filter smoothing.
            minL -- maximum light direction.
            maxL -- minimum light direction.
        Outputs:
            outRaster -- cluster shaded relief.
     """&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone has any insight that would be wonderful! Hopefully it isn't just outdated and incompatibly with ArcGIS Pro 3.2.2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 22:28:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/older-toolbox-python-script-error-tool-failed-to/m-p/1389759#M70000</guid>
      <dc:creator>SimonBV</dc:creator>
      <dc:date>2024-03-01T22:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Older Toolbox Python Script Error (Tool Failed to Open, Tabs/Spaces Syntax)</title>
      <link>https://community.esri.com/t5/python-questions/older-toolbox-python-script-error-tool-failed-to/m-p/1389777#M70001</link>
      <description>&lt;P&gt;The error is pretty straightforward, it looks like. (And I get bitten by it all the time in the Python Window).&lt;/P&gt;&lt;P&gt;Python relies on indentation to determine loops, etc.&lt;/P&gt;&lt;P&gt;You can use either tabs or spaces. A tab frequently looks like the same space as 4 or 8 spaces depending on the program you're using, but is considered to be an entirely different length.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1709333458123.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96566i717974487CF2A39E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_0-1709333458123.png" alt="AlfredBaldenweck_0-1709333458123.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;To fix it, open up the script in a text editor (I like Notepad++) and make sure that you can view whitespace chars. Find and replace all the tabs with spaces.&lt;/P&gt;&lt;P&gt;As an aside, many text editors will just turn tab key presses into spaces to avoid this problem. That, or if you have a tab, tabbing the line will turn it into spaces.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 22:54:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/older-toolbox-python-script-error-tool-failed-to/m-p/1389777#M70001</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-03-01T22:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Older Toolbox Python Script Error (Tool Failed to Open, Tabs/Spaces Syntax)</title>
      <link>https://community.esri.com/t5/python-questions/older-toolbox-python-script-error-tool-failed-to/m-p/1389780#M70002</link>
      <description>&lt;P&gt;I have an update, while poking around the validate tab on the script properties, I noticed some errors with regards to the spacing and indents:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SimonBV_0-1709333209063.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96565i7FBBA1589E2AC763/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SimonBV_0-1709333209063.png" alt="SimonBV_0-1709333209063.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
class ToolValidator(object):
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""

  def __init__(self):
    """Setup arcpy and the list of tool parameters."""
    self.params = arcpy.GetParameterInfo()

  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    return

  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    inDEM = self.params[0].value
    if self.params[2].value:
	if inDEM: 
            if arcpy.Describe(inDEM).spatialReference.type == "Geographic":
	        self.params[2].value = 9.01248403045503E-06
	    if arcpy.Describe(inDEM).spatialReference.type == "Projected":
		self.params[2].value = 1
    return

  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    inFC = self.params[0].value
    self.params[0].clearMessage()
    if self.params[0].value is None:
        self.params[0].clearMessage()
    else:
        if inFC:
            desc = arcpy.Describe(inFC) 
            sr = desc.spatialReference
            if sr.type == "Geographic":
                self.params[0].setErrorMessage("Data needs to be in a Projected Coordinate System")
            else:
                self.params[0].clearMessage()
    return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the error lies within the validation. It seems that there is an included validation step for "inDEM" to ensure it is in a projected coordinate system, and to convert it to a projection. All I ended up doing was replacing the the updateParameters so that it showed this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    return&lt;/LI-CODE&gt;&lt;P&gt;Instead of this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    inDEM = self.params[0].value
    if self.params[2].value:
        if inDEM: 
            if arcpy.Describe(inDEM).spatialReference.type == "Geographic":
	        self.params[2].value = 9.01248403045503E-06
	    if arcpy.Describe(inDEM).spatialReference.type == "Projected":
		self.params[2].value = 1
    return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Seems to work now, hope this helps people in a similar boat!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 23:02:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/older-toolbox-python-script-error-tool-failed-to/m-p/1389780#M70002</guid>
      <dc:creator>SimonBV</dc:creator>
      <dc:date>2024-03-01T23:02:41Z</dc:date>
    </item>
  </channel>
</rss>

