I've built a tool that will be used to populate required metadata in the attributes of a specific schema. This tool is in a python toolbox and called by a python addin button.
The value entered for each input is saved to a text file to be used as the default for the next run of the tool.
All of this works, but as I understand it, the tool is only loaded once when ArcMap opens. So even when you change the input and run it, the old values are still used as the tool defaults until ArcMap is restarted.
I've tried loading the toolbox as a temp file posted here but that breaks the reference to the toolbox and text file location, which is based on the addin_addin.py location.
I've also tried to store/load new defaults with the ConfigParser from memory, but this isn't working for me either.
What I need is for the input values from each run of the tool to be set as the defaults for the next run without the user having to do anything.
I would prefer to find a way to refresh the toolbox or store defaults in memory until ArcMap is restarted over loading a temporary toolbox and finding a new way to reference the locations.
I'm also open to novel solutions.
Addin:
class populateAttributes(object):
"""Implementation for addin_addin.populateAttributes_button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
try:
relPath = os.path.dirname(__file__)
toolboxPath = os.path.join(relPath,"IncidentToolbox.pyt")
pythonaddins.GPToolDialog(toolboxPath, "populateReqAttributes")
except SystemExit:
pass
except:
traceback.print_exc()
pythonaddins.MessageBox("Somethings gone horribly wrong, sorry.", "Populate Attributes")
Get Parameters:
relPath = os.path.dirname(__file__)
iniPath = os.path.join(relPath,"incidentTools.ini")
def getParameterInfo(self):
"""Define parameter definitions"""
default_incidentName = None
default_irwinid = None
default_unitID = None
default_localIncidentID = None
default_gacc = None
default_imtName = None
default_contactName = None
default_contactEmail = None
default_contactPhone = None
config = ConfigParser.SafeConfigParser()
try:
default_incidentName = config.get("incidentAttributes","incidentName")
default_irwinid = config.get("incidentAttributes","irwinid")
default_unitID = config.get("incidentAttributes","unitID")
default_localIncidentID = config.get("incidentAttributes","localIncidentID")
default_gacc = config.get("incidentAttributes","gacc")
default_imtName = config.get("incidentAttributes","imtName")
default_contactName = config.get("incidentAttributes","contactName")
default_contactEmail = config.get("incidentAttributes","contactEmail")
default_contactPhone = config.get("incidentAttributes","contactPhone")
print "defaults set from in memory"
except:
if os.path.exists(iniPath):
config.read(iniPath)
if "incidentAttributes" in config.sections():
try:
default_incidentName = config.get("incidentAttributes","incidentName")
default_irwinid = config.get("incidentAttributes","irwinid")
default_unitID = config.get("incidentAttributes","unitID")
default_localIncidentID = config.get("incidentAttributes","localIncidentID")
default_gacc = config.get("incidentAttributes","gacc")
default_imtName = config.get("incidentAttributes","imtName")
default_contactName = config.get("incidentAttributes","contactName")
default_contactEmail = config.get("incidentAttributes","contactEmail")
default_contactPhone = config.get("incidentAttributes","contactPhone")
print "defaults set from file"
except:
print "default value missing"
# IncidentName
param0 = arcpy.Parameter(
displayName="Incident Name",
name="incidentName",
datatype="GPString",
parameterType="Required",
direction="Input")
if default_incidentName:
param0.value = default_incidentName
# IRWINID
param1 = arcpy.Parameter(
displayName="IRWINID",
name="irwinid",
datatype="GPString",
parameterType="Required",
direction="Input")
if default_irwinid:
param1.value = default_irwinid
# UnitID
param2 = arcpy.Parameter(
displayName="Unit ID",
name="unitID",
datatype="GPString",
parameterType="Required",
direction="Input")
if default_unitID:
param2.value = default_unitID
# LocalIncidentID
param3 = arcpy.Parameter(
displayName="Local Incident ID",
name="localIncidentID",
datatype="GPString",
parameterType="Required",
direction="Input")
if default_localIncidentID:
param3.value = default_localIncidentID
# GACC
param4 = arcpy.Parameter(
displayName="GACC",
name="gacc",
datatype="GPString",
parameterType="Required",
direction="Input")
if default_gacc:
param4.value = default_gacc
# IMTName
param5 = arcpy.Parameter(
displayName="IMT Name",
name="imtName",
datatype="GPString",
parameterType="Required",
direction="Input")
if default_imtName:
param5.value = default_imtName
# ContactName
param6 = arcpy.Parameter(
displayName="Contact Name",
name="contactName",
datatype="GPString",
parameterType="Required",
direction="Input")
if default_contactName:
param6.value = default_contactName
# ContactEmail
param7 = arcpy.Parameter(
displayName="Contact Email",
name="contactEmail",
datatype="GPString",
parameterType="Required",
direction="Input")
if default_contactEmail:
param7.value = default_contactEmail
# ContactPhone
param8 = arcpy.Parameter(
displayName="Contact Phone",
name="contactPhone",
datatype="GPString",
parameterType="Required",
direction="Input")
if default_contactPhone:
param8.value = default_contactPhone
params = [param0, param1, param2, param3, param4, param5, param6, param7, param8]
return params