Modify all Script File Paths in Custom Toolbox?

4129
4
Jump to solution
05-18-2015 01:44 PM
MicahBabinski
Occasional Contributor III

Greetings,

I have a custom toolbox called "Micahs_tools.tbx" which I have built up over a couple of years:

The toolbox contains 94 tools. Initially I saved the source Python scripts in a network location, but for various reasons I have moved the directory which contains the scripts to a local drive. Now I'm wondering if there's a Python way to get at the paths to those scripts and change them to reflect the new location of the scripts.

Is this possible, and how would it be accomplished?

Thanks!

Micah

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

No it can't be done -- they are binary files that you cannot access in Python. If you  look there is text embedded in the tbx file, but that's just the metadata - tool documentation (XML code).

The only way to do this is to go through and update the script paths one by one for your 94 tools. If you go to relative paths [or embed the scripts in the tbx, or do Bill's suggestion to make a pyt], from here on out you will never have to do it again. Personally I like leaving the scripts outside the toolbox where I can easily edit them.

View solution in original post

0 Kudos
4 Replies
curtvprice
MVP Esteemed Contributor

Was the toolbox originally located on the same disk as the scripts? Relative paths make this process transparent, i.e. you can move the scripts and the toolbox together and the paths will resolve automatically.

You can also embed (import) scripts into the tbx file - if the paths are correct when you do it.

MicahBabinski
Occasional Contributor III

Alas, no, the scripts were saved on a network share and the .tbx is on my C drive. Does that mean it can't be done?

0 Kudos
curtvprice
MVP Esteemed Contributor

No it can't be done -- they are binary files that you cannot access in Python. If you  look there is text embedded in the tbx file, but that's just the metadata - tool documentation (XML code).

The only way to do this is to go through and update the script paths one by one for your 94 tools. If you go to relative paths [or embed the scripts in the tbx, or do Bill's suggestion to make a pyt], from here on out you will never have to do it again. Personally I like leaving the scripts outside the toolbox where I can easily edit them.

0 Kudos
BillDaigle
Occasional Contributor III

I don't think you can get to the raw code in a tbx file.  You might, however, be able to convert the tbx to a pyt using the following tool: http://www.arcgis.com/home/item.html?id=83585412edd04ae48bdffea3e1f7b2e7.  I haven't tried it, so I'm not sure what complexity it will introduce.  Once the tool is in the pyt, updating the scripts paths should be relatively simple.