7

I have a python script that checks file path names for corresponding files in a drive location. All of the inputs were originally hard coded, and it works well enough:

    import arcpy
    import os
    shp = r"C:\Users\dotwell\Desktop\Locations.shp"
    fields = ["ZdriveLoc"]
    f = open (r"C:\Users\dotwell\Desktop\ValMapsTest.txt", "w")
    cursor = arcpy.da.SearchCursor (shp, fields)
        for row in cursor:
            Roll=str(row[0])
            if not os.path.exists(Roll):
            f.write(Roll + os.linesep)


    f.close()

I'm trying to create an ArcGIS script tool from this, and I've only had partial success. I can use

shp = arcpy.GetParameterAsText(0)

to allow the user to select the shapefile. I'd like to then have a drop down list of the fields in that shapefile for the user to select the field that contains the path names, but I can't get it to work. Can someone show me how to generate the drop down? Here's my latest try. It works, but requires the user to type in the field name. It would also be nice for the user to designate the output text file name and location.

import arcpy
import os
shapefile = arcpy.GetParameterAsText(0)
field = arcpy.GetParameterAsText(1)
f = open (r"C:\Users\dotwell\Desktop\ValMapsTemp.txt", "w")
cursor = arcpy.da.SearchCursor (shapefile, field)
for row in cursor:
    Roll=str(row[0])
    if not os.path.exists(Roll):
        f.write(Roll + os.linesep)


f.close()

Here are the parameters in my ArcGIS script tool: ArcCatalog Script Properties

  • 1
  • I'll close this question as a duplicate and then merge the two questions. That means that your question will act as a gateway to the two answers in one place, which gives us a chance to take advantage of being a wiki to improve both Q&As into a canonical Q&A. I'll also rollback your last edit - because the contents of Q&As should be the actual question and answers rather than commentary about the Q&A (which is best placed in comments). – PolyGeo Nov 19 '15 at 21:42
  • 1
    Actually, I've changed my mind and I'll do the duplicate/merge in the other direction because that earlier question is far inferior to this one. – PolyGeo Nov 19 '15 at 21:43
9

Change the "Obtained from" property for the input to the shapefile parameter.

enter image description here

enter image description here

4

First Add the file as the first parameter (you probably already got this far). Then add a field. Filter the field as in my top screenshot for the type of data for your field. "Obtained From" provides the answer to the question. You have to set that to your FILE. You also have to set the TYPE to Derived (instead of required) on the Field. enter image description here enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.