0

I'm creating a suite of add-in tools on a tool bar, and using this tool as a test. How I want it to work is thus:

  • I have a buffer which has already been cut up by a line feature class
  • I select the portions of the cut-up buffer that I want to keep (will usually be 1-2)
  • I then press my add-in button, which switches my selection to all other parts of the buffer (I will then add in 'delete all' functionality).

I have gone through the process and created the add-in project, toolbar, button etc., and loaded it into ArcMap through the customize menu. The button appears as intended, no 'Missing' issues. However, when I attempt to use it as described above, I get an egg-timer for a brief moment, and then nothing appears to happen. There is no change in the selection after I press the button compared to before.

My code:

import arcpy
import pythonaddins


class InverseSelection(object):
    """Implementation for RAFTv2_addin.invbtn (Button)"""

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

    def onClick(self):
        buffcut = "U:/ArcGIS/Default.gdb/buffcut"
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        arcpy.SelectLayerByAttribute_management(buffcut, "NEW_SELECTION", "INVERT")

    arcpy.RefreshActiveView()

I have also tried "SWITCH-SELECTION", but that didn't work either.

5
  • You need to read the help file and understand the syntax of the select by attribute tool. You are using the wrong parameter, look for the word switch.
    – Hornbydd
    Commented Jun 4, 2019 at 13:14
  • Are you talking about "SWITCH_SELECTION"? If so I tried that with no success, as stated. Will try again though. Commented Jun 4, 2019 at 13:40
  • 1
    But if switch selection and then invert...you are back to square 1.
    – Hornbydd
    Commented Jun 4, 2019 at 14:06
  • 1
    The invert_where_clause parameter doesn't exist for 10.4; it's only in Pro. But you don't need it, anyway. As Hornbydd implied, the selection line should read arcpy.SelectLayerByAttribute_management(buffcut, "SWITCH_SELECTION").
    – Tom
    Commented Jun 4, 2019 at 16:40
  • Still no luck. I select a part of my buffer, press my add-in button and get an egg-timer for a second, but then my selection remains the same and doesn't switch. Commented Jun 6, 2019 at 8:40

1 Answer 1

1

Ok, so I got it working

arcpy.SelectLayerByAttribute_management("buffcut", "SWITCH_SELECTION")

I needed to wrap buffcut with "". I thought setting it earlier on was the correct method but apparently not!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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