2

I have a multiple Python scripts that act as geoprocessing tools. I have an ArcGIS Pro Toolbox (.atbx format) defining how to call them. The scripts are in a subdirectory of the location where the .atbx file is stored. I want to be able to move around the directory containing the .atbx file and .py files and have them go on working.

According to the ArcGIS Pro documentation Add a script tool:

If your toolbox is an ArcGIS toolbox (.atbx), this behavior is managed differently. If the script is in the same directory as the .atbx file or is in a child folder from where the .atbx is stored, a relative path is maintained. If the script and .atbx file are completely separate, an absolute path is maintained.

However, I have not seen this happen as described above. I have tried putting the .py files in various locations, including the same folder as the .atbx file. The path to the .py file is always absolute.

I see that the .atbx file format is a zipped archive where each tool gets a .tool directory containing a file called tool.script.execute.link. I have opened this after trying various .py locations and it always shows an absolute path. I tried manually editing it to use a relative path, but the next time I modified anything about the tool in the .atbx file it switched back to an absolute path.

My organisation is using ArcGIS Pro 2.9 for compatibility reasons, if this makes a difference.

So, can I get these .atbx files to store a relative path to my scripts?

Other options if ArcGIS Pro simply won't do this with .atbx files:

  • The scripts are long and under version control, so I don't consider storing them inside the .atbx satisfactory.
  • I could use the legacy toolbox (.tbx) format, but this may be removed from some future version of ArcGIS Pro.
  • In similar circumstances I have used the Python Toolbox (.pyt) format and it has been unwieldy but functional. It remains an option if there is no way to use the .atbx.

2 Answers 2

1

Sounds like a version issue if you are stuck at 2.9. I just set up a toolbox with a tool pointing to a py file in a sub-folder, moved atbx file and folder into a completely different drive space and it worked as intended. I'm using ArcPro 3.2.1.

1
  • Are your files stored in a mapped letter drive? Commented Sep 16, 2024 at 18:56
0

As always, it's when I give up that I get another idea and it finally works.

Previously, I would have embedded code on the Execute tab that I "exported" on that same tab to the toolbox's folder and which put the absolute path in the .link file. This time, I had embedded code on the Execute tab but I didn't export it to a file in the toolbox's folder, I simply browsed to the external script which was there from before.

By browsing for the script, ArcGIS Pro determines that it's in the same folder as the toolbox and puts a relative path in the .link file. If you export existing code to a Python file, ArcGIS Pro doesn't seem to do that same evaluation. It simply puts the absolute path you provide into it.

Sorry for the bother to everyone. I'd thought I'd include this additional information, though, in case someone else is struggling with same.

Cheers, Joanne

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.