arcpy.env.workspace = "C:\\Users\\me\\AppData\\Roaming\ESRI\\Desktop10.1\\ArcCatalog\\mysdeserver.sde" sdelist = arcpy.ListFeatureClasses() for sdeFC in sdelist: ## locate the desired fc and add it to the TOC if sdeFC == 'GIS.THE_FEATURE_CLASS_NAME': sdeLyr = arcpy.mapping.Layer(sdeFC) arcpy.mapping.AddLayer(df, sdeLyr, "BOTTOM") arcpy.mapping.AddLayer arcpy.RefreshTOC()
Solved! Go to Solution.
I think you want to use MakeFeatureLayer and add that as a layer object to your map.
http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000006p000000
if sdeFC == 'GIS.THE_FEATURE_CLASS_NAME': sdeLyr = arcpy.mapping.Layer(sdeFC) arcpy.MakeFeatureLayer_management(sdeFC, "GIS.THE_FEATURE_CLASS_NAME")
I'm not sure why you would have an issue with using the qualified name. I don't get any error when using the same layer name as the feature class name. How are you creating your mxd and df objects?
def onRectangle(self, rectangle_geometry): mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0]
That all seems fine, what is the error message you get?
arcpy.mapping.AddLayer(df, theFC, "BOTTOM")
arcpy.env.workspace = "C:\\Users\\me\\AppData\\Roaming\ESRI\\Desktop10.1\\ArcCatalog\\mysdeserver.sde" sdelist = arcpy.ListFeatureClasses() for sdeFC in sdelist: ## locate the desired fc and add it to the TOC if sdeFC == 'GIS.THE_FEATURE_CLASS_NAME': sdeLyr = arcpy.mapping.Layer(sdeFC) arcpy.mapping.AddLayer(df, sdeLyr, "BOTTOM") arcpy.mapping.AddLayer ## reset the fc's name after it is added to the TOC arcpy.mapping.ListLayers(mxd)[0].name = "GIS.THE_FEATURE_CLASS_NAME" arcpy.RefreshTOC()