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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 28, 2020 at 15:16
2
  • 2
    Try using addfielddelimiters, for example: query="{0} <= 0.01".format(arcpy.AddFieldDelimiters(lyr, 'acres')" 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! 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')"

answered Jan 28, 2020 at 16:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.