Hello and thanks for your reply.
I saw that and have been working with it for a couple of hours now.
Still cant seem to access the layers in the map specifically.
import arcpy
#Set env workspace
mxd = arcpy.mapping.MapDocument(r"C:\Users\billid\Desktop\WaterUtilityNetwork\WaterSystem.mxd")
#Get layers
for lyr in arcpy.mapping.ListLayers(mxd):
#Get fields
fields = arcpy.ListFields(lyr)
for field in fields:
print(field)
I just get this error.
Traceback (most recent call last):
File "D:\PythonWorkingFolder\GIS_Python\ListLayers.py", line 8, in <module>
fields = arcpy.ListFields(lyr)
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\__init__.py", line 1138, in ListFields
return gp.listFields(dataset, wild_card, field_type)
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\geoprocessing\_base.py", line 346, in listFields
self._gp.ListFields(*gp_fixargs(args, True)))
IOError: "Water System" does not exist
ListFields is supposed to take a string. ListLayers returns <class 'arcpy._mapping.Layer'> not a string
Note that "Water System" is a layer group, but even when I un-group all the layers it just tells me the first layer doesn't exist. I'm guessing it is because it's not a string.
I don't want to work on the data source as it is already set "editable = true" the map layer properties have it set to false and I would like to change the map and then I can overwrite the .lyr file. Yes I can do it manually but I have many maps and need to check all the fields.
Thanks again for your feed back.
EDIT: I suppose if i could turn the layer names into text I could make a list out of them....