AnsweredAssumed Answered

Create a search with user GetParameterAsText using arcpy.da.SearchCursor

Question asked by CCweedcontrol on May 20, 2015
Latest reply on May 21, 2015 by tsellste

I am trying to create a script tool to do a search but i am having a little trouble putting it together and i am not sure if i am going about it the right way. I would like to have a script tool that can search for a subdivision name inside arcmap in the toolbox. I have attached my python code i have and working with, one other thing i would like this script to do is use a wildcard. For example say a subdivision that i am searching for attribute is "County Side Estates" but I would like to just enter "County" and select all subs with "County" but i am not sure how to accomplish this. Any help would be gratefully appreciated.

Thanks.

 

The error i am getting with my current code.

Traceback (most recent call last):

  File "C:\GIS\Python Scripts\ZoomToParcelScript6Eb.py", line 9, in <module>

    for row in cursor:

RuntimeError: Underlying DBMS error [[Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near 'ACRES'.] [vector.DBO.Subdivision_boundaries]

 

Failed to execute (ZoomToSubScript).

 

import arcpy

mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
lyr = arcpy.mapping.ListLayers(mxd, "Subdivision Boundaries")[0] 

whereClause = arcpy.GetParameterAsText(0)
with arcpy.da.SearchCursor(lyr, ("PLAT_NAME"), whereClause) as cursor:
    for row in cursor:
        query_str = whereClause #= '{0}'.format(row[1])
        arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", query_str) 
        df.extent = row[0].extent
        df.scale = df.scale * 5

        arcpy.RefreshActiveView()
        #arcpy.mapping.ExportToPDF(mxd, "C:/test/" + fc + "_" + str(row[1]) + "_" +  str(row[2]) + ".pdf") 

 

 

 

 

Here are my script parameters.

Attachments

Outcomes