Loop through multi-input list/selection?

المشرف العام

Administrator
طاقم الإدارة
I'm back with a script I've previously posted about that I'm constantly improving.

Below is a working script that is connected to a database with 52 feature classes on a server that, when having user specified inputs for a parish name and output folder, extracts features that were selected by location from that database.

What I'm trying to add is the optional parameter of being able to select which feature classes/layers to extract from, instead of extracting all 52. I figured I would create a multivalue list input and have it loop through that by adding an if statement for the optional list paramater but how can I get a list of the feature classes from the database so that the user can select from those and add them to a list as a single list parameter?

import arcpyfrom arcpy import envenv.workspace = r'\\server\database.sde'stateFeature = r'\\server\state.shp'parish = arcpy.GetParameterAsText(0)output = arcpy.GetParameterAsText(1)nameField = "PARISH"arcpy.CreateFileGDB_management(output, parish)arcpy.Delete_management('SelectionStateLayer')arcpy.Delete_management('lyr')arcpy.MakeFeatureLayer_management(stateFeature, 'SelectionStateLayer', '"' + str(nameField) + '" = ' + "'" + str(parish) + "'")for fc in arcpy.ListFeatureClasses(): if arcpy.Exists('lyr'): arcpy.Delete_management('lyr') arcpy.MakeFeatureLayer_management(fc, 'lyr') arcpy.SelectLayerByLocation_management('lyr', "WITHIN", 'SelectionStateLayer') outname = fc.replace(".","_") outpath = output + r'/' + parish + '.gdb' + r'\{0}'.format(outname) arcpy.CopyFeatures_management('lyr', outpath)arcpy.Delete_management('lyr')arcpy.env.workspace = output + r'/' + parish + '.gdb'for fc in arcpy.ListFeatureClasses(): if int(arcpy.GetCount_management(fc).getOutput(0)) == 0: arcpy.Delete_management(fc) arcpy.AddMessage('Deleted "{}" because it contains no features!'.format(fc))

أكثر...
 
أعلى