Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am writing Python Addins for ArcGIS. I call a Python Toolbox, the Addin tool only works once in ArcCatalog when picked. If you pick it again nothing happens.

import arcpy
import pythonaddins
import os

 class OreconDBtoArcGISTool(object):
     def __init__(self):
         self.enabled = True
         self.checked = False

     def onClick(self):

        toolboxName = "OreconDB_Toolbox"
        toolName = "OreconDBtoArcGISTool"
        relPath = os.path.dirname(__file__)
        pyt = relPath + os.sep + toolboxName + ".pyt"
        pythonaddins.GPToolDialog(pyt, toolName)

If I close and restart ArcCatalog the tool will work one more time again. Any Ideas on how to fix this would be appreciated.

share|improve this question
    
Is the Python Window giving you any hints? And if not, try adding a few print statement in the onClick to see if it's doing anything when you click it again. –  Jason Scheirer Mar 27 '13 at 2:14
    
I added a print under onClick and it only printed the first time picked and never again. –  MCSQRD Mar 27 '13 at 15:46
add comment

2 Answers

I changed the Addin so it was a Button instead of a Tool in the Python Addin Wizard and now it works as expected. ie I can run the pyt over and over again. I believe it is the behavior of "Tool" to be more interactive?

import arcpy
import pythonaddins
import os

 class BlastHoleAttributestoOreConDBButton(object):
     def __init__(self):
        self.enabled = True
        self.checked = False

     def onClick(self):
         toolboxName = "OreconDB_Toolbox"
         toolName = "OreconDBtoArcGISTool"
         relPath = os.path.dirname(__file__)
         pyt = relPath + os.sep + toolboxName + ".pyt"
         pythonaddins.GPToolDialog(pyt, toolName) 

Same code just being called as a button.

share|improve this answer
1  
Well that makes sense. A Tool's onClick method probably only runs when it becomes the active tool, and not when you click on it if it's already the active tool. And yes Tools are meant to let you interact with the map using the mouse, not perform an action each time you click it, like a Button. –  blah238 Mar 27 '13 at 16:12
add comment

Maybe try deleting out your im memory variables after execution?

del toolboxName, toolName, relPath, pyt

Are you closing the tool dialogue box after you run the addin and before you run it again? I guess it would be redundant for the program to run if the tool was already open?

share|improve this answer
    
thanks, tried that but still tool inactive after first pick. –  MCSQRD Mar 27 '13 at 15:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.