Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Select Layer By Location different between stand-alone script and immediate mode?

$
0
0
I'm fairly new to arcpy, and I don't understand why this one line of code executes in immediate mode, but not in a stand alone script.
Code:

arcpy.SelectLayerByLocation_management("ProjectsLayer", "INTERSECT", "RegionOverlay")
When I run my .py script in ArcMap (shown below), my dialog box shows that the script completed successfully, but I don't see any evidence of a selection. Performing my code line by line in ArcMap's built-in python window, however, selects and highlights the applicable records. Must I add something more to my standalone script to perform this selection task?

Code:

import arcpy
arcpy.env.workspace = 'PATH_TO_RESOURCE'
arcpy.env.overwriteOutput = True
inFeatureClass = arcpy.GetParameterAsText(0)
if inFeatureClass == "Elderly block groups":
        selectedLayer = 'PATH_TO_RESOURCE'
elif inFeatureClass == "Minorities":
        selectedLayer = 'PATH_TO_RESOURCE'
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
newlayer = arcpy.mapping.Layer(selectedLayer)
projects = 'PATH_TO_RESOURCE'
projectsLayer = arcpy.mapping.Layer(projects)
arcpy.mapping.AddLayer(df, newlayer)
arcpy.mapping.AddLayer(df, projectsLayer, "TOP")
arcpy.MakeFeatureLayer_management(projects, "ProjectsLayer")
arcpy.MakeFeatureLayer_management(newlayer, "RegionOverlay")
arcpy.SelectLayerByLocation_management("ProjectsLayer", "INTERSECT", "RegionOverlay")
arcpy.MakeFeatureLayer_management("ProjectsLayer", "OverlayProjects")


Viewing all articles
Browse latest Browse all 2485

Trending Articles