I have a script tool that prints a list of unique attributes in a feature class. It works fine in PythonWin. When I include it my model, it runs successfully, but does not display the attributes in the geoproccessing results window. I am a very new user to Python and ModelBuilder. I read the help previously on this site "Why are results from Python tool not in results window", but I still don't get it.
Here is my script that managed to put together.
import arcpy
arcpy.env.workspace = "F:\Shared\DDS\GIS\Infrastructure\DATAMIGRATE\CURRENTPROJ\HOUSTON_PLAT_TRACKER\ESRI\ImportAndCleanLines\Scratch\Scratch.gdb"
arcpy.env.overwriteOutput = True
with arcpy.da.SearchCursor ("DwgToUpload", "Layer") as cursor:
print sorted({str(row[0]) for row in cursor})
1 Answer 1
You need to change the print
line to arcpy.AddMessage()
:
import arcpy
arcpy.env.workspace = r"F:\Shared\DDS\GIS\Infrastructure\DATAMIGRATE\CURRENTPROJ\HOUSTON_PLAT_TRACKER\ESRI\ImportAndCleanLines\Scratch\Scratch.gdb"
arcpy.env.overwriteOutput = True
with arcpy.da.SearchCursor ("DwgToUpload", "Layer") as cursor:
arcpy.AddMessage( sorted({str(row[0]) for row in cursor}) )
The arcpy.AddMessage()
prints messages to the ArcGIS results window, the print
will only work in the Python window or in a separate IDE.
Also you need an r
in front of your workspace path (and any other paths) otherwise you are likely to get an error due to the slash \
in the path.
Explore related questions
See similar questions with these tags.