I am looking for a way to access a .mxd file's layer names and data sources.
In ArcGIS Desktop, I could do:
def print_layer_info(mxd_path):
print(mxd_path + ":")
mxd = arcpy.mapping.MapDocument(mxd_path)
for df in arcpy.mapping.ListDataFrames(mxd, "*"):
lyr = arcpy.mapping.ListLayers(mxd, "", df)[0]
if lyr.supports("dataSource"):
print "\t" + lyr.name
print "\t\t" + lyr.dataSource
del mxd
According to http://pro.arcgis.com/en/pro-app/arcpy/mapping/migratingfrom10xarcpymapping.htm, I could do:
p = arcpy.mp.ArcGISProject("file.mxd")
But that doesn't work. When I do that I get a OSError.
Since the arcpy.mapping.MapDocument is gone in ArcPy for ArcGIS Pro, what is the equivalent way of reading layer name and datasource of an .mxd file?
No comments:
Post a Comment