Multiple Parameters for Python Addin?

1061
3
04-28-2014 01:50 PM
MikeMacRae
Occasional Contributor III
I'm running ArcGIS 10.1 and I'm creating a Python Addin. I'm am wondering if we can have multiple parameters for a python addin tool/button/combobox?


This is what I want to do. I want to create a button that takes 2 parameters the user will choose and zoom to an area of interest.

    The first parameter will have a dropdown where the user chooses one of 2 items. "SITE_A_NAME" or SITE_B_NAME" (These are SDE feature classes)

  • After the user chooses an item, they will manually enter a number (this is a site number. Both of the SDE feature classes have a field called SITE_NUMBER).



    • So, now they have chosen a record in one of the 2 SDE feature classes.

      When they have entered these 2 parameters, I would have them click on a button and the map will zomm to the area.

      I can get the coding down, but I'm not sure if I can set 2 parameters like this?
      Tags (2)
      0 Kudos
      3 Replies
      JasonScheirer
      Occasional Contributor III
      This sounds like the job for a geoprocessing tool.

      You could just associate the button's onClick with a GPToolDialog call.
      0 Kudos
      MikeMacRae
      Occasional Contributor III
      I'm giving that a try. I wanted to see how this works, so I just tried to use the example on the page you provided and tried to create a button that opens the 'Intersect' tool:

      import arcpy
      import pythonaddins
      
      class OpenGPTool(object):
          """Implementation for Test_Addin_Button_addin.button (Button)"""
          def __init__(self):
              self.enabled = True
              self.checked = False
          def onClick(self):
              pythonaddins.GPToolDialog(r'path to ArcGIS Install\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\Analysis Tools.tbx', 'Intersect')


      This isn't working. I'm getting the red circle "Missing" icon when I try to open my addin. I thought it might be the path to the tool because it sits in a toolset, so I tried:

      pythonaddins.GPToolDialog(r'path to ArcGIS Install\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\Analysis Tools.tbx\Overlay', 'Intersect'


      or

      pythonaddins.GPToolDialog(r'path to ArcGIS Install\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\Analysis Tools.tbx', 'Overlay\Intersect'


      And nothing seems to work.
      0 Kudos
      markdenil
      Occasional Contributor III
      You can set any number of variables / parameters.

      First, set a variable to hold each parameter at the head of the ~_addin.py
      just after your imports

      dataType = listOfTypes
      dataField = listOfFields
      dataDate = listOfDates
      dataList = listOfChoices
      
      theType = 'none'
      theField = 'none'
      theDate = 'none'
      theChoice = 'none'


      now declare each of the variables global inside each class where you want to set or use them.
      for example:
      class ComboBoxClass_DataType(object):
          """Select the data TYPE            """
          def __init__(self):
              global dataType
              self.items = dataType
              self.editable = True
              self.enabled = True
              self.dropdownWidth = '%s' % ('W' * 12)
              self.width = '%s' % ('W' * 12)
              
          def onSelChange(self, selection):
              global theType
              theType = selection


      Then, in the class behind the 'go' button, access that variable and
      any others the user sets in other wigits
      class ButtonClass_LoadData(object):
          """Implementation for DataBrowser_LoadData.button (Button)
              LOADS the data into the current mxd     """
          def __init__(self):
              self.enabled = True
              self.checked = False
          def onClick(self):
              global theType
              global theField
              global theDate
              global theChoice
              result = LayerFinder.loadLayerToMxd(theType, 
                                                                 theField, 
                                                                 theDate, 
                                                                 theChoice)
      


      Dynamically preloading the input lists is an enhancement......
      0 Kudos