This question already has an answer here:
This question has been asked multiple times with proper answers:
- How to add feature class to MXD with ArcPy (Python)?
- Adding shapefile or feature class as layer in ArcGIS Desktop using Python/ArcPy?
- Adding feature class into ArcGIS 10.3 mxd using python script
but I still cannot get it right.
I am using ArcGIS 10.2.2.
I want to add via a Python standalone script a Featureclass from a file-gdb to the TOC. If I try it in the ArcGIS Python window it works fine. However in a standalone script nothing happens. There is no error message or anything. I already thought it might be a bug, but it seems to work for everyone else. I also tried it with a .lyr and it didn´t work either. Someone got a hint for me?
Here is the code (I also tried the one from the ArcGIS help site, and from all the links above).
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\GIS\KUP\Check.mxd") df = arcpy.mapping.ListDataFrames(mxd, "*") addLayer = arcpy.mapping.Layer(r"C:\GIS\KUP\Ergebnisse.gdb\Potenziale_singlepart_final") arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
I also tried :
addLayer = arcpy.mapping.Layer(r"C:\GIS\KUP\Potenziale_singlepart_final.lyr")
What am I doing wrong? I am trying for a week now. I`m getting crazy with this one. Seems so easy.