It's been years since I have worked with ArcPy and I'm having trouble setting up the parameters in my script tool.

What I'm trying to do:

I have a layer file (.lyr) that is a state wide index grid of available elevation model tiles. The layer's attribute table has a field "URL" that contains the download link. In my map document, I want to be able to make a selection of records in the layer and download the elevation model image tiles in my selected project area.

Here's the layer file. And the data table at the bottom:

enter image description here

What works:

I can run the script tool successfully but it's downloading all 15,000 files in the table not just my selected records.

this is the .py behind my script tool:


import urllib

import os

import arcpy

#where am I saving the download?
path = (str(arcpy.GetParameterAsText(1)))

#path to my index layer...stil unsure how to get this as a dropdown menu item in my tool
fc= r"C:\Users\Z\Desktop\LiDAR_Index.lyr"
cursor = arcpy.SearchCursor(fc)

for row in cursor:
    field ="URL"
    link =(row.getValue(field))
    head, tail = os.path.split(str(link))
    print "Downloading: "+ tail
    download=urllib.urlretrieve((str(link)), tail)


I'm lost as to how to only make this act on the selected records and not the whole feature class or shapefile.

Current UI on left and tool properties on right:

enter image description here

  • What version of ArcGIS?
    – Midavalo
    Sep 12, 2016 at 1:14
  • Are you selecting these features in a layer in ArcMap, and then only want to output those selected features?
    – Midavalo
    Sep 12, 2016 at 1:15
  • v 10.4 correct...I want to select a bunch of records, lets say a full city's coverage of DEM tiles, and run the tool to save the files all in one shot rather than individually downloading 15-20 individually
    – Zipper1365
    Sep 13, 2016 at 1:14

1 Answer 1


I think I see the problem. If you're selecting features in your layer in ArcMap and then running this script, the script isn't looking at the layer, but rather at a layer file .lyr stored elsewhere which doesn't have a selection. You need to tell your script to use your ArcMap layer, or to select the matching features in the layer file.

If you add the mxd line and change the fc line as follows, it should read your layer from within ArcMap.

mxd = arcpy.mapping.MapDocument("CURRENT")
fc = arcpy.mapping.ListLayers(mxd, "Lidar Index")[0]
cursor = arcpy.SearchCursor(fc)

It's also possible to make that a dropdown in your script tool. Change the DATA TYPE setting from String to Layer for your first parameter, and it should list all the layers in your current MXD. You could then pass this as a parameter to your script rather than specifying the name of the Layer in the List Layers.

  • Midavalo was right on money. Thanks! needed to specify the current mxd mxd = arcpy.mapping.MapDocument("CURRENT") fc = arcpy.mapping.ListLayers(mxd, "Lidar Index")[0] And since this is a the same .lyr that my whole department uses, I think I'm OK hard coding the layer name rather than dealing with the drop-down menu. That also means that I only need one parameter in the tool.
    – Zipper1365
    Sep 13, 2016 at 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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