How do I add a layer in the 'memory' workspace to the current active map in ArcGIS Pro using Python

255
4
08-03-2021 07:53 AM
Howeitzer
New Contributor III

According to the ArcGIS Pro support pages, "You can add memory datasets to a map in ArcGIS Pro.".

I have a layer in the 'memory' workspace that I would like to add to my current active map.  I've tried:

mem_lyr = r"memory\Test_Layer"
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprx_map = aprx.activeMap
aprx_map.addDataFromPath(mem_lyr)

but get the below error. Is there a correct way to add layers in memory to the current map?

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 1862, in addDataFromPath
    return convertArcObjectToPythonObject(self._arc_object.addDataFromPath(*gp_fixargs((data_path,), True)))
RuntimeError

 

Tags (3)
0 Kudos
4 Replies
JoshuaBixby
MVP Esteemed Contributor

Most ArcPy functions and GP tools understand the "memory" and "in_memory" aliases, but not all of them.  The addDataFromPath method of the ArcPy Map object does not understand or honor it.

I suggest changing your workflow to start with Make Feature Layer (Data Management)—ArcGIS Pro | Documentation and then use addLayer method of Map—ArcGIS Pro | Documentation.

Howeitzer
New Contributor III

Thanks Joshua. Unfortunately I get the same error. I'll contact Esri support.

 

0 Kudos
JoeBorgione
MVP Esteemed Contributor

@Howeitzer ; can you tell us what version of arcgis pro you are using? 

can't wait to retire....
0 Kudos
Howeitzer
New Contributor III

@JoeBorgione  sure, I'm using 2.7.2

0 Kudos