
Originally Posted by
KG22
if i could find a way to just publish the pyt once then throw the extra scripts in there and have them recognized that would be the bomb
Something like the following might work:
Code:
# \--SomeDir
# | toolbox.pyt
# | some_script.py
# | another_script.py
# | ...
# | last_script.py
#
# Each *.py contains a class called Tool that's just a stub for your "main" def.
#----------------------------
#The .pyt file (all Tools are dynamically imported not hardcoded)
#----------------------------
import arcpy
import os,sys,glob
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the .pyt file)."""
self.label = "MultiTool_Toolbox"
self.alias = "Toolbox with Multiple Dynamically Imported Tools"
# Dynamic list of tool classes associated with this toolbox
path=os.path.dirname(__file__)
self.tools=[]
for py in glob.glob(os.path.join(path,'*.py')):
if not __file__ in py:
module=os.path.basename(py)[:-3]
#Note: "Tool" class must have same
#name as the script "Tool" classes
self.tools.append(__import__(module).Tool)
#----------------------------
#The .py script files
#----------------------------
#"Tool" class can be called anything but must be
# the same in each script and in the calling toolbox
class Tool(object):
# tool/parameter setup methods etc...
def execute(self,*args,**kwargs):
main(*args,**kwargs)
def main(*args,**kwargs):
#do stuff
return
if __name__=='__main__':
#Run script
main(sys.argv[1:])
Bookmarks