Monday, 5 December 2016

arcpy - ArcGIS Python Script Tool Field Name Drop Down?


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



Answer



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



enter image description here


enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...