Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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"
BOL='Breakout_Location.shp'
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.

share|improve this question
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

2 Answers 2

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

share|improve this answer

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')

To:

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

And

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

To

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

Then save the filename as .py

This allowed the tool to work correctly

Cheers

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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