ArcGISProject

Synthèse

Provides a reference to an ArcGIS project (.aprx) stored on disk or to the project currently loaded in ArcGIS Pro 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. These projects are opened in memory and changes made can only be seen if you export the results or save the project, open it, and verify the changes.

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 application. The CURRENT keyword can be used in the Python window, a Notebook, or geoprocessing script tools.

Remarque :

If you are running a script in the application and reference a project using a path instead of the CURRENT keyword, changes will not occur in the current application. If you want to immediately see the changes from your script, you must be in the application and using the CURRENT keyword.

Remarque :

Projects can be referenced multiple times but only the first reference can be saved directly using the save method on the ArcGISProject class. Other project references will be opened as read-only. The ArcGISProject class has an isReadOnly property that can be used to determine a project's read/write state.

For a more complete discussion and code samples refer to the ArcGISProject class help.

Syntaxe

ArcGISProject (aprx_path)
ParamètreExplicationType de données
aprx_path

The full system path and file name of an existing ArcGIS project (.aprx) or the CURRENT keyword.

String
Valeur renvoyée
Type de donnéesExplication
ArcGISProject

The ArcGISProject object provides access to project properties and methods. A reference to this object is essential for most arcpy.mp scripting operations.

Exemple de code

ArcGISProject example 1

The following line of code references a project on disk and can be run outside of an ArcGIS Pro session (for example, from a Python IDE).


import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
ArcGISProject example 2

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")