arcpy.mapping.ListLayers

385
4
12-01-2011 11:49 AM
MarkCollins1
New Contributor
Hey all,

I have 20 features classes, each with multiple fields, but ALL containing a field titled "AFE_Number."  I need to create a script to loop through a list of All feature classes and select any/all with the "AFE_Number" field containing a specific #.   I am able to generate a list of the necessary features, but am unable to selectbyattribute for more than one at a time.  Any suggestions?  Thanks a bunch
Tags (2)
0 Kudos
4 Replies
JeffBarrette
Esri Regular Contributor
SelectByAttribute works on only one FC at a time.  Can't you simply build a list of FCs and loop through them.

lyrs = [lyr1, lyr2, lyr3, etc]
query = ' "AFE_Number' = SomeValue '
for lyr in lyrs:
  arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", query)

Jeff
0 Kudos
MarkCollins1
New Contributor
I believe you are right about creating a list of fc's [a,b,c,...] and looping.  Seems to be my only option.  I appreciate your input.  Im still new to the Python game and needed some advice.  Thanks
0 Kudos
MarkCollins1
New Contributor
Is there a way to populate a list file via an arcpy.GetParameterAsText()  ?    Set a list [] variable equal to the value/s of a GetParametAsText.  Seems like you could add the script in ArcMap and set the parameters as a multivalue and select all feature classes, then loop through them.   Any ideas if something like this could work?
0 Kudos
ChrisFox3
Occasional Contributor III
Try this:

param1 = arcpy.getParameterAsText(0)
lyrList = param1.split(';')


The multivalue paramater will return you the values seperated by semi-colon if you use the split method on a string it will return you a list of items delimited by the character you pass into the method.
0 Kudos