Near analysis does not run in stand alone script

Discussion created by jesuspisto on Sep 21, 2012
Latest reply on Sep 21, 2012 by jesuspisto
I'm using a bunch of tools in a stand alone script, and the near analysis tool does not work. Behavior is erratic, it runs from within ArcGIS only if the candidates are supplied as a string, not as a feature layer.

import arcpy

pMXD = arcpy.mapping.MapDocument("C:\\Proj\\BBerry.mxd")
pDF = arcpy.mapping.ListDataFrames(pMXD, "Layers")[0]

## Candidates are point feature class
for fc in pDF:
    if == "Candidates":
        nearFeatures = fc
    if == "tmp":
        inFeatures = fc

## arcpy.Near_analysis(inFeatures, nearFeatures, "", "NO_LOCATION", "NO_ANGLE") ## Does not work!
arcpy.Near_analysis(inFeatures, "Candidates", "", "NO_LOCATION", "NO_ANGLE") ## Works 

The goal is to add this function to a stand alone script, but it does not work as such no matter what. Stand alone script error message is:

[INDENT]arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Near Features: Dataset Candidates does not exist or is not supported
Failed to execute (Near).[/INDENT]

Any suggestions are welcome.