Summary
Provides a reference to an ArcGIS project (.aprx) stored on disk or to the project currently loaded within the ArcGIS Pro application using the CURRENT keyword.
Discussion
There are two different ways that an ArcGISProject object can be created using the ArcGISProject function. The first, and most recommended, method is to provide a system path to the location of the project file (.aprx) on disk. This technique is most versatile because then a script can be run outside of an ArcGIS Pro application. Referencing a specific project on disk provides more control in terms of how the script will execute because a given script may not work with all projects.
The second technique is to use the CURRENT keyword as an input parameter to the ArcGISProject function. This technique only works from within an ArcGIS Pro application because the ArcGISProject object references the project that is currently loaded into the ArcGIS Pro application. The CURRENT keyword can be used in the Python window or with geoprocessing script tools.
For a more complete discussion and code samples refer to the ArcGISProject class help.
Syntax
ArcGISProject (aprx_path)
Parameter | Explanation | Data Type |
aprx_path | A string that includes the full system path and file name of an existing ArcGIS project (.aprx) or a string that contains the CURRENT keyword. | String |
Data Type | Explanation |
ArcGISProject | The ArcGISProject object provides access to project properties and methods. A reference to this object is essential for most map scripting operations. |
Code sample
The following line of code references a project on disk and can be run outside of an ArcGIS session (for example, from a Python IDE).
import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
The following line of code needs to be run from within the ArcGIS Pro application because it is using the keyword CURRENT. This example will work in the Python window or from a geoprocessing script tool.
aprx = arcpy.mp.ArcGISProject("CURRENT")