Select to view content in your preferred language

Call a script from the default toolbox

272
2
Jump to solution
02-27-2025 03:38 PM
DanCrawford
Occasional Contributor

Is there any way to call a script using the project's default toolbox parameter?
What works:
arcpy.ImportToolbox(path + r"\ArcGIS_Pro.atbx")
arcpy.ArcGISProatbx.SE4Polygons()

What I would like to do:
arcpy.ImportToolbox(project.defaultToolbox)                     #this part is ok
mytools = arcpy.ImportToolbox(project.defaultToolbox)  #this is ok too
arcpy.project.defaultToolbox.SE4Polygons()                       # doesn't work
arcpy.mytools.SE4Polygons()                                                  # doesn't work

Thanks in advance!

 

 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

arcpy.ImportToolbox(project.defaultToolboxk, "mytools")

arcpy.SE4Polygons_mytools(....

based on suggestions in...

Add toolboxes in Python—ArcGIS Pro | Documentation


... sort of retired...

View solution in original post

2 Replies
DanPatterson
MVP Esteemed Contributor

arcpy.ImportToolbox(project.defaultToolboxk, "mytools")

arcpy.SE4Polygons_mytools(....

based on suggestions in...

Add toolboxes in Python—ArcGIS Pro | Documentation


... sort of retired...
DavidPike
MVP Notable Contributor

I think you need to specify an alias for the toolbox on the fly, or set the alias beforehand in the tbx.

https://learn.finaldraftmapping.com/how-to-use-custom-tools-in-a-python-script-with-arcpy/

 

import arcpy

aprx = arcpy.mp.ArcGISProject("CURRENT")

#import toolbox with alias 'default_toolbox'
arcpy.ImportToolbox(aprx.defaultToolbox, 'default_toolbox')                     

#run SE4()
arcpy.default_toolbox.SE4Polygons()