AnsweredAssumed Answered

Python addin toolbar running a python toolbox closing down ArcMap when run

Question asked by simpson.ben1990 on Nov 24, 2015
Latest reply on Nov 24, 2015 by lpinner



I am trying to build a python toolbox which is called from a python addin toolbar button in ArcMap. At the moment I am just trying to test the python toolbox to get it to work from the toolbar button. The problem I am currently having is that everytime I press the toolbar button ArcMap closed down/crashes with nothing else, such as an error message appearing.Below I have the code that I am currently using.


Toolbar Script:


import arcpy
import pythonaddins
import os
import sys

class AppendModelsOracle(object):
    """Implementation for Append_Models_Oracle.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        # Toolbox name
        toolboxName = "Toolbox"
        # Name of tool to be executed
        toolName = "Tool"
        # Create string with path to toolbox
        relPath = os.path.dirname(__file__)
        pyt = relPath + os.sep + toolboxName + ".pyt"
        # Call geoprocessing tool
        pythonaddins.GPToolDialog(pyt, toolName)


Python Toolbox Script:


import arcpy
import pythonaddins
import os
import sys
class Toolbox(object):
 def __init__(self):
  """Define the toolbox (the name of the toolbox is the name of the
  .pyt file)."""
  self.label = "Toolbox"
  self.alias = ""
  # List of tool classes associated with this toolbox = [Tool]
class Tool(object):
 def __init__(self):
  """Define the tool (tool name is the name of the class)."""
  self.label = "Tool"
  self.description = ""
  self.canRunInBackground = False
 def getParameterInfo(self):
  """Define parameter definitions"""
  model_list = arcpy.Parameter(
   displayName="Input GDB",
  model_list.filter.type = "Workspace"
  model_list.filter.list = ["Local Database"]
  return [model_list]
 def isLicensed(self):
  """Set whether tool is licensed to execute."""
  return True
 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."""
 def updateMessages(self, parameters):
  """Modify the messages created by internal validation for each tool
  parameter.  This method is called after internal validation."""
 def execute(self, parameters, messages):
  """The source code of the tool."""
  model_list_len = len(model_list)
  model_list_pos = 0
  model_count = 1
  for model in model_list:
   msg1 = ("\nFirst model in list of selected models is: {0}".format(os.path.basename(model)))
   msg2 = ("\n{0} out of {1} models identified.".format(model_list_pos, model_list_len))
   arcpy.AddMessage(msg1 + msg2)
   model_list_pos = model_list_pos + 1
   model_count = model_count + 1
  arcpy.AddMessage("\nAll models identified." + "\nTest Successful.")
  pythonaddins.MessageBox("Bloody well work.","Test box 2",0) 


Can anyone see a reason why my toolbar and/or toolbox would be causing ArcMap to shut down?


Thanks in advance for any help,