I'm quite late, but I haven't been able to get this method to work. The syntax on the .pyt is OK (i.e.: I'm able to view the toolbox within arcmap without it displaying the red X), but when I click the drop-down for the toolbox, it displays no tools.
My directory is set up as such:
Tools/
- bhaTools.pyt
- publishing.py
-findingpath.pyc
The findingpath.pyc:
def findpath():
local_path = os.path.abspath(os.path.dirname(__file__))
return local_path
The bhaTools.pyt has the following:
import contextlib
import os
import sys
import arcpy
import glob
class Toolbox(object):
def __init__(self):
self.label = u'bhaTools'
self.alias = 'bhaTools'
import findingpath
path = findingpath.findpath()
self.tools=[]
for py in glob.glob(os.path.join(path,'*.py')):
if not __file__ in py:
module=os.path.basename(py)[:-3]
self.tools.append(__import__(module).Tool)
The publishing.py:
class Tool(object):
def __init__(self):
self.label = u'Publish Parcel Fabric Parcels'
self.canRunInBackground = False
self.category = ["Parcel_Fabric_Migration_Tools"]
def getParameterInfo(self):
param_1 = arcpy.Parameter()
param_1.name = u'inputParcelFabricParcels'
param_1.displayName = u'Input Parcel Fabric Parcels'
param_1.parameterType = 'Required'
param_1.direction = 'Input'
param_1.datatype = u'DEFeatureClass'
return [param_1,param_2,param_3,param_4,param_5]
def isLicensed(self):
return True
def updateParameters(self, parameters):
validator = getattr(self, 'ToolValidator', None)
if validator:
return validator(parameters).updateParameters()
def updateMessages(self, parameters):
validator = getattr(self, 'ToolValidator', None)
if validator:
return validator(parameters).updateMessages()
def execute(self,*args,**kwargs):
main(*args,**kwargs)
def main(*args,**kwargs):
try:
except arcpy.ExecuteError:
arcpy.AddError(arcpy.GetMessages())
if __name__=='__main__':
main(sys.argv[1:])