Select to view content in your preferred language

Use custom .pyt toolbox in arcpy

1140
1
Jump to solution
08-02-2022 08:15 AM
WadeWall
Regular Contributor

Hi all,

I have  created a custom .pyt toolbox in ArcGIS Pro 2.9. I would like to use the created tools in a scripting environment, but unsure how to do this. When I run one of the tools, if I copy the python code it looks something like this:

arcpy.toolboxName,toolName(input,output).

However, if I try to run the script in arcpy, the toolbox is not loaded. How does one get the same functionality that is available within a GUI environment in ArcgisPro?

Even though I can copy and paste the python code, is that kind of pseudo-code that can't actually be used? When I try to cut and paste into a python window within an arcgisPro GUI, it doesn't work.

Just trying to understand python toolboxes and how to get them to play with scripts. It's a little redundant to write scripts and tools separately.

0 Kudos
1 Solution

Accepted Solutions
ShaunWalbridge
Esri Regular Contributor

ArcPy doesn't automatically know about your custom toolbox, but you can add it with ImportToolbox:

arcpy.ImportToolbox(r"C:\path\to\custom.pyt")
arcpy.custom.Tool("parameter 1", "parameter 2")

 
Where `custom` is the alias assigned to the toolbox. The documents within the Using tools in Python section of the help provide details on working with toolboxes from Python that may be of use.

Cheers,
Shaun

 

View solution in original post

1 Reply
ShaunWalbridge
Esri Regular Contributor

ArcPy doesn't automatically know about your custom toolbox, but you can add it with ImportToolbox:

arcpy.ImportToolbox(r"C:\path\to\custom.pyt")
arcpy.custom.Tool("parameter 1", "parameter 2")

 
Where `custom` is the alias assigned to the toolbox. The documents within the Using tools in Python section of the help provide details on working with toolboxes from Python that may be of use.

Cheers,
Shaun