Does arcpy.mp module work inside a Python toolbox when executing in Visual Studio Code?

543
1
Jump to solution
05-12-2023 03:41 AM
awesomeLLama27
New Contributor II

I am looking at this documentation for post processing validation resource within a python toolbox and it utilizes the arcpy.mp module for manipulating the contents of existing projects (.aprx) and layer files (.lyrx). The example in that link above makes it seem that arcpy.mp can be used inside a python toolbox. However, I'm reading that arcpy.mp requires that some methods and properties only work when ran inside the python pane or a script tool inside of ArcPro (ArcGISProject object resource ). Does the arcpy.mp only work when its a geoprocessing toolbox and not a python toolbox thats executed in an IDE?

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

The main issue you'll find is that arcpy.mp.ArcGISProject("CURRENT") won't work outside of ArcGIS Pro.  This includes scripts run from an IDE or external python interpreter or script tools/python toolbox tools started from ArcGIS Pro but running in the background.

You can use arcpy.mp outside of ArcGIS Pro, but to instantiate an ArcGISProject object, you need to use arcpy.mp.ArcGISProject(r"Drive:\Path\to\project.aprx) and understand that any changes you make won't be reflected in an open ArcGIS Pro project, but you need to save the ArcGISProject object and then open it in Pro to see changes.

View solution in original post

0 Kudos
1 Reply
Luke_Pinner
MVP Regular Contributor

The main issue you'll find is that arcpy.mp.ArcGISProject("CURRENT") won't work outside of ArcGIS Pro.  This includes scripts run from an IDE or external python interpreter or script tools/python toolbox tools started from ArcGIS Pro but running in the background.

You can use arcpy.mp outside of ArcGIS Pro, but to instantiate an ArcGISProject object, you need to use arcpy.mp.ArcGISProject(r"Drive:\Path\to\project.aprx) and understand that any changes you make won't be reflected in an open ArcGIS Pro project, but you need to save the ArcGISProject object and then open it in Pro to see changes.

0 Kudos