AnsweredAssumed Answered

How to add raster dataset to active map contents using ArcPy in ArcGIS Pro

Question asked by mshukun1 on Feb 16, 2018
Latest reply on Feb 16, 2018 by Dan_Patterson

How to add raster dataset to active map contents using arcPy in ArcGIS Pro?  The code below gives me an error on line 10,  "ValueError: tempRas".  I am trying to migrate ArcMap 10.5 to ArcGIS Pro and I am having difficulty finding a solution for this problem.  I would very much appreciate your help.

 

import arcpy
import traceback

try:
    aprx = arcpy.mp.ArcGISProject('CURRENT')
    ras = '<path to>\\example.tif'
   
    rasTempLyr = arcpy.MakeRasterLayer_management(ras, 'tempRas')
    activeMap = aprx.activeMap
    activeMap.addLayer(rasTempLyr, 'TOP')

except:
    arcpy.AddError(traceback.format_exc())

Outcomes