inputWorkspace = myWorkspace dataList = list() twnshpLyr = r"TFM_BKG.NEATLINE" selectSearch = arcpy.SearchCursor(twnshpLyr) for row in selectSearch: township = row.getValue("TILE_NAME") arcpy.env.workspace = inputWorkspace+os.sep+township+".mdb" fcList = arcpy.ListFeatureClasses() if fcList: dataList.append(str(township)) else: continue arcpy.MakeFeatureLayer_management(twnshpLyr, "townshipData", "TILE_NAME in (",str(dataList)+")")
where = "TILE_NAME in (" + ','.join(dataList) + ")"
What I am trying to do is create a definition query or where clause on a polygon grid feature layer. Each grid feature has a name and that name references a unique geodatabase in a directory. What I am doing is checking for a particular layer(s) in each geodatabase, saving that corresponding name in the feature layer if found, and outputting another feature layer with just the polygons that have a geodatabase with a corresponding feature class. Hopefully that wasn't too convoluted.
My problem is, no matter what I've tried, I can't seem to pass this list on to something arcpy will take. Here's my code so far, simplified to just test if the geodatabase has features at all. The bold lines are where I would think I need to change to get this to work, crashes on the makefeaturelayer.inputWorkspace = myWorkspace dataList = list() twnshpLyr = r"TFM_BKG.NEATLINE" selectSearch = arcpy.SearchCursor(twnshpLyr) for row in selectSearch: township = row.getValue("TILE_NAME") arcpy.env.workspace = inputWorkspace+os.sep+township+".mdb" fcList = arcpy.ListFeatureClasses() if fcList: dataList.append(str(township)) else: continue arcpy.MakeFeatureLayer_management(twnshpLyr, "townshipData", "TILE_NAME in (",str(dataList)+")")
Here is the error I get from the python window:
Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000732: Workspace or Feature Dataset: Dataset (...all the feature values in the list...) does not exist or is not supported Failed to execute (MakeFeatureLayer).
where = "TILE_NAME in ('" + '\',\''.join(dataList) + "')"
import arcpy, os sde = r"Database Connections\wisprod.sde" inputWorkspace = r"\\winms-gissvr\data\new_avi_pgdb\data" dataList = list() twnshpLyr = r"TFM_BKG.NEATLINE" selectSearch = arcpy.SearchCursor(twnshpLyr) for row in selectSearch: township = row.getValue("TILE_NAME") arcpy.env.workspace = inputWorkspace+os.sep+township+".mdb" fcList = arcpy.ListFeatureClasses() if fcList: dataList.append(str(township)) else: pass arcpy.env.workspace = inputWorkspace where = "TILE_NAME in ('" + '\',\''.join(dataList) + "')" arcpy.MakeFeatureLayer_management(sde+os.sep+twnshpLyr, "townshipData", where)