Packaging python toolboxes with a Pro Add-In

1929
5
04-24-2018 08:43 AM
by Anonymous User
Not applicable

Quite a vague question here but interested to hear some thoughts from ESRI and the community.. 

I have vague plans to move portions of our existing .NET SDK business logic into Python toolboxes for ease of distribution and sharing code between desktop and online. Also integration with the GP framework is a big plus.

Just wondering if there are any recommended practices I should follow here and if this approach is recommended at all.

Is there a standard way of distributing toolboxes within add-ins? Would they need to be packaged and distributed separately?

Or is there another recommended approach I should take entirely if I want to "share" query logic between my desktop and online apps? Are toolboxes the way to go?

Cheers

0 Kudos
5 Replies
ChrisFox
Esri Regular Contributor

Hi Luke,

This is certainly a supported approach if you want to include geoprocessing tools with your add-in. I have done this in a couple of my add-ins when I had existing geoprocessing tools that I leverage in other workflows but also want to invoke them from custom controls in the UI.

To package the toolbox with the add-in you will want to add the .pyt to your project, set the build action to 'None' and the Copy to Output Directory to 'Copy always'. When you build the project the toolbox will be packaged with the add-in along with your \assembly and any other dependencies.

In your add-in code you can then get the path to the toolbox on disk using the path of the executing assembly:

string installPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string toolboxPath = Path.Combine(installPath, "MyToolbox.pyt");‍‍

Now with the path to the toolbox you can either open the tool in the geoprocessing pane or execute the tool.

by Anonymous User
Not applicable

Thanks Chris this was just the reply I was hoping for - appreciated.  On the subject of .NET vs ArcPy in Pro, would there be performance differences between to the two for say querying a table with a standard search cursor and returning some data? 

0 Kudos
ChrisFox
Esri Regular Contributor

I haven't done any performance testing in this regard, but my guess is it would be faster via .NET and the Pro api. This theory is simply based on the fact that there is some overhead in executing a GP tool. The things that are nice about GP such as parameter validation, messages, and cleanup when you are working with the tool through the UI can add a little time to each operation that you won't incur in .NET.

0 Kudos
ArunEpuri
New Contributor II

Hi Chris,

We have developed some custom python tools and created Conda package to distribute.

I want to distribute these tools in Marketplace,

My concern using above procedure is . there are many tools and they are dependent on third parry libraries, so I can't include all in "Build Action"

My Ides is to invoke conda package on add-in button click. How can I invoke "Conda install mytoolspkg" package from ArcGIS Pro add-in button click. i.e only first time, if the package is not installed.

Please suggest me what are the best options and share any related codes samples.

Thanks,

Arun E

0 Kudos
DemevengDerrick
New Contributor

Hello @ArunEpuri, did you, by any chance, get a solution to this? I am trying to package the pro-add-in and my python toolbox using @ChrisFox 's method. The issue is that I also have an external python file containing some functions being used in my python toolbox. I tried copying both the python toolbox and the dependent python file into the Add-in directory and setting the build action to 'None' and the Copy to Output Directory to 'Copy always' for both files as recommended. But when pro open, the tool does not appear and I get the following error message

'C:\Users\Stefan\AppData\Local\ESRI\ArcGISPro\AssemblyCache\{1324153b-c1b5-48d0-a19f-5e778729ef24}\ArcGISDataConnector4ODK.pyt\Tool'

Traceback (most recent call last):
File "<string>", line 94, in getParameterInfo
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\ntpath.py", line 78, in join
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType

Being newbie to C#, I have no clue of where to go.

Please kindly support if you can

Thanks

Derrick

0 Kudos