I'm converting Python standalone scripts from Desktop (10.6.1) to Pro (2.3.2). I can add a raster to an open Pro project file interactively by right clicking on the raster in the Catalog and choosing "Add to Current Map". I would like to do this in a script and have tried two ways (one commented out below):
inRas = '<projectDir>/Risks/riskv0'
outAPRX = '<projectDir>/Reports/riskv0/riskv0.aprx'
templateFile = '<projectDir>/MapTemplates/risksTemplate/risksTemplate.aprx'
aprx = arcpy.mp.ArcGISProject(templateFile)
map = aprx.listMaps()
#refLyr = map.listLayers()
#map.insertLayer(refLyr, inRas, "AFTER")
When I use addDataFromPath, I receive a RuntimeError for line 6 with no further information.
The listLayers/insertLayer approach results in a ValueErr at line 8 for the inRas file.
I would be grateful for any advice on adding a raster to a map in Pro.