After some discussion with an Esri rep, I know have a solution and answer to WHY this issue is not really a bug (which I agree with). The reason this isn't really a bug is because Input is meant for files that already exist, Output is meant for new files, and I was trying to use the file selector as both either one. Ultimately this is just semantics but makes sense when you think about it.
Now the solution... In my dialog I created 3 input boxes: 1) A Required string type with Direction = Input and Value List = "New", "Append", 2) an Optional file type with Display name = "New", Direction = Output, and 3) an Optional file type with Display Name = "Existing", Direction = Input.
Now, in order to control which input box opens, thereby allowing my to choose either an output (new) or input (existing) file, I needed to put some code into the ToolValidator (Properties->Validation tab). Under the def initializeParameters(self)
category I added the following code to disable the New & Existing file input boxes at startup:
self.params[1].Enabled = 0 # 0 = Disabled, 1 = Enabled on load
self.params[2].Enabled = 0 #Disable on load
and under the def updateParameters(self)
category I added the following code to enable the correct file box based upon if I wanted to create a New or Append to existing file:
import sys, string, os
ftype = str(self.params[0].value)
if ftype == "New":
self.params[1].Enabled = 1 #
elif ftype == "Append":
self.params[2].Enabled = 1
Then from within my scripting code, I can just identify which option was selected for the 1st parameter (New or Append), and grab the text string from the appropriate optional file string from parameter 2 or 3 with a simple If/Then statement.
More details on programming the ToolValidator here:
http://webhelp.esri.com/arcgiSDEsktop/9.3/index.cfm?TopicName=Programming_a_ToolValidator_class
Since your cursor isn't iterable, use a while loop instead of a for loop:
rows = gp.SearchCursor(grids)
row = rows.Next()
while row:
...do something with each row...
row = rows.Next()
Best Answer
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.
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:
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:
The from here run the rest of your script. As @Simon Norris shows below.
Again, hope this helps!