If I'm understanding the need correctly, you could modify the validation code so it will populate the list after selecting a layer. You might have to convert to a python script to get to it (it's in the Script Properties under the Validation tab).
The validation code contains functions that are run when the tool is opened, when a parameter is changed, and after internal validation runs. It doesn't reference a script file like the tool itself does. You have to either edit in place and save, or copy and paste your code in.
I modified this validation code to disable some parameter fields until the first parameter is picked. It also populates a pick list by grabbing the unique values from a feature class's attribute field. Basically, it's set up to wait for a connection to be picked by the user, uses that connection to look at feature class, populates a list based on the values found for one of the FC's fields, and only then makes the rest of the parameters available to fill in.
import arcpy
class ToolValidator:
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup the Geoprocessor and the list of tool parameters."""
self.params = arcpy.GetParameterInfo()
self.X = 0
def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
self.params[1].enabled = False
self.params[2].enabled = False
self.params[3].enabled = False
#self.params[4].value = "False" #for debugging
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."""
if self.X == 0:
if self.params[0].altered == True:
FC = str(self.params[0].value) + "\\gis.ELEC.ElectricDataset\\gis.ELEC.eCircuitBreaker"
self.params[4].value = FC
Col = "FeederID"
self.params[1].filter.list = [str(val) for val in \
sorted(\
set(\
row.getValue(Col) for row in \
arcpy.SearchCursor(FC, None, None, Col)\
)\
)\
]
self.params[1].enabled = True
self.params[2].enabled = True
self.params[3].enabled = True
self.X = 1
#self.params[4].value = "True" #for debugging
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
Some resources on script validation:
This is a problem that I've encountered many times, getting a disc full of tiles and needing to find the ones that are in/near an area to subset the rasters for building VRT, mosaic dataset or mosaicing (depending on requirements)...
I am not aware of any tool in Model Builder that will help with this, there is a limit to what can be done in model builder, however this kind of operation is very easy in python:
import os, sys, arcpy
AOI = sys.argv[1] # the area of interest to find the rasters for
rFolder = sys.argv[2] # the folder containing the rasters to search from
oFolder = sys.argv[3] # the folder to copy to
desc = arcpy.Describe(AOI) # get the extent of the AOI
sExt = desc.extent
arcpy.env.workspace = rFolder
for ThisRas in arcpy.ListRasters():
rDesc = arcpy.Describe(ThisRas)
rExt = rDesc.extent
# check if this extent is related spatially
# by using not disjoint
if sExt.disjoint(rExt):
arcpy.AddMessage("Raster %s is outside" % (ThisRas))
else:
arcpy.AddMessage("Raster %s overlaps" % (ThisRas))
outFile = os.path.join(oFolder,ThisRas)
arcpy.Copy_management(ThisRas,outFile)
This is a very cut-down tool that I use regularly; beware the AOI and the rasters must be in the same coordinate system.. You can use this in model builder after you have created your own toolbox and added a python script tool, the parameters are Feature Class, Folder and Folder (make them all input for simplicity).
I use sys.argv[] over arcpy.GetParameterAsText() - they both do the same thing but less typing.
This can be further refined using the geometries in the file (point, line or polygon - it doesn't matter):
import os, sys, arcpy
AOI = sys.argv[1] # the area of interest to find the rasters for
rFolder = sys.argv[2] # the folder containing the rasters to search from
oFolder = sys.argv[3] # the folder to copy to
desc = arcpy.Describe(AOI) # get the extent of the AOI
sExt = desc.extent
arcpy.env.workspace = rFolder
# could use walk here to do this folder and all subfolders
for ThisRas in arcpy.ListRasters():
rDesc = arcpy.Describe(ThisRas)
rExt = rDesc.extent
# check if this extent is related spatially
# by using not disjoint
if sExt.disjoint(rExt):
arcpy.AddMessage("Raster %s is outside" % (ThisRas))
else:
arcpy.AddMessage("Raster %s is a canditate" % (ThisRas))
outFile = os.path.join(oFolder,ThisRas)
# refine further with geometry
with arcpy.da.SearchCursor(AOI,"SHAPE@") as sCur:
IntersectsShape = False
for ft in sCur:
if not ft[0].disjoint(rExt):
IntersectsShape = True
break
if IntersectsShape:
arcpy.AddMessage("Copy Raster %s" % (ThisRas))
arcpy.Copy_management(ThisRas,outFile)
Best Answer
You need to go to Customize> Customize Mode on the Menu bar, in ArcMap. From there, click the commands tab, and select "Geoprocessing Tools" in the category list. Then browse to your toolbox containing the model and select it. This brings in the model to the commands. Now you can place it in a toolbar.