3

I'm creating an arcpy script for a custom toolbox and I want to make it so that a user can essentially utilize the script in that toolbox without having to change the source path (which I made relative in the properties of the script).

How do I go about doing so in Python or any other method?

I'm guessing it might be under the tool validation code somehow, but I'm not sure.

1
  • I'm not quite clear what you're trying to do. Granted, I'm no expect on ArcGIS and arcpy, but I do know a fair bit about Python. Are you just trying to find the directory of the Python script? See here if so. If you're trying to add to PYTHONPATH so you can import other modules, use sys.path. If you're just trying to combine the working directory with a relative path, use os.path.join.
    – jpmc26
    Commented Feb 10, 2014 at 23:11

2 Answers 2

4

Sounds like you want to use relative paths to store the script that is associated with the Toolbox, if I understand the question properly. Right click on your Script in its Toolbox, go the General tab, check the "Store relative path names" option. From the help:

enter image description here

Using absolute paths, if you moved the toolbox from D:\Tools\Toolboxes\Toolbox1 to a different disk, such as E:\Final\Toolbox1 ArcGIS will find D:\Tools\Scripts\MyScript.py and everything will work fine. If, however, you use relative paths, ArcGIS will not find the script and the tool will not work. The tool dialog box will open, but when you execute, you'll get the error message "Script associated with this tool does not exist." You will have to open the tool's properties and enter the correct path to the script. On the other hand, if you use relative paths, you can simply copy the folder D:\Tools anywhere on anyone's computer and everything will work. This won't work if you use absolute paths, because the recipient could copy the folder to F:\NewTools and the path D:\Tools\Scripts\MyScript.py won't exist on his or her computer.

1
  • right that's kind of what I figured. Well I guess I meant an absolute path such that the toolbox would automatically find the current working directory of the scriptfile and then be able to apply that to the script properties. So I know in python how to get the current working directory, but I don't know if there's a way to programmatically add that to the source path in the properties of the script itself which I'm guessing there isn't. Thanks though.
    – Nightvein
    Commented May 9, 2012 at 19:34
2

I find that following the help about using Toolshare folders (and always moving them rather than the toolbox contained within) works well for me. It's from the same area of the documentation as Chad indicated but I'm not sure if you saw this part of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.