Select Input Parameters from Dropdown List Showing Current Map Layers

2369
3
05-10-2011 10:04 AM
AmySmith1
New Contributor II
Hello!

I'm very new to creating script tools, and I recently started working with the Tool Validator. I'd like the users of my script tool to be able to select their input parameters from a dropdown list showing current map layers that match the input type (for example, if the input is specified as the type "Feature Class", a list of feature classes in the current map document would appear as options in a dropdown list). Most of the ArcGIS tools automatically do this.

Although it doesn't work, this is what I have come up with so far (input 1 is a Feature Class, and input 2 is a Raster):

def initializeParameters(self):
    
    mxd = arcpy.mapping.MapDocument("CURRENT")
    featureLayerList = []
    rasterLayerList = []
    for lyr in arcpy.mapping.ListLayers(mxd):
      if lyr.isFeatureLayer == True:
        featureLayerList.append(lyr.name)
      elif lyr.isRasterLayer == True:
        rasterLayerList.append(lyr.name)
    self.params[1].filter.list = featureLayerList
    self.params[2].filter.list = rasterLayerList

    return


I would greatly appreciate any advice!

Ride the lightning,

Amy

---
www.wolfmapper.com
Tags (2)
0 Kudos
3 Replies
LoganPugh
Occasional Contributor III
It should work like this by default (no ToolValidator modifications needed) as long as your input parameter is of type Feature Layer.
0 Kudos
AmySmith1
New Contributor II
Thanks, lpugh01. I don't know why, but it is not working this way by default. Does anyone have any idea why this might be happening?

Amy

---
www.wolfmapper.com
0 Kudos
AmySmith1
New Contributor II
Ah, I see, there's a difference between a Feature Class and a Feature Layer. Like I said, I'm new at this! Thanks again for your help. 😮

Amy

---
www.wolfmapper.com
0 Kudos