Hi All, some years ago one of our developers wrote a python script to identify text fields in an mxd file and extract information such as file names and layer names. The script doesn't work with recent versions/releases of ArcGIS. What is the best/official way to extract information from an mxd file programmatically on recent versions? ArcGIS API for Python? Or other API? Thanks
The ArcGIS API for Python is focused on web GIS, so it isn't designed to extract information out of MXDs. In terms of Python, ArcPy would be the API/library you want to use to extract information out of MXDs. You could also write some ArcObjects code (.NET, Java) to extract information as well.
My guess is that the script you have uses ArcPy, if it is a Python script for accessing information in MXDs. What isn't working with it, specifically?
Thank you for your responses.
Joshua, the old scripts used to extract file paths, layer names, and CRS information. Only partial information is being returned now.
Michael, one of my colleagues tells me that you are probably right. They were old scripts in Pro reading ArcMap mxds. Sorry to be so vague but the scripts were written 7-8 years ago by a developer who left soon afterwards.
ArcGIS Pro didn't exist 7-8 years ago, so these can't be "old scripts in Pro rereading ArcMap mxds."
The ArcPy mapping module was completely rewritten from ArcMap (arcpy.mapping) to Pro (arcpy.mp). No arcpy.mapping code will run within the Pro application or using the Pro-bundled Python interpreter because the ArcMap version of the library isn't complied for Pro.
I am still not clear how you are trying to run these scripts. But back to your original question, ArcPy is the best Python API for extracting information out of MXD or APRX files.
Thanks, everybody, for your responses.
Joshua, the scripts are being invoked by a Java application. I have looked at a couple of the scripts. The scripts start with an 'import arcpy.mapping' statement. Can I replace this statement with 'import arcpy.mp' and run the scripts against Pro projects?
Hi Laurence Jackson
Please have a look at this Migrating from arcpy.mapping to ArcGIS Pro—ArcPy | ArcGIS Desktop for more information on the migration from arcpy.mapping to arcpy.mp. I don't think a simple find and replace will do...
arcpy.mp will definitely not read MXDs. You need to install ArcMap and have your Java script crank up python from the ArcMap Python 2.7 executable. (For example, C:\Python27\ArcGIS10.6\python.exe.) I'm pretty sure your code will all work if you use this Python stack, arcpy.mapping has not had big changes for a while. Most users still need both and ArcMap is not going away until 2025 so IMHO a full desktop install still really includes both.
Now, if you want your script to extract paths from ArcGIS Pro projects, that will require recoding using arcpy.mp and running the python script using the Pro python environment. (C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe). The structure is different so some software development will be needed.