I have a tool where I'm trying to do some script validation. The user selects a data frame from a map as the first parameter, self.params (works fine), and then should select a layer from the layers in that data frame. However, I can't get the second parameter to populate based just on the selected dataframe. The code below doesn't throw an error, but returns an empty list, and thus no layers to select. I've tried several variations on this, and the only one that works at all returns all layers in the mxd, not just the ones in the data frame. This seems like it should be simple, but I'm missing something. Any ideas? Thanks.
def initializeParameters(self): """Refine the properties of a tool's parameters. This method is called when the tool is opened. Populates data frame parameter with data frames in map and disables other parameters. """ try: # this works mxd = arcpy.mapping.MapDocument('CURRENT') dflist = [df.name for df in arcpy.mapping.ListDataFrames(mxd)] self.params.filter.type = "ValueList" self.params.filter.list = dflist del mxd except: arcpy.AddError("\nMust run this tool in ArcMap, not ArcCatalog") self.params.enabled = False self.params.enabled = False return def updateParameters(self): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.""" mxd = arcpy.mapping.MapDocument('CURRENT') if self.params.value: self.params.enabled = True # this does not work the way I want layerList = [lyr.name for lyr in arcpy.mapping.ListLayers(mxd, self.params.value) if not lyr.isGroupLayer] uniqueList = list(set(layerList)) uniqueList.sort() self.params.filter.type = "ValueList" self.params.filter.list = uniqueList
Solved! Go to Solution.