For some work i was creating a tool which can add same field in attribute table of multiple feature classes. I wrote the script and it worked well but when i added this script to a tool; the tool didn't resulted in same results. I' m attaching screenshots for same. I'm kinda new to scripting and arcpy.
you need to use
GetParameterAsText—ArcPy Functions | ArcGIS Desktop
so that the parameters are derived from the tool itself.
It is more fully described in
Adding a script tool—Geoprocessing and Python | ArcGIS Desktop
The process is the same for ArcMap and ArcGIS Pro
I followed Dan Patterson your instructions but still it is getting failed .... your
Your toolbox shows that the tool is called "Script1" which means that you didn't associate your script "add.py" to the toolbox properly. hence the error message. Notice that the path to your toolbox is called
E:\Toolbox.tbx#add.py"
You need to follow
What is a script tool?—Geoprocessing and Python | ArcGIS Desktop
all the sections in here
Understanding script tool parameters—Geoprocessing and Python | ArcGIS Desktop
and in here
Adding a script tool—Geoprocessing and Python | ArcGIS Desktop
You will then get a properly formed and named toolbox with the script and its parameters correctly associated with the dialog.
It is still showing this error ....
dump all the parameters except for 0 and 1 for now
It seems that your first parameter is a multivalue parameter which return a semicolon delimited list of shapefiles. You will have to split that parameter on the semicolon and process each file in a 'for' loop. in fact, it doesn't even appear as a parameter in your original script, it is defined as a workspace and not featureclass(es).
Why don't you just run the existing tool in batch mode? (or can't you do that in arcmap? I can't remember)