<?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: Python Toolbox Script Problem -Cannot get output raster layer to display or save in project in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/python-toolbox-script-problem-cannot-get-output/m-p/1351023#M75312</link>
    <description>&lt;P&gt;Hi Janna,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you need to first identify the ArcGIS project and the active map, then add the layer in order to view the output.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("current")
mp = aprx.listMaps()[0]
mp.addLayer(output_raster_layer)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Nov 2023 19:20:05 GMT</pubDate>
    <dc:creator>Yuriko</dc:creator>
    <dc:date>2023-11-17T19:20:05Z</dc:date>
    <item>
      <title>Python Toolbox Script Problem -Cannot get output raster layer to display or save in project</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-toolbox-script-problem-cannot-get-output/m-p/1351009#M75310</link>
      <description>&lt;P&gt;I am new to Python and am in the process of creating a Python Toolbox in ArcGIS Pro (version 3.1.3) to conduct a trend analysis on a multidimensional Raster layer. When I run the tool, it states that it ran successfully, but it is not adding the trend analysis raster layer to the project. My code is below (things that I have tried are commented out). I am obviously missing something simple. Any help to correct this would be greatly appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;# -*- coding: utf-8 -*-&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os&lt;/P&gt;&lt;P&gt;# Define a class named Toolbox&lt;BR /&gt;class Toolbox(object):&lt;BR /&gt;def __init__(self):&lt;BR /&gt;"""Define the toolbox (the name of the toolbox is the name of the .pyt file)."""&lt;BR /&gt;self.label = "Coral Reef Assessment Tools"&lt;BR /&gt;self.alias = "toolbox"&lt;/P&gt;&lt;P&gt;# List of tool classes associated with this toolbox&lt;BR /&gt;self.tools = [SeaSurfaceTemp_Trend_Analysis]&lt;/P&gt;&lt;P&gt;# Define the tool class named SeaSurfaceTemp_Trend_Analysis&lt;BR /&gt;class SeaSurfaceTemp_Trend_Analysis(object):&lt;BR /&gt;def __init__(self):&lt;BR /&gt;"""Define the tool (tool name is the name of the class)."""&lt;BR /&gt;self.label = "Bighouse_Temperature_Trend_Analysis"&lt;BR /&gt;self.description = "Performs a multidimensional trend analysis on a raster layer"&lt;BR /&gt;self.canRunInBackground = False&lt;BR /&gt;&lt;BR /&gt;# Assign parameters&lt;BR /&gt;def getParameterInfo(self):&lt;BR /&gt;"""Define parameter definitions"""&lt;BR /&gt;params = [&lt;BR /&gt;arcpy.Parameter(displayName="Input Multidimensional Raster Layer",&lt;BR /&gt;name="input_Multidimensional_Raster_layer",&lt;BR /&gt;datatype="GPRasterLayer",&lt;BR /&gt;parameterType="Required",&lt;BR /&gt;direction="Input"),&lt;/P&gt;&lt;P&gt;arcpy.Parameter(displayName="Output Raster",&lt;BR /&gt;name="output_raster_name",&lt;BR /&gt;datatype="DERasterDataset",&lt;BR /&gt;parameterType="Required",&lt;BR /&gt;direction="Output"),&lt;BR /&gt;]&lt;BR /&gt;return params&lt;BR /&gt;&lt;BR /&gt;# Other methods ...&lt;/P&gt;&lt;P&gt;def execute(self, parameters, messages):&lt;BR /&gt;"""The source code of the tool."""&lt;BR /&gt;try:&lt;BR /&gt;multidimensional_raster = parameters[0].valueAsText&lt;BR /&gt;output_raster_name = parameters[1].valueAsText&lt;/P&gt;&lt;P&gt;# Hardcoded extent and spatial reference&lt;BR /&gt;xmin, ymin, xmax, ymax = -177.540046, 21.549769, -159.090139, 28.420046&lt;BR /&gt;spatial_reference = arcpy.SpatialReference(4326) # WGS 1984&lt;/P&gt;&lt;P&gt;# Set the environment with extent and spatial reference&lt;BR /&gt;with arcpy.EnvManager(extent=arcpy.Extent(xmin, ymin, xmax, ymax),&lt;BR /&gt;outputCoordinateSystem=spatial_reference):&lt;/P&gt;&lt;P&gt;# Perform the trend analysis&lt;BR /&gt;out_multidimensional_raster = arcpy.ia.GenerateTrendRaster(&lt;BR /&gt;in_multidimensional_raster=multidimensional_raster,&lt;BR /&gt;dimension="StdTime",&lt;BR /&gt;variables="cfsrsst",&lt;BR /&gt;line_type="HARMONIC",&lt;BR /&gt;frequency=1,&lt;BR /&gt;ignore_nodata="DATA",&lt;BR /&gt;cycle_length=1,&lt;BR /&gt;cycle_unit="YEARS",&lt;BR /&gt;rmse="RMSE",&lt;BR /&gt;r2="NO_R2",&lt;BR /&gt;slope_p_value="NO_SLOPEPVALUE",&lt;BR /&gt;seasonal_period=""&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;# Save the output raster to a file test lines added&lt;BR /&gt;#output_path = os.path.join(arcpy.env.scratchFolder, output_raster_name + ".tif")&lt;BR /&gt;#out_multidimensional_raster.save(output_path)&lt;/P&gt;&lt;P&gt;# Make raster layer from saved output raster and add to map&lt;BR /&gt;arcpy.management.MakeRasterLayer(multidimensional_raster, output_raster_name)&lt;/P&gt;&lt;P&gt;return&lt;BR /&gt;# Make a raster layer from the saved output raster and add it to the map&lt;BR /&gt;#result = arcpy.management.MakeRasterLayer(output_path, output_raster_name)&lt;BR /&gt;#output_raster_layer = result.getOutput(0)&lt;/P&gt;&lt;P&gt;# Set the derived output parameter&lt;BR /&gt;arcpy.SetParameter(1, output_raster_layer)&lt;BR /&gt;except Exception as e:&lt;BR /&gt;arcpy.AddError(f"An error occurred: {str(e)}")&lt;BR /&gt;raise&lt;/P&gt;&lt;P&gt;return&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 19:02:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-toolbox-script-problem-cannot-get-output/m-p/1351009#M75310</guid>
      <dc:creator>JannaBighouse</dc:creator>
      <dc:date>2023-11-17T19:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox Script Problem -Cannot get output raster layer to display or save in project</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-toolbox-script-problem-cannot-get-output/m-p/1351023#M75312</link>
      <description>&lt;P&gt;Hi Janna,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you need to first identify the ArcGIS project and the active map, then add the layer in order to view the output.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("current")
mp = aprx.listMaps()[0]
mp.addLayer(output_raster_layer)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 19:20:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-toolbox-script-problem-cannot-get-output/m-p/1351023#M75312</guid>
      <dc:creator>Yuriko</dc:creator>
      <dc:date>2023-11-17T19:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox Script Problem -Cannot get output raster layer to display or save in project</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-toolbox-script-problem-cannot-get-output/m-p/1351044#M75313</link>
      <description>&lt;P&gt;Thanks for the quick response. I added the lines you mentioned, but it still isn't adding the layer to view. Below is what my script looks like now. Again, it stated that the tool ran successfully, but no layer can be found. Did I add the lines in the wrong place? Any other suggestions would be greatly appreciated!&lt;/P&gt;&lt;P&gt;Thanks again!&amp;nbsp;&lt;/P&gt;&lt;P&gt;# -*- coding: utf-8 -*-&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os&lt;/P&gt;&lt;P&gt;# Define a class named Toolbox&lt;BR /&gt;class Toolbox(object):&lt;BR /&gt;def __init__(self):&lt;BR /&gt;"""Define the toolbox (the name of the toolbox is the name of the .pyt file)."""&lt;BR /&gt;self.label = "Coral Reef Assessment Tools"&lt;BR /&gt;self.alias = "toolbox"&lt;/P&gt;&lt;P&gt;# List of tool classes associated with this toolbox&lt;BR /&gt;self.tools = [SeaSurfaceTemp_Trend_Analysis]&lt;/P&gt;&lt;P&gt;# Define the tool class named SeaSurfaceTemp_Trend_Analysis&lt;BR /&gt;class SeaSurfaceTemp_Trend_Analysis(object):&lt;BR /&gt;def __init__(self):&lt;BR /&gt;"""Define the tool (tool name is the name of the class)."""&lt;BR /&gt;self.label = "Bighouse_Temperature_Trend_Analysis"&lt;BR /&gt;self.description = "Performs a multidimensional trend analysis on a raster layer"&lt;BR /&gt;self.canRunInBackground = False&lt;BR /&gt;&lt;BR /&gt;# Assign parameters&lt;BR /&gt;def getParameterInfo(self):&lt;BR /&gt;"""Define parameter definitions"""&lt;BR /&gt;params = [&lt;BR /&gt;arcpy.Parameter(displayName="Input Multidimensional Raster Layer",&lt;BR /&gt;name="input_Multidimensional_Raster_layer",&lt;BR /&gt;datatype="GPRasterLayer",&lt;BR /&gt;parameterType="Required",&lt;BR /&gt;direction="Input"),&lt;/P&gt;&lt;P&gt;arcpy.Parameter(displayName="Output Raster",&lt;BR /&gt;name="output_raster_name",&lt;BR /&gt;datatype="DERasterDataset",&lt;BR /&gt;parameterType="Required",&lt;BR /&gt;direction="Output"),&lt;BR /&gt;]&lt;BR /&gt;return params&lt;BR /&gt;&lt;BR /&gt;# Other methods ...&lt;/P&gt;&lt;P&gt;def execute(self, parameters, messages):&lt;BR /&gt;"""The source code of the tool."""&lt;BR /&gt;try:&lt;BR /&gt;multidimensional_raster = parameters[0].valueAsText&lt;BR /&gt;output_raster_name = parameters[1].valueAsText&lt;/P&gt;&lt;P&gt;# Hardcoded extent and spatial reference&lt;BR /&gt;xmin, ymin, xmax, ymax = -177.540046, 21.549769, -159.090139, 28.420046&lt;BR /&gt;spatial_reference = arcpy.SpatialReference(4326) # WGS 1984&lt;/P&gt;&lt;P&gt;# Set the environment with extent and spatial reference&lt;BR /&gt;with arcpy.EnvManager(extent=arcpy.Extent(xmin, ymin, xmax, ymax),&lt;BR /&gt;outputCoordinateSystem=spatial_reference):&lt;/P&gt;&lt;P&gt;# Perform the trend analysis&lt;BR /&gt;out_multidimensional_raster = arcpy.ia.GenerateTrendRaster(&lt;BR /&gt;in_multidimensional_raster=multidimensional_raster,&lt;BR /&gt;dimension="StdTime",&lt;BR /&gt;variables="cfsrsst",&lt;BR /&gt;line_type="HARMONIC",&lt;BR /&gt;frequency=1,&lt;BR /&gt;ignore_nodata="DATA",&lt;BR /&gt;cycle_length=1,&lt;BR /&gt;cycle_unit="YEARS",&lt;BR /&gt;rmse="RMSE",&lt;BR /&gt;r2="NO_R2",&lt;BR /&gt;slope_p_value="NO_SLOPEPVALUE",&lt;BR /&gt;seasonal_period=""&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;# Save the output raster to a file test lines added&lt;BR /&gt;#output_path = os.path.join(arcpy.env.scratchFolder, output_raster_name + ".tif")&lt;BR /&gt;#out_multidimensional_raster.save(output_path)&lt;/P&gt;&lt;P&gt;# Make raster layer from saved output raster and add to map&lt;BR /&gt;arcpy.management.MakeRasterLayer(multidimensional_raster, output_raster_name)&lt;/P&gt;&lt;P&gt;return&lt;BR /&gt;# Set the derived output parameter first three lines are test code&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject("current")&lt;BR /&gt;mp = aprx.listMaps()[0]&lt;BR /&gt;mp.addLayer(output_raster_layer)&lt;/P&gt;&lt;P&gt;arcpy.SetParameter(0, output_raster_layer)&lt;/P&gt;&lt;P&gt;# Make a raster layer from the saved output raster and add it to the map&lt;BR /&gt;#result = arcpy.management.MakeRasterLayer(output_path, output_raster_name)&lt;BR /&gt;#output_raster_layer = result.getOutput(0)&lt;/P&gt;&lt;P&gt;except Exception as e:&lt;BR /&gt;arcpy.AddError(f"An error occurred: {str(e)}")&lt;BR /&gt;raise&lt;/P&gt;&lt;P&gt;return&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 19:48:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-toolbox-script-problem-cannot-get-output/m-p/1351044#M75313</guid>
      <dc:creator>JannaBighouse</dc:creator>
      <dc:date>2023-11-17T19:48:41Z</dc:date>
    </item>
  </channel>
</rss>

