AnsweredAssumed Answered

Not Able to Add FC from GDB Dataset to an MXD using ArcPy Stand Alone Script

Question asked by BEHSEINI on Oct 19, 2018
Latest reply on Oct 19, 2018 by bixb0012

I am trying to add a Feature Class from a Geodatabase Dataset to an MXD and save a copy like this but I am getting following errors on each methos

import arcpy
import os

arcpy.env.workspace = r"C:\arcgis\ArcTutor\AAA\MXDs"
MXD = arcpy.mapping.MapDocument(r"C:\arcgis\ArcTutor\AAA\MXDs\map.mxd")
DF = arcpy.mapping.ListDataFrames(MXD)[0]

lyr = arcpy.mapping.Layer("C:\arcgis\ArcTutor\AAA\GDBs\Delaware.gdb\Kent\Kent")
arcpy.mapping.AddLayer(DF, layer, "AUTO_ARRANGE")
MXD.saveACopy('newmxd.mxd')
del MXD
print(" Done")

enter image description here

and

import arcpy
import os
arcpy.env.workspace = r"C:\arcgis\ArcTutor\AAA\MXDs"
MXD = arcpy.mapping.MapDocument(r"C:\arcgis\ArcTutor\AAA\MXDs\map.mxd")
DF = arcpy.mapping.ListDataFrames(MXD)[0]

lyr = "C:\arcgis\ArcTutor\AAA\GDBs\Delaware.gdb\Kent\Kent"

arcpy.MakeFeatureLayer_management(lyr, 'shplyr')
arcpy.mapping.AddLayer(DF, lyr, "AUTO_ARRANGE")
print(" Step 4")
MXD.saveACopy('newmxd.mxd')
del MXD
print(" Done")

enter image description here

Outcomes