Adding feature class to Map in CURRENT project using ArcPy in ArcGIS Pro?
The addDataFromPath
method on the Map object worked for me, as shown in code below.
lyrTest = r"C:\data\test.gdb\Layer1"
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxMap = aprx.listMaps("MainMap")[0]
aprxMap.addDataFromPath(lyrTest)
and if you also need a Layer object from that data then change the last line to:
lyr = aprxMap.addDataFromPath(lyrTest)
See the ArcGIS Pro Help for Map class properties:
The addDataFromPath method provides a way to add a layer to a map in a similar way to how the Add Data From Path button works in the application; it places each layer based on layer weight rules and geometry type. For more precise layer placement control, refer to the moveLayer method.