<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Write multiple lines to a text element in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/write-multiple-lines-to-a-text-element/m-p/71035#M5805</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;\r\n inserts a new line command.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;var = "OWNER1|OWNER2|MAIL1|MAIL2|CITY_STATE_ZIP5_ZIP4 \r\nDave_Jordan|Page1| | | \r\n|||\r\nBAYVIEW LOAN SERVICING LLC| |895 SW 30 AVE STE 202| |POMPANO BCH FL 33064 0\r\nBUCKSHIN, ROBERT| |4052 FOUNTAIN PALM RD| |COCOA FL 32926 311" elm.text = var&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 29 Aug 2012 19:47:19 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2012-08-29T19:47:19Z</dc:date>
    <item>
      <title>Write multiple lines to a text element</title>
      <link>https://community.esri.com/t5/python-questions/write-multiple-lines-to-a-text-element/m-p/71034#M5804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am writing a script that will produce mailing labels in a layout.&amp;nbsp; Basiclally, I have 30 text elements (3x10) on a page that I want to populate with the contents from a text file, which is pipe delimited.&amp;nbsp; For each line in the text file I am breaking out each line for the label using string.split('|').&amp;nbsp; Now I am stumped on how to write multiple lines of text to a text element in the layout.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My Question: How can I create new lines to a text element without overwriting the previous line of text?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here is a sample of the first 5 lines of the text file.&amp;nbsp; The first line is the header, so it gets ignored, the next two lines aren't actual labels but they get printed as if they are.&amp;nbsp; the last two lines are the actual label material.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;OWNER1|OWNER2|MAIL1|MAIL2|CITY_STATE_ZIP5_ZIP4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dave_Jordan|Page1| | |&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;|||&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;BAYVIEW LOAN SERVICING LLC| |895 SW 30 AVE STE 202| |POMPANO BCH FL 33064 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;BUCKSHIN, ROBERT| |4052 FOUNTAIN PALM RD| |COCOA FL 32926 311&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Import arcpy module import arcpy&amp;nbsp; #Get user supplied parameters fName = arcpy.GetParameterAsText(0) #Dist = arcpy.GetParameterAsText(1) #AppName = arcpy.GetParameterAsText(2)&amp;nbsp; # Local variables: mxd = arcpy.mapping.MapDocument("Current") mxd.activeView='PAGE_LAYOUT'&amp;nbsp; arcpy.RefreshActiveView() # Process: arcpy.AddMessage("==============================================") arcpy.AddMessage("Generating mailing labels from "+fName) #if arcpy.Exists(fName): try:&amp;nbsp; arcpy.AddMessage("Processing file...")&amp;nbsp; f1 = open(fName,'r')&amp;nbsp; lines = f1.readlines()&amp;nbsp; cnt = 0&amp;nbsp; #Start the count at zero to skip the header line in the text file&amp;nbsp; for line in lines: &amp;nbsp; arcpy.AddMessage("----Label "+str(cnt)) &amp;nbsp; for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"): &amp;nbsp;&amp;nbsp; if elm.name == "lbl"+str(cnt): &amp;nbsp;&amp;nbsp;&amp;nbsp; for val in line.split('|'): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if val != ' ': #Here is where I get stumped.&amp;nbsp; The AddMessage will print to the screen the way I want to brint to the label... &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = ????? &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.AddMessage(val) &amp;nbsp;&amp;nbsp;&amp;nbsp; #elm.text = line &amp;nbsp; cnt = cnt + 1&amp;nbsp; f1.close()&amp;nbsp; arcpy.RefreshActiveView() except Exception, e:&amp;nbsp; import traceback&amp;nbsp; f1.close()&amp;nbsp; map(arcpy.AddError, traceback.format_exc().split("\n"))&amp;nbsp; arcpy.AddError(str(e))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Aug 2012 19:30:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/write-multiple-lines-to-a-text-element/m-p/71034#M5804</guid>
      <dc:creator>DaveJordan1</dc:creator>
      <dc:date>2012-08-29T19:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Write multiple lines to a text element</title>
      <link>https://community.esri.com/t5/python-questions/write-multiple-lines-to-a-text-element/m-p/71035#M5805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;\r\n inserts a new line command.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;var = "OWNER1|OWNER2|MAIL1|MAIL2|CITY_STATE_ZIP5_ZIP4 \r\nDave_Jordan|Page1| | | \r\n|||\r\nBAYVIEW LOAN SERVICING LLC| |895 SW 30 AVE STE 202| |POMPANO BCH FL 33064 0\r\nBUCKSHIN, ROBERT| |4052 FOUNTAIN PALM RD| |COCOA FL 32926 311" elm.text = var&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Aug 2012 19:47:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/write-multiple-lines-to-a-text-element/m-p/71035#M5805</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-08-29T19:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Write multiple lines to a text element</title>
      <link>https://community.esri.com/t5/python-questions/write-multiple-lines-to-a-text-element/m-p/71036#M5806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you - That works.&amp;nbsp; I used the string.replace to replace the delimiters (|) with Newline Returns (\n\r):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; for line in lines:
&amp;nbsp; for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
&amp;nbsp;&amp;nbsp; if elm.name == "lbl"+str(cnt):
&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = line.replace('|','\r\n')
&amp;nbsp; cnt = cnt + 1&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:44:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/write-multiple-lines-to-a-text-element/m-p/71036#M5806</guid>
      <dc:creator>DaveJordan1</dc:creator>
      <dc:date>2021-12-10T22:44:10Z</dc:date>
    </item>
  </channel>
</rss>

