AnsweredAssumed Answered

Using Layers dataSource to print field names

Question asked by BrokenLegMike on Jun 8, 2015
Latest reply on Jun 8, 2015 by sunnywisher



I am trying to List the fields of each data source (which are all feature classes) of each layer in a map. The data source feature classes are SDE feature classes.


When I try this simple script:


mxd = arcpy.mapping.MapDocument(r"C:\Map_Documents\Test.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyrList = arcpy.mapping.ListLayers(mxd, "", df)
for lyr in lyrList:
     if lyr.supports("dataSource"):
         for field in arcpy.ListFields(lyr.dataSource):


which throws the following error:


Runtime error 
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "e:\sw_nt\arcgis\desktop10.2\arcpy\arcpy\", line 1119, in ListFields
    return gp.listFields(dataset, wild_card, field_type)
  File "e:\sw_nt\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\", line 344, in listFields
    self._gp.ListFields(*gp_fixargs(args, True)))
IOError: "C:\Documents and Settings\username\Application Data\ESRI\ArcCatalog\Connection to ThisSDE.sde\POPULATION_POINT" does not exist


indicating that the datasource does not exist. The problem is, that it does. My SDE feature classes are password protected, so i have a feeling that is why the script can't see each feature class and its associated fields. Can anyone suggest a work around to fix this?