Does anyone know why line 1 - 3 does not add feature to the map to the map.
But line 6 - 8 adds the feature to the map.
Only difference is that I'm using the Path to the Aprx and not "Current". I was under the impression you can add add to the map with line 6 - 8 in a stand alone script.
aprx = arcpy.mp.ArcGISProject(r'xxxxxx\\MyProject4\\MyProject5.aprx')
mpDEM = aprx.listMaps("Map2")[0]
mpDEM.addDataFromPath(r"C:\xxxxxxx\Adam.gdb\ProjectBoundary")
aprx = arcpy.mp.ArcGISProject("CURRENT")
mpDEM = aprx.listMaps("Map2")[0]
mpDEM.addDataFromPath(r"C:\xxxxxxx\Adam.gdb\ProjectBoundary")
Solved! Go to Solution.
wild guess is that that method requires a "layer"
and not a featureclass in a gdb. Use Save to Layer file to make a lyrx out of the featureclass and try loading that file instead of the featureclass reference
the "Current" one works because the aprx is open
wild guess is that that method requires a "layer"
and not a featureclass in a gdb. Use Save to Layer file to make a lyrx out of the featureclass and try loading that file instead of the featureclass reference
the "Current" one works because the aprx is open
Thanks, Dan
I've tried for hours but I don't get it. I tried to Make
I want to add a Layer to an existing APRX/Map not to the Current APRX I have open.
I even tried to add a layer with ESRI's example below. I can't get the below example to work.
import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
m = aprx.listMaps("Yosemite National Park")[0]
for lyr in m.listLayers():
m.removeLayer(lyr)
lf = arcpy.mp.LayerFile(r"C:\Projects\YosemiteNP\Yosemite.lyrx")
m.addLayer(lf)
aprx.save()
del aprx
This below script should work no ?
aprx = arcpy.mp.ArcGISProject(r"......\MyProject8\MyProject8.aprx")
mp = aprx.listMaps("Map")[0]
a = arcpy.mp.LayerFile(r".....\TestSlope\prjbdyoutada.lyrx")
mp.addLayer(a)
the last one... did you add
aprx.save()
after line 4?
Just to make sure... you don't have the project open do you when you run the last example do you? It won't update.
The ones that use "Current" are designed to run in the python window inside of ArcGIS Pro. The code for adding an existing layer to an aprx should be run in a standalone python IDE like spyder and not in pro's python window
Yeah it was the save thing.
I figured out what I have to do with the code below.
arcpy.AddMessage("Creating Project Boundary Layer...")
arcpy.management.MakeFeatureLayer(Project_Boundary, "ProjectBoundary",Expression)
arcpy.SaveToLayerFile_management("ProjectBoundary", ProjDataSave+ r"\ProjectBoundary")
lf = arcpy.mp.LayerFile(ProjDataSave + r"\ProjectBoundary.lyrx")
mpDEM.addLayer(lf)
Adam, you might want to mark the correct answer to close out the thread.
guess I will mark it "assumed answered"
Sorry about that.