Hello,
When I run the addDataFromPath command, python prints "<arcpy._mp.Layer object at 0x000002658CF55948>" rather than adding anything to the map. I have 'arcpy.env.addOutputsToMap' set to 'True'
Here is a sample of my script:
layer_name = "layer"
Input_gdb = "gdb"
aprx = arcpy.mp.ArcGISProject(InputProject)
m = aprx.listMaps('Map')[0]
m.addDataFromPath(Input_gdb + "\\" + layer_name)
check the code examples
Map—ArcGIS Pro | Documentation
If the code is as you show it, then layer_name and input_gdb won't be known
I am having the same problem as @OwenKirkham when I try to do this in python outside of arcgis pro (being careful to run it with Pro's python environment). Here's the code:
import arcpy
project = arcpy.mp.ArcGISProject (r'fullPathToProject')
m = project.listMaps()[0]
m.addDataFromPath(project.defaultGeodatabase + r'\featureClassName')
The output generated from this last line is the same as Owen's (with a different memory address of course). I have also tried the .addDataFromPath line copying the entire path to the feature class instead of using project.defaultGeodatabase and the result is the same, but in both cases the 'featureClassName' data was not added to the map. I also checked arpcy.end.addOutputsToMap and found that it was already True.
Any thoughts on what could be wrong?
Someone in another thread solved it (for the standalone scenario anyway). Adding a line to the above code:
project.save()
did the trick.