Select to view content in your preferred language

Script working in Python window but not script tool

1944
13
01-29-2020 12:44 PM
GraceKeyes
Emerging Contributor

I'm new to Python but am working with a very simple script to convert elevation units from meters to feet. It works in the Python window but not as a script tool. Below is my script. 


import arcpy
arcpy.env.workspace = "C:\Users\keyesge\Desktop"

inputShp = "JunctionElev"
fieldName = "RASTERVALU"
expression = "!RASTERVALU! * 3.28084"

arcpy.CalculateField_management(inputShp, fieldName, expression,"PYTHON")

Any input is appreciated.

0 Kudos
13 Replies
DanPatterson_Retired
MVP Emeritus

fix the path problem first, it may fail without reporting the error if it is a script tool

And if it is a script tool, it would have no parameters is that what it shows when you run it?  That look more like a script you would run from the python window or the command line of another IDE like spyder or pycharm.

Also if you were running the script from outside of the builtin python window, nothing will get updated unless you close the table and reopen it.  If the table is open, it won't get refreshed.

0 Kudos
GraceKeyes
Emerging Contributor

 The results from running my script.

I fixed the file path. Again, I'm not getting any error messages and my table is closed when I run the script. Attached is a snip of my results window from running the script tool. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

Grace Keyes

the above seems to be different than the script reported in the original

arcpy.env.workspace = "C:\Users\keyesge\Desktop"

inputShp = "JunctionElev"

or is it the ElevationsTest.shp?

if it resides on the Desktop you will have issues.  Move the shapefile into a folder like r"C:\Temp" and skip the workspace and provide the full path to the file for the calculation

Can you fix or repost the script you are using that matches the above.

Also, since it is a shapefile, remove it from the project, then re-add it after the script has run

GraceKeyes
Emerging Contributor

Thank you for all your input I will try this!

0 Kudos