Hi,
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)
pass
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
self.tools = [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",
name="in_gdb",
datatype="DEWorkspace",
parameterType="Required",
direction="Input",
multiValue="Yes")
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."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
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
arcpy.AddMessage(model_list_pos)
model_count = model_count + 1
arcpy.AddMessage(os.path.basename(model))
arcpy.AddMessage("\nAll models identified." + "\nTest Successful.")
pythonaddins.MessageBox("Bloody well work.","Test box 2",0)
return
Can anyone see a reason why my toolbar and/or toolbox would be causing ArcMap to shut down?
Thanks in advance for any help,
Ben.