Hello!
I am modifying a custom python toolbox in ArcGIS Pro 3.3, and I am running into issues getting the toolbox to recognize any changes. I make edits in VS Code, save the edits, right click on toolbox, and then click refresh. However, I do not see the changed reflected the next time I open the tool.
This is an error I got about RemoveSpatialIndex:
But I had commented it out before saving and then refreshing:
I've also tried clearing the cache from Pro Options and that doesn't work. I can get the tool to register edits after I quit Pro and reopen it. Has anyone else ran into this? or is there a step I've missed in the workflow?
Thanks!
Hey @MBocek
If you create a new toolbox with a different name and then link it to the Pro project is the outcome the same? Also, I would check to see if the toolbox is in Onedrive, that could potentially cause syncing issues to occur on the toolbox itself.
Cody
Hello Cody,
I have noticed this behavior with at least 2 python toolboxes. I don't recall having this issue in Pro 2.x, but I wasn't as advanced in coding either. The toolboxes have been saved to a shared drive. In theory, it would be nice to use the toolboxes on different machines via the shared drive, but I can try the C drive to see if that helps at all.
I ran into that scenario with various python ides (eg. spyder etc) when I hadn't set up the python editor in the project backstage
Edit script tool code—ArcGIS Pro | Documentation
When I wanted to edit a toolbox script, I would right-click on the tool and select Edit. If memory serves this would allow for a refresh whereas if I just launched the ide and edited the script a refresh didn't occur.
Experiment and see if that is the case for VS Code... it works for Spyder for sure
Hey Dan,
I added VS Code to the Script Editor in the Pro options. I was able to open the .pty file in VS Code, edit, and then refresh in Pro. However, any helper .py files that I am importing to the main python toolbox do not get refreshed. The 'edit' option always opens the .pyt file only. It's an improvement, but I'll keep trying to see if I can refresh all scripts.
Hi all
Why use python toolbox when regular toolbox where the python script saved separately is so much better.
You can use IDLE like pycharm to edit your code.
you just save the script and the toolbox see it immediately without need of any refresh.
You can run it within the IDLE for testing using the debug tools and you can use source control to keep history.
None of this is easy to do in python toolbox.
I think there is some confusion of what a python toolbox is on my end. I am referring to a toolbox (.pyt) that calls python scripts (.py) that are outside of the original .pyt file. How is that different than what you've described?
For running the tool, are you suggesting running the python toolbox from terminal in IDE? What benefits would IDLE have over VS Code or Pycharm? I would prefer to run the toolbox in Pro to validate the shapefile uploads and the attribute table, but that is something I could explore if it is more responsive than Pro.
I am using atbx file, that is the default toolbox.
This toolbox have no python code in it (The validation code does not published anyway).
I found it the easiest way.
I have a similar setup (a main .pyt toolbox that loads individual tools from separate .py files) and encountered this issue years ago. I don't remember exactly how I landed on it (probably from old threads) but this approach did fix the issue for me.
#import base modules and define path to individual tool scripts
import sys
import os
import arcpy
from importlib import reload
# Assuming you have a folder named toolboxscripts in the same directory as your .pyt file
sys.path.append(os.path.join(os.path.dirname(__file__), "toolboxscripts"))
#import the individual tool scripts, forcing a reload of any imported tools/modules
#otherwise you would have to restart Arc each time you edited an individual tool script
#this way you just have to right click -> Refresh the toolbox
import filename1
reload(filename1)
from filename1 import ToolName1
import filename2
reload(filename2)
from filename2import ToolName2
class Toolbox(object):
def __init__(self):
self.tools = [ToolName1,
ToolName2]