2

I am building an addin that will create a selection of multiple features that fit within the scope of multiple 'where' statements. All fields will be within the same layer, the layer will always be named "ParcelsWslivers" and will always have a field named "acres" and "VPA". Currently, when I run my script it returns the following error.

enter image description here

My code currently is

import arcpy
import os

class CreateLayerOfPotentialSlivers(object):
"""Implementation for Test2_addin.button (Button)"""
def __init__(self):
    self.enabled = True
    self.checked = False
def onClick(self):
    # Get the current map document and the first data frame.
    mxd = arcpy.mapping.MapDocument("CURRENT")
    lyr = arcpy.mapping.Layer("ParcelsWslivers")
    field = 'Sliver'

    # select parcels with acres less than 0.01 acres
    arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", '[acres] <= 0.01')
    # select parcels with greater than 100,000,000 VPA
    arcpy.SelectLayerByAttribute_management(lyr, "ADD_TO_SELECTION", '"VPA" >= 100000000')

I feel that my issue may be that I'm not being specific with the code about my workspace. However I want it to be conditional so that it does'nt matter which computer this is opened on it will still work within the current document.

2
  • 2
    Try using addfielddelimiters, for example: query="{0} <= 0.01".format(arcpy.AddFieldDelimiters(lyr, 'acres')"
    – Bera
    Commented Jan 28, 2020 at 15:39
  • 1
    Thank you, a combination of adding that and restating ArcMap got it to make the selections I want!
    – Pierce_h
    Commented Jan 28, 2020 at 16:52

1 Answer 1

2

Try using addfielddelimiters, for example:

query="{0} <= 0.01".format(arcpy.AddFieldDelimiters(lyr, 'acres')"

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.