2

I'm specifically referring to the output of the Compare Table (Data Management) tool, which is a comma delimited text file.

When you add the text file manually, you can actually view it like any other table, by selecting "View Attribute Table," even though it's a just text file.

Previously, I've written code that adds the output of other tools to the map document, but these have always been feature class outputs, not text file outputs. Here's how I've added feature class outputs to an mxd in the past:

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
fc = pathToMyFeatureClass
arcpy.MakeFeatureLayer_management(fc, "fc_lyr")
addLayer = arcpy.mapping.Layer("fc_lyr")
arcpy.mapping.AddLayer(df, addLayer)

So I'm looking for something similar for the text file, and I'm not finding anything. Seems simple enough. I thought maybe something like arcpy.MakeTableView_management() might do the trick, but when I added that to my code, I got an error that my parameters were invalid, that the output of my Compare Table tool did not exist or is not supported, and since I know the output exists, then it must not be supported.

Per below comment, here are some screenshots. The attributes are sort of nonsensical to protect privacy. First screenshot is of the output text file, and the second is what it looks like once you view it in ArcMap.

enter image description here

enter image description here

  • Can you give an example of what the text file contains? – ianbroad Jul 16 '15 at 20:47
  • This may work with .csv files. If not, you could just use TableToTable to convert the csv to a .dbf and then add that. – mr.adam Jul 16 '15 at 20:47
  • @ian, sure I'll edit the question to include some screenshots – Kristen G. Jul 16 '15 at 20:52
  • @mr.adam AddTableView (arcpy.mapping). How did I miss that? I will try that tomorrow morning and give an update! – Kristen G. Jul 16 '15 at 20:56
  • @KristenG. I'm curious what you ended up doing? – ianbroad Jul 18 '15 at 4:38
2

This worked for me:

result_output = "C:\\Data\\Results.csv"

arcpy.TableCompare_management("C:\\Data\\Data.gdb\TaxLot", "C:\\Data\\Data.gdb\TaxLot2", "OBJECTID", out_compare_file=result_output)

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

data = arcpy.TableToTable_conversion(result_output, "in_memory", "Results")

table_view = arcpy.mapping.TableView(str(data.getOutput(0)))

arcpy.mapping.AddTableView(df, table_view)

One strange thing I noticed is that if I saved the result_output into my C root, when I used the TableToTable tool it would fail. I'm not sure why.

  • Possibly UAC settings... thanks to Windows the 'C' drive is ultra protected in an attempt to prevent unwanted nasties finding a permanent home. It would be much better to save to a separate partition or disc. – Michael Stimson Jul 16 '15 at 22:33
  • @MichaelMiles-Stimson well the strange part is that I use the C root all the time for quick tests. This is the first tool I've had an issue with. And it was just to read the file using the TableToTable tool. The Compare tool wrote to my C drive just fine. Maybe a bug? I'd be curious to see if it works for other people. – ianbroad Jul 16 '15 at 22:57
  • 1
    I use D:\Testing... my C is a SSD so I avoid writing to it to prolong its life - pagefile, TEMP and TMP are on D:\ also.. D:\ being a RAID(stripe) (note C:\ is faster at I/O than D:). It is quite weird that this is the first instance of not working, if it was UAC you'd expect it to fail on every tool. – Michael Stimson Jul 16 '15 at 23:01
  • @KristenG. Awesome! – ianbroad Aug 7 '15 at 17:05

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.