I guess this depends on how often you want to run the script, whether or not you want to hard code in the clip grids and the output shapefiles.
Very simply, I'd have a dictionary, of clip_grid : output_shapefile, loop through that and spit out the output.
import arcgisscripting
#Create the geoprocessor
gp = arcgisscripting.create(9.3)
input_shape = "yourshapefile.shp" #<-- this single file will be clipped repeatedly
#grids and corresponding outputs go here
clip_dictionary = {"clipgrid1.shp":"output1.shp", "clipgrid2.shp":"output2.shp"}
for iter in clip_dictionary:
#Clip_analysis (in_features, clip_features, out_feature_class, cluster_tolerance)
gp.Clip_analysis(input_shape, iter, clip_dictionary[iter])
Hope that helps!
sys.argv is a possiblity if you wish to read in the arguments from the command line (or if you wish to add the script to the toolbox). You could also use getopt or optparse as well.
Assume that we have a script called clip_export.py, which we wish to pass a list of inputs. We could run the script like:
clip_export.py input_shape clipshape_1;clipshape_2;clipshape_3 output_folder
Note that this is similar to the input that is sent to a python script by Toolbox.
At any rate, you can read this in your script like so:
import sys
input_shape = sys.argv[1] #<-- Note that the 0th argument in sys.argv is the script name
clip_shape_list = sys.argv[2].split(';') #<-- splits the second argument on the semicolon into a python list
output_folder = sys.argv[3]
The from here run the rest of your script. As @Simon Norris shows below.
Again, hope this helps!
A sample code for a script tool which will have a single check box. If a check box will be checked by a user, the tool will verify existance of a specified data file.
import arcpy
input_fc = r'C:\GIS\Temp\data_shp.shp'
#getting the input parameter - will become a tool parameter in ArcGIS of Boolean type
ischecked = arcpy.GetParameterAsText(0)
#Important to convert the check box value to a string first.
#Should be 'true' with the small case for 't',
#not the 'True' as shown in the Python window in ArcGIS
if str(ischecked) == 'true':
arcpy.AddMessage("The check box was checked")
result = arcpy.Exists(input_fc)
#to return 'True' or 'False' depending on whether the data file exists
#since it is a Boolean, important to convert it to a string
arcpy.AddMessage(str(result))
else: #in this case, the check box value is 'false', user did not check the box
arcpy.AddMessage("The check box was not checked")
Remember to add a tool parameter of Boolean data type when creating a new script tool in ArcGIS Desktop application. This parameter will be automatically shown as a check box when user runs the tool.
Best Answer
I've worked out how to do this albeit in a fairly simple manner. I wanted to create a multivalue parameter where I add many FeatureLayers and then choose an ID field for each layer. I've got it working but I was unable to work how to make the field a drop down list, so a user has to enter a field name manually. Here is the interface:
If anyone has managed to crack this problem or some guru from ESRI blesses us with their knowledge I would love to find out how to turn my second column (Site ID) into a drop down, listing specific fields. If you want to see an example of this have a look at the Create TIN tool.
Anyway to create this interface I create a script tool and added a parameter of type feature layer and set it to a multivalue as shown below.
I then clicked on the Validation tab at the top and then the Edit button. As this parameter is the 6th parameter in my script tool I updated the following code:
This resets the interface into the multi column table that I wanted. When you use GetParameterAsText it returns the following using my example:
pipeline pid;Dredging did
I've done some more research and have created the tool using a python toolbox. It works very well but does have a limitation if you go back and choose another ID. I have posted the code on GeoNet here.