Chris, Kim,Enclosed is the script I've written (with a few minor rewrites of names). It works well, except for the Group Layer (in this example ","county features//parks") - it doesn't recognize the feature layer inside the group ("Parks"). I've tried to write the path every way Dale suggested ( // , \\ , \, /, ///) and still, it doesn't work.Thank you in advance(oh, and you're welcome to point out anything you think I can improve, as I am quite a NEWBIE)# -----------------------------------------------------------------------------------------------------------
#
# This script does a "select by location" query on layers in the TOC and exports the results as shapefiles.
#
# Note: when building a tool for this script, this tool requires a shapefile input
#
# -----------------------------------------------------------------------------------------------------------
# Import system modules
import sys, string, os, arcgisscripting
from os.path import basename, splitext
# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
# Load required toolboxes...
gp.AddToolbox("E:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")
gp.AddToolbox("E:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
multinputs = sys.argv[1]
inputlist = multinputs.split(";")
units = ["unit_388", "unit_434"]
# Local variables...
unitnames = [ splitext(basename(i))[0] for i in inputlist ]
cop_dictionary = {"local housing":"house","local streets":"streets","county features//parks":"cparks"}
#The cop_dictionary variable houses the layer's names: the first name as the one appearing in TOC, second name as name of output shp
#notice the third one is a parks layer in a group layer (county features)
part_path = "X:\\Exported_shps\\"
f = open( part_path + "logfile.txt ", 'a')
f.write(" The script is: " + str(sys.argv[0]))
for iter in cop_dictionary:
for curr in unitnames:
fc_output_subdir = part_path + str(curr) + "\\"
try:
os.makedirs(fc_output_subdir)
except OSError:
pass
exportkav = fc_output_subdir + cop_dictionary[iter]
imp = iter
inter = iter
using = "X:\\units_poly_bank\\" + curr + ".shp"
gp.AddMessage( cop_dictionary[iter] +" "+ curr)
f.write( " " + str(cop_dictionary[iter])+ " \n")
f.write(" " + str(curr)+ " \n")
desc = gp.Describe(imp)
typest = str(desc.ShapeType)
if "Point" in typest:
gp.SelectLayerByLocation_management(imp, "WITHIN", using, "", "NEW_SELECTION")
f.write("POINT LAYER DETECTED!! performing -WITHIN- select ONLY" + str(imp)+ " \n")
gp.AddMessage("POINT LAYER DETECTED!! performing -WITHIN- select ONLY")
else:
gp.SelectLayerByLocation_management(imp, "WITHIN", using, "", "NEW_SELECTION")
f.write("Finished -WITHIN- select"+ " \n")
gp.AddMessage("Finished -WITHIN- select")
gp.SelectLayerByLocation_management(imp, "CROSSED_BY_THE_OUTLINE_OF", using, "", "ADD_TO_SELECTION")
f.write("Finished -CROSSED_BY_THE_OUTLINE- select"+ " \n")
gp.AddMessage("Finished -CROSSED_BY_THE_OUTLINE- select")
# Process: Select...
gp.Select_analysis(inter, exportkav, "")
gp.AddMessage(exportkav + " has been exported \n")
f.write( str(cop_dictionary[iter]) + "_" + curr + " has been exported \n" )
# Use these commands when f i n i s h e d
f.write( "Total export has ended \n" )
f.flush()
f.close()
del inputlist, using, exportkav, imp, inter