I am trying to convert my plain python script to script in ArcToolbox to share, where user can set input data (in this case, feature class). Unfortunately, Converting Python (ArcPy) script into tool or toolbox script? did not provide an answer for me, although I tried to follow it.
This is my working script which is working good when run from python window.
import arcpy
fcLst = [r"D:\GIS_Temp\Folder B\Water.shp"]
for fc in fcLst:
fieldList = [f.name for f in arcpy.ListFields(fc) if f.type == "String"]
if fieldList:
with arcpy.da.UpdateCursor(fc, fieldList) as cursor:
for row in cursor:
for i in range (len(fieldList)):
row[i] = row[i].replace("!","1")
cursor.updateRow(row)
I want to make script in ArcToolbox, with this code, where user can select for which feature class he wants to edit data (in this case, "D:\GIS_Temp\Folder B\Water.shp"
)
In ArcToolbox I created new script, clicked "store relative paths names (instead absolute paths), and browse to my python code, which I tried to edit given the answer on post I linked.
This is the python script for toolbox (which is not working):
import arcpy
fcLst = arcpy.GetParameterAsText(0)
for fc in fcLst:
fieldList = [f.name for f in arcpy.ListFields(fc) if f.type == "String"]
if fieldList:
with arcpy.da.UpdateCursor(fc, fieldList) as cursor:
for row in cursor:
for i in range (len(fieldList)):
row[i] = row[i].replace("!","1")
cursor.updateRow(row)
As you can see, I put arcpy.GetParameterAsText(0)
into code, so the user can select own data to edit. But I get this error:
Traceback (most recent call last): File "C:\Users\Name\Desktop\Script.py", line 4, in fieldList = [f.name for f in arcpy.ListFields(fc) if f.type == "String"] File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy__init__.py", line 1075, in ListFields return gp.listFields(dataset, wild_card, field_type) File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing_base.py", line 344, in listFields self._gp.ListFields(*gp_fixargs(args, True))) IOError: "D" does not exist Failed to execute (Script).
What am I missing? I have decent number of working codes in python, but I want to eventually convert them all to scripts in toolbox and share it with other users. What is the main process for converting the codes, and which parts of codes, given the example?
EDIT:
This is the tab i edited for the script for parameters: