I am probably making a simple mistake but can't seem to figure it out, only a beginner.The Select By Location Script is working and it exports to excel when it is run from Python GUI, it also works in ArcGIS when i use the Pyton Shell but when i try to make a tool out of it in ArcGIS it does not work. The error was ERROR 000714, which the help says there is an error in the script. If it works in Python GUI and in ArcGIS Python Shell (picture below) , why does this error appear when i try to run the custom tool? any ideas? enter image description here

import arcpy

arcpy.env.workspace = "Z:\GIS TEST\Select_by_Location"
arcpy.MakeFeatureLayer_management('Bld_Locations.shp', 'Bld_Locations_lyr')
arcpy.SelectLayerByLocation_management('Bld_Locations_lyr', "WITHIN_A_DISTANCE", 'Breakout_Location.shp', "2000 Meters", "NEW_SELECTION")
arcpy.SetParameterAsText(0, BOL)

arcpy.MakeFeatureLayer_management('Bld_Locations.shp', 'Bld_Locations2_lyr')  
arcpy.SelectLayerByLocation_management('Bld_Locations_lyr', "WITHIN_A_DISTANCE", 'RiversITM.shp', "100 Meters", "ADD_TO_SELECTION")

CSVFile = 'Z:\\Excel.csv'

fields = [f.name for f in arcpy.ListFields('Bld_Locations_lyr')]

for i,f in enumerate(fields):
    if f == 'Shape' or f == 'Shape_Length' or f == 'OBJECTID':
    del fields[i]

with open(CSVFile, 'w') as f:
    f.write(','.join(fields)+'\n') #csv headers
    with arcpy.da.SearchCursor('Bld_Locations_lyr', fields) as cursor:
        for row in cursor:
            f.write(','.join([str(r) for r in row])+'\n')

There will only be one input into the Custom Tool, that is why i only used one parameter.

  • 5
    It looks like you are writing a Python script tool rather than a Python toolbox. If you want one input then there should be a GetParameterAsText (not SetParameterAsText) used. – PolyGeo Dec 17 '13 at 11:52

How to access parameters in a script tool using arcpy.GetParameterAsText() is described here.

The way that you tried, arcpy.SetParameterAsText(), is intended for setting output rather than input parameters


It turned out to be pretty simple, these are the things that get me the most.

I Change:

    arcpy.MakeFeatureLayer_management('Bld_Locations.shp', 'Bld_Locations_lyr')


    arcpy.MakeFeatureLayer_management('Bld_Locations', 'Bld_Locations_lyr')


    arcpy.MakeFeatureLayer_management('Bld_Locations.shp', 'Bld_Locations2_lyr')


    arcpy.MakeFeatureLayer_management('Bld_Locations', 'Bld_Locations_lyr')

Then save the filename as .py

This allowed the tool to work correctly


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.