Skip to main content
added 361 characters in body
Source Link
GISGe
  • 9.7k
  • 19
  • 42

Your code tries to get the catalogPath property of the group layer containing your rasters, which doesn't exist. Instead, I would retrieve the dataSource property of the Layer, after testing that it is indeed applicable with the supports() method (group layers don't support this property).

Your code would look like this:

import arcpy
mxd=arcpy.mapping.MapDocument(r"S:\path_to_mxd.mxd")
dataframes=arcpy.mapping.ListDataFrames(mxd)
for dataframe in dataframes:
    for lyr in arcpy.mapping.ListLayers(mxd, "", dataframe):
        if lyr.supports(dataSource):
            print lyr.dataSource

See the help page for Layer properties and methods for more details.

If you want to follow @Hélène's suggestion and list all rasters in a gdb, use the arcpy.ListRasters() function. If all your rasters are in the same workspace, this would indeed be more straightforward than putting everything in an mxd to get your list.

Your code tries to get the catalogPath property of the group layer containing your rasters, which doesn't exist. Instead, I would retrieve the dataSource property of the Layer, after testing that it is indeed applicable with the supports() method (group layers don't support this property).

Your code would look like this:

import arcpy
mxd=arcpy.mapping.MapDocument(r"S:\path_to_mxd.mxd")
dataframes=arcpy.mapping.ListDataFrames(mxd)
for dataframe in dataframes:
    for lyr in arcpy.mapping.ListLayers(mxd, "", dataframe):
        if lyr.supports(dataSource):
            print lyr.dataSource

See the help page for Layer properties and methods for more details.

Your code tries to get the catalogPath property of the group layer containing your rasters, which doesn't exist. Instead, I would retrieve the dataSource property of the Layer, after testing that it is indeed applicable with the supports() method (group layers don't support this property).

Your code would look like this:

import arcpy
mxd=arcpy.mapping.MapDocument(r"S:\path_to_mxd.mxd")
dataframes=arcpy.mapping.ListDataFrames(mxd)
for dataframe in dataframes:
    for lyr in arcpy.mapping.ListLayers(mxd, "", dataframe):
        if lyr.supports(dataSource):
            print lyr.dataSource

See the help page for Layer properties and methods for more details.

If you want to follow @Hélène's suggestion and list all rasters in a gdb, use the arcpy.ListRasters() function. If all your rasters are in the same workspace, this would indeed be more straightforward than putting everything in an mxd to get your list.

Source Link
GISGe
  • 9.7k
  • 19
  • 42

Your code tries to get the catalogPath property of the group layer containing your rasters, which doesn't exist. Instead, I would retrieve the dataSource property of the Layer, after testing that it is indeed applicable with the supports() method (group layers don't support this property).

Your code would look like this:

import arcpy
mxd=arcpy.mapping.MapDocument(r"S:\path_to_mxd.mxd")
dataframes=arcpy.mapping.ListDataFrames(mxd)
for dataframe in dataframes:
    for lyr in arcpy.mapping.ListLayers(mxd, "", dataframe):
        if lyr.supports(dataSource):
            print lyr.dataSource

See the help page for Layer properties and methods for more details.