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?
Best Answer
You can list the layers and the datasources of an MXD (ArcMap document) from ArcGIS Pro by simply importing the MXD into a project, and then following the same workflow you would do from ArcMap. (The syntax may vary a little).
current
, as the following code is run from the Python window)code: