import arcpy import arcpy.mapping import os GeoDatabaseName = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurementsDeep_GroundwaterElevation_Daily_Contours_20130625_20120731.gdb" ##Reference the map document in memory. mxd = arcpy.mapping.MapDocument(r"G:\Documents\GIS\HydstraData\Contours_20131223.mxd") df = arcpy.mapping.ListDataFrames(mxd)[0] print df FeatureClassToAdd = os.path.join(GeoDatabaseName,"AllPoints") print FeatureClassToAdd tempLayer = "layer" ## Make a layer from the feature class arcpy.MakeFeatureLayer_management(FeatureClassToAdd,tempLayer) addLayer = arcpy.Layer(tempLayer) arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE") arcpy.RefreshTOC()
Solved! Go to Solution.
import arcpy import arcpy.mapping import os arcpy.env.workspace = r"C:\Temp" ##Reference the Current map document. mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd)[0] print df NewLayer = arcpy.mapping.Layer("AllContours3D.shp") print NewLayer arcpy.mapping.AddLayer(df, NewLayer, "AUTO_ARRANGE") arcpy.RefreshTOC()arcpy.MakeFeatureLayer_management(FeatureClassToAdd,tempLayer) -- remove this line addLayer = arcpy.Layer(FeatureClassToAdd) -- modify "tempLayer" to FeatureClassToAdd arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE") arcpy.RefreshTOC()
GeoDatabaseName = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurementsDeep_GroundwaterElevation_Daily_Contours_20130625_20120731.gdb" -- change the \ slash to a / slash FeatureClassToAdd = os.path.join(GeoDatabaseName,"AllPoints") -- it looks like you are appending "AllPoints" to the geodatabase full path; is "AllPoints" your feature class name? I think you might need a slash between the ".gdb" and the "AllPoints" for this portion of the code. Try modifying "AllPoints" to "/AllPoints" or "\AllPoints".
#... other logic
tempLayer = "layer"
# Make a layer from the feature class
arcpy.MakeFeatureLayer_management("C:/data/mexico.gdb/cities",tempLayer)
addLayer = arcpy.Layer(tempLayer)
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
arcpy.RefreshTOC()The ultimate goal is to add in a few feature classes, symbolize them on a previously created and saved ".lyr" file and then do some other processing.
import arcpy
import arcpy.mapping
import os
arcpy.env.workspace = r"C:\Temp"
##Reference the map document in memory.
mxd = arcpy.mapping.MapDocument(r"C:\Temp\Test.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
print df
NewLayer = arcpy.mapping.Layer("AllContours3D.shp")
print NewLayer
arcpy.mapping.AddLayer(df, NewLayer, "AUTO_ARRANGE")
arcpy.RefreshTOC()import arcpy import arcpy.mapping import os arcpy.env.workspace = r"C:\Temp" ##Reference the Current map document. mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd)[0] print df NewLayer = arcpy.mapping.Layer("AllContours3D.shp") print NewLayer arcpy.mapping.AddLayer(df, NewLayer, "AUTO_ARRANGE") arcpy.RefreshTOC()