I am using Desktop 10.5.1
I have a python script, works great when I copy/paste into the ArcMap terminal and replace the arcpy.GetParameterAsText
function with a hard-coded string variable.
However when I put this script as a script tool inside a toolbox I get errors for the input values.
the code is below for the script tool.
import arcpy
arcpy.env.overwriteOutput = True
structures = arcpy.GetParameter[0]
Prim_Conductor = arcpy.GetParameter[1]
TableOutput = arcpy.GetParameter[2]
PrimConductor_FL = "Primary_Conductor FL"
structures_FL = "structures_lyr"
arcpy.MakeFeatureLayer_management(structures, structures_FL)
whereSQL = """ Damage_Cat = 'Major Damage' OR Damage_Cat = 'Minor Damage' """
arcpy.SelectLayerByAttribute_management(structures_FL, "NEW_SELECTION", whereSQL)
bufferOutput = r"\\path\to\shapefile.shp"
arcpy.Buffer_analysis(structures_FL, bufferOutput,"20 Feet", line_side="FULL", line_end_type="ROUND", dissolve_option="NONE", dissolve_field="", method="PLANAR")
arcpy.SelectLayerByAttribute_management(structures_FL, "CLEAR_SELECTION")
arcpy.MakeFeatureLayer_management(Prim_Conductor, PrimConductor_FL)
arcpy.SelectLayerByLocation_management(PrimConductor_FL, "INTERSECT", bufferOutput)
arcpy.TableToExcel_conversion(PrimConductor_FL, TableOutput, "NAME")
Parameter data types in the tool properties are:
- [0]: Feature Class (it is a SDE featureclass)
- [1]: Feature Class (SDE Feature Class)
- [2]: File (output direction)- output for excel file.
The error I see is:
Traceback (most recent call last):
File "Y:\Emergency Data\Electric V-Look Up\Script Tool\Script.py", line 7, in <module>
structures = arcpy.GetParameter[0]
TypeError: 'function' object has no attribute '__getitem__'
Failed to execute (Script).
1 Answer 1
It's trying to "get" an item (sort of like from an array or list) because of the brackets to mark the parameter number - the function takes the index for each parameter in () parentheses. Also, GetParameter() returns an object (instead of a string value to input into geoprocesses, like you have).
Simple fix:
import arcpy
arcpy.env.overwriteOutput = True
structures = arcpy.GetParameterAsText(0)
Prim_Conductor = arcpy.GetParameterAsText(1)
TableOutput = arcpy.GetParameterAsText(2)
-
ahh this works if I open the directory folder and navigate to the FC, but it wont let em drag and drop it in the parameter box. Says Invalid...?NULL.Dude– NULL.Dude2018年05月02日 20:08:38 +00:00Commented May 2, 2018 at 20:08
-
1Yup that's an annoying thing - when the FC draws in Arc it's creating a layer (in memory) - go into the Script Properties window and change that parameter type to Layer from the drop-down, and it should work as intended.AlecZ– AlecZ2018年05月02日 20:22:18 +00:00Commented May 2, 2018 at 20:22
Explore related questions
See similar questions with these tags.