2

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})
0

1 Answer 1

4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.