AnsweredAssumed Answered

Custom Toolbox (.tbx, not .pyt)

Question asked by cpyywhite on Mar 29, 2018
Latest reply on Mar 30, 2018 by cpyywhite

I have to create a custom toolbox in ArcMap and have a .py tool in it. I have my .py script already written and functional (without input parameters). I knew I had to write a toolbox with this script, found the python toolbox and went to town. Got it all written (with input parameters) and it works fine. However, I just found out that I have to write a custom toolbox (.tbx), rather than a python toolbox (.pyt), but I cannot find any documentation on how to do so other than via the ArcToolbox in ArcMap (steps show gui, not python). I have to do this in python, but I cannot figure it out. I took the toolbox code from my .pyt code and made a new file on my computer with the .tbx extension, refreshed my toolbox in ArcMap and it saw it without any issue, but the new toolbox is not usable. I can't add my script to it (all those options are grayed out). I'm thinking that the code I pulled from my .pyt toolbox is not the same code I need in my .tbx toolbox. What needs to go in there? I went ahead and kept the def execute section in my new .tbx, but not really sure what needs to go in there as my actual code needs to be in my .py file unlike in my .pyt toolbox.

 

I also tried to just create a toolbox (.tbx) manually (gui) through ArcToolBox and then check its script (like I could for the python toolboxes) to see if I could figure out where I was going wrong in mine and fix it, but no luck, it's all in binary or other such gibberish (proprietary? Sorry ESRI if so, I wasn't trying to steal anything, just figure out what I was doing wrong...)

 

This is what I copied from my .pyt file and put in the .tbx:

############################################

class Toolbox(object):
   def __init__(self):
   self.label = "PPPtest"
   self.alias = "PPPtest"

   self.tools = [CFTool]

 

class CFTool(object):

   def __init__(self):
      self.label = "CFTool"
      self.description = "DOES STUFF - fix later"
      self.canRunInBackground = True

   

   def getParameterInfo(self):
      #Get Parameters
      #InputRaster - Top
      param0 = arcpy.Parameter(displayName = "Input Raster - TOP",
         name = "input_raster_top",
         datatype ="GPRasterLayer",
         parameterType = "Required",
         direction = "Input")

   

   #InputRasters - Bottoms
      param1 = arcpy.Parameter(displayName = "Input Rasters - BOTTOM",
         name = "input_raster_bottom",
         datatype ="GPRasterLayer",
         parameterType = "Required",
         direction = "Input",
         multiValue=True)


      params = [param0, param1]

      return params

 

def isLicensed(self):
"""Set whether tool is licensed to execute."""
   return True

 

#######No idea what to put in here ###########
## def updateParameters(self, parameters):
## """Modify the values and properties of parameters before internal
## validation is performed. This method is called whenever a parameter
## has been changed."""
## return
##

 

def updateMessages(self, parameters):
   topRaster = parameters[0]
   botRaster = parameters[1]
   return

 

####No idea what to put in here now......######

def execute(self,parameters, messages):

   return

############################################

I'm not asking anyone to write my code, really just what is supposed to be in the .tbx file and how to make it work as a normal toolbox so I can add my script to it and get everything run like it should. Thanks in advance!

Outcomes