0

I have a script that shows certain features that are within a user-set distance of a point. I would like, however, to have those features that are "in the buffer zone" to be listed at the end when the layer is added in the form of a table. I know MakeTableView_management, but that only adds a table to the Table of Contents and doesn't open it so that doesn't really help me. Listing out rows also doesn't help since it doesn't appear clear in the message window. Therefore, is there some way to make a Table View, and have all the rows and columns of that table be displayed as a message? Or even a way to add the table and program it to automatically open?

This is what I have tried, but all it did was list the name of my table and not show anything as a message:

SourceCount = arcpy.MakeTableView_management("Selected_Sources", "Source_Table")
if arcpy.Exists("Selected_Sources"):
    arcpy.AddMessage("Creating a source layer to add to the map...")
    SourceLyr = arcpy.mapping.Layer("Selected_Sources")
    arcpy.mapping.AddLayer(df, SourceLyr, "TOP")
    arcpy.ApplySymbologyFromLayer_management("Selected_Sources", "E:/GIS/File_Organization/Data/Sources/Source_Colors.lyr")
    arcpy.AddMessage("Sources surrounding your point have been added to the map and are listed below.")
    arcpy.AddMessage("{0}".format(SourceCount))
else:
    pass
1
  • 1
    There is no way to open a table in ArcMap through arcpy. Interacting with the Application framework is something you would do with ArcObjects. – Hornbydd Dec 19 '17 at 15:27
2

Taking your SourceCount I tried to make a string of the tables content using a SearchCursor:

cur = arcpy.da.SearchCursor(SourceCount, "*")
data = [r for r in cur]
aString = "\n".join(map(str,data))

The cursor is used to access the table data, which then is transformed into a List using the little list comprehension. At last i used join to build the whole string, using new-lines to separate the table rows. This string could be used in a arcpy.AddMessage, but it will not display well i think...

1
  • This did work, but you were right about it not being very clear in the message box. Thank you though! At least gives me something to work with! – Daniel Katleman Dec 19 '17 at 15:53
0

You may also use the arcpy.TableToExcel_conversion() method to convert the table to .xls file and use python os.startfile() method to open the xls file in Excel at the end of your script. This would provide the user something easier to read and a file that is saved on disk for future reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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