Pass multiple parameters into script

231
2
Jump to solution
12-08-2021 12:52 PM
2Quiker
Occasional Contributor II

I have the following basic code, I need to be able to run the script to select either 1 features or multiple features based on what is provided from arcpy.GetParameterAsText(0)

I have the arcpy.GetParameterAsText(0) set as 'Any Value' and for the data type parameter properties MultiValue set to 'Yes' but I keep getting the error. I am guessing that my whereClause is incorrect and if so how can I get to work?

PLATNAME field is a text field.

 

Error;

ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute)

 

Script code;

 

import arcpy

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

search_string = arcpy.GetParameterAsText(0)
search_string = search_string.split(";")
search_string = ["'{0}'".format(v) for v in search_string]
whereClause = "{0} IN ({1})".format("PLATNAME", ",".join(search_string))

arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION",whereClause )  
with arcpy.da.SearchCursor(lyr, ["SHAPE@","PLATNAME"]) as cursor:   
    for row in cursor:  
        df.extent = row[0].extent   
        df.scale = df.scale * 5   
        arcpy.RefreshActiveView() 

 

 

0 Kudos
1 Solution

Accepted Solutions
DonMorrison1
Occasional Contributor III

I would simply dump out the variables and see what they look like - something like this (this is in a python toolbox?)

arcpy.AddMessage("search_string: " + search_string)
arcpy.AddMessage("whereClause: " + whereClause)

 

 

View solution in original post

2 Replies
DonMorrison1
Occasional Contributor III

I would simply dump out the variables and see what they look like - something like this (this is in a python toolbox?)

arcpy.AddMessage("search_string: " + search_string)
arcpy.AddMessage("whereClause: " + whereClause)

 

 

2Quiker
Occasional Contributor II

Thank you for suggesting the print/add message, seems I always forget to do that. Turns out that line 9 puts extra set of apostrophes in the string , ''Rosedown sub''. I made changes to line 9.

 

Change line 9 from

earch_string = ["'{0}'".format(v) for v in search_string]

 

to

earch_string = ["{0}".format(v) for v in search_string]

 

0 Kudos