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})
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Oct 20, 2016 at 18:35
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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Oct 20, 2016 at 19:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.