Importing Text File directly into Layout View

1970
3
04-07-2014 09:44 AM
JasonTheis
New Contributor
I have been searching multiple online forums and I have yet to find anything saying whether or not a text file can be imported into the Layout view in ESRI. My goal is to be able to import a given text file, which has a series of a data in it, into layout view to simply view. I'm not trying to manipulate the data in ESRI. I simply want to show the document in ESRI. Is this even possible?
Thanks in advance for your input.
0 Kudos
3 Replies
WilliamCraft
MVP Regular Contributor
There is not a way to do this if you want changes in the text file to be reflected in the map layout.  For example, you can add the text file to your map document using Add Data, then open it as an attribute table, and choose the Add Table to Layout option from the Table Options drop-down menu on the top left.  The process I followed is outlined here.  However, no row information ever appears in the layout when the table item is added... only the field names from the text file appear.  I have tried this with a TXT file and a CSV file, and I get the same results each time.  See screenshot below...

[ATTACH=CONFIG]32885[/ATTACH]

I suspect this functionality would work with DBF tables or other types of input, but unfortunately displaying information from a text file does not.  However, if you don't require that updated information in the text file be reflect 'real-time' within the layout, you can simply import your text file into a spreadsheet (e.g., MS Excel), format it the way you want, and then take a screenshot of the table to produce a JPG, BMP, PNG, etc.  From there, open the Insert menu and select Picture to import the screenshot into your layout.  It's static, but it gets the table into the map document layout. 

So, in summary, the answer to your question is "there isn't a way to do this in you need to preserve a link between the text file and the map document layout".
0 Kudos
JasonTheis
New Contributor
I didn't think about creating a jpg of the text file. I can write a script for that and do this for multiple files easily. Having the text file update as the file is changed does not matter in this particular application that I'm using this in. Thanks for your input I'll let you know how creating a jpg of the text file works and post the script once I've written it.
0 Kudos
JasonTheis
New Contributor
I ended up going a slightly different direction than mentioned above but in the end it worked for the purposes of my program. Create a text box in layout view manually and put some kind of identifier in it. After that you can essentially copy and paste a text file into the text box from whatever text file you choose. Here's a bit of code that I made:

with open("Text File") as d:
    lines = d.readlines()

for i in range(len(lines)):
    for textElement in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
        if textElement.text == position: ## Position is a user input of the number inside the Text box created in arc.
            textElement.text = lines + lines[i+1] + lines[i+2] + lines[i+3] + lines[i+4] + lines[i+5] + lines[i+6]

##depending on what all you want to call into the text box you may need to call more or less depending what is in your list created from the text file.
0 Kudos