Problems with converting script to run in IDE from Py window

395
0
12-26-2019 06:27 PM
GabrielMarcus1
Occasional Contributor II

I created a python script to download satellite fire detection hotspots and do some various things to them. 

Today, I wanted to run it within Visual Studio to use the debugger. I referenced an arcPy book for steps required to change the script to remove errors when running from an IDE verus the ArcGIS Pro Python window .

The only requirement that I found mentioned appears to be changing the argument from "CURRENT" to the full path of the .aprx file. 

I changed the line:

aprx = arcpy.mp.ArcGISProject("CURRENT")‍
aprxMap = aprx.listMaps()[0]‍‍

into

aprx = arcpy.mp.ArcGISProject(r"C:\Users\gmarcus\Documents\ArcGIS\Projects\MyProject8_del6\MyProject8_del6.aprx")‍
aprxMap = aprx.listMaps()[0]‍‍‍‍

I experienced no errors when executing the script from within the Python window in ArcGIS Pro. When running from Visual Studio or PyCharm, the .aprx file acts as if the script is operating on a different file. (It isn't.)

To investigate this further:

I set several breakpoints to investigate the state of different variables. Using the Immediate Window , I was able to addDataFromPath, and get it to list the layer names that the script adds, but the layers don't appear in the ArcGIS Pro map window.  Applying symbology from a layer file fails as if the target layer wasn't added. 

I was able to add data manually from manual arcPy commands issue from the Immediate Window. I saved the .aprx file as a different file, opened it and verified that the data layers were added. Yet, I still couldn't apply symbologyFromLayer. 

I appreciate the recent mention from Leslie on 1/7 and I re-wrote this to make my issues more clear. Having this post be seen over 80 times with zero responses is frustrating. I'm not looking for help on the script itself (I'm not a sadist), but I am hoping someone can post pre-existing documentation, if it exists. 

Are there any documented steps that describe what must be changed in a script to transition from running in the ArcGIS Pro Python window to running from an IDE? I must be missing something else, but I couldn't find the answer. I'm including my script. 

0 Kudos
0 Replies