<?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: Arcpy.mapping change text elemnts doesn't word with unicode in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-mapping-change-text-elemnts-doesn-t-word/m-p/62091#M4969</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can't reproduce either but that doesn't mean there isn't an issue.&amp;nbsp; I need to know more about your system environment. Please answer the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you using an English OS ? If not, please specify.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you using an English ArcGIS Desktop or&amp;nbsp; a localized ArcGIS Desktop to reproduce the issue? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please provides your workflow.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 01 May 2013 17:22:07 GMT</pubDate>
    <dc:creator>JeffBarrette</dc:creator>
    <dc:date>2013-05-01T17:22:07Z</dc:date>
    <item>
      <title>Arcpy.mapping change text elemnts doesn't word with unicode</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-change-text-elemnts-doesn-t-word/m-p/62089#M4967</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am having a problem for days and I just can't figure it out. I have this code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;cenario = "1"
num = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[6]
num.text = "CENÁRIO " + cenario

cond = "Sizigia"&amp;nbsp;&amp;nbsp;&amp;nbsp; 
textoGeral = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[9]
textoGeral.text =&amp;nbsp; "Condição" + cond&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the first text ("CENÁRIO") is working just fine when it change the text element on my mxd. However, the situation below is not working. If I put only the string "Condição" the ç and the ã goes just fine, but when I add it with the variable "cond" it goes nuts and puts strange simbols instead (see picture below).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]23773[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As you can see, the "CENÁRIO" WORKED just fine...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I looked some topics here on the forum and tryied everything.&amp;nbsp; In the begining of my code I have the &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#!/usr/bin/python
# coding: utf-8&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also have tryed put an "u" before the text like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;textoGeral.text =&amp;nbsp; u"Condição" + cond&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can some tell me what is happening?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The full script I take the cond information from a txt file. The full code is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#!/usr/bin/python
# coding: utf-8

import arcpy
import arcpy.mapping as MP
from datetime import datetime

startTime = datetime.now()

mxd = MP.MapDocument(r"p:\5270069_vli_tuf_dragagem_feL3\navigation\results\GIS_geral\Cenario_Basico_Santos_piacaguera_3.mxd")

DF1 = MP.ListDataFrames(mxd)[0]
Zoom1 = MP.ListDataFrames(mxd)[1]
Zoom2 = MP.ListDataFrames(mxd)[2]

projeto = raw_input("Digite o caminho com a pasta do projeto contendo os txts: ")


caminho_navios = projeto + "navios.txt"
f = open(caminho_navios,"r")
data = f.readlines()
numcenarios = len(data)


#Lendo o txt e separando as info
for i in range(0,numcenarios):
&amp;nbsp;&amp;nbsp;&amp;nbsp; vez = data&lt;I&gt;.split('\t')
&amp;nbsp;&amp;nbsp;&amp;nbsp; cenario = vez[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; navio = vez[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp; tipo = vez[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; rebocador = vez[3]
&amp;nbsp;&amp;nbsp;&amp;nbsp; condicao = vez[4]
&amp;nbsp;&amp;nbsp;&amp;nbsp; vento = vez [5]
&amp;nbsp;&amp;nbsp;&amp;nbsp; trackplot = vez[6]
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
#Changing layout elements...
&amp;nbsp;&amp;nbsp;&amp;nbsp; numero_projeto = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[4]
&amp;nbsp;&amp;nbsp;&amp;nbsp; numero_projeto.text = numProjeto

&amp;nbsp;&amp;nbsp;&amp;nbsp; num = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[6]
&amp;nbsp;&amp;nbsp;&amp;nbsp; num.text = "CENÁRIO " + cenario

&amp;nbsp;&amp;nbsp;&amp;nbsp; titulo_final = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[7]
&amp;nbsp;&amp;nbsp;&amp;nbsp; titulo_final.text = titulo
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; textoGeral = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[9]
&amp;nbsp;&amp;nbsp;&amp;nbsp; textoGeral.text =&amp;nbsp; "Condição" + condicao

&amp;nbsp;&amp;nbsp;&amp;nbsp; # textoGeral = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[9]
&amp;nbsp;&amp;nbsp;&amp;nbsp; # textoGeral.text = "Condição: " + condicao

#Exportando pra PDF
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Exportando mapa do cenario " + cenario

&amp;nbsp;&amp;nbsp;&amp;nbsp; MP.ExportToPNG(mxd, projeto + "TUF_Cenario_" + cenario + ".png")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "PNG Exportado"

&amp;nbsp;&amp;nbsp;&amp;nbsp; MP.ExportToPDF(mxd, projeto + "TUF_Cenario_" + cenario + ".pdf")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "PDF Exportado"

#Salvando copia do MXD
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.saveACopy(projeto + "TUF_Cenario" + cenario + ".mxd")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Cenario " + cenario + " Finalizado"

print "Esta rotina demorou " + str(datetime.now()-startTime) + " horas"
&lt;/I&gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Apr 2013 19:19:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-change-text-elemnts-doesn-t-word/m-p/62089#M4967</guid>
      <dc:creator>LeticiaNascimento</dc:creator>
      <dc:date>2013-04-25T19:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy.mapping change text elemnts doesn't word with unicode</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-change-text-elemnts-doesn-t-word/m-p/62090#M4968</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried your code, and it works just fine here.&amp;nbsp; I get "Condição Sizigia" in my layout text.&amp;nbsp; So I'm just guessing, but maybe it is your source code encoding. Make sure the text editor you are using saves the module file encoded to utf-8.&amp;nbsp; One other thing you might try is to change the coding header in your module from "# coding: utf-8" to "# -*- coding: utf-8 -*-"&amp;nbsp; I'm not sure either of these suggestions will help, but they are worth a try.&amp;nbsp;&amp;nbsp; Like I said, I cannot repeat the issue you are having.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Apr 2013 22:29:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-change-text-elemnts-doesn-t-word/m-p/62090#M4968</guid>
      <dc:creator>MikeHunter</dc:creator>
      <dc:date>2013-04-28T22:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy.mapping change text elemnts doesn't word with unicode</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-change-text-elemnts-doesn-t-word/m-p/62091#M4969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I can't reproduce either but that doesn't mean there isn't an issue.&amp;nbsp; I need to know more about your system environment. Please answer the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you using an English OS ? If not, please specify.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you using an English ArcGIS Desktop or&amp;nbsp; a localized ArcGIS Desktop to reproduce the issue? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please provides your workflow.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 May 2013 17:22:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-change-text-elemnts-doesn-t-word/m-p/62091#M4969</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2013-05-01T17:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy.mapping change text elemnts doesn't word with unicode</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-change-text-elemnts-doesn-t-word/m-p/62092#M4970</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Let's look at this logically. The text element is storing the text attribute as a unicode string. We can confirm this in the Arcmap Python window:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; textoGeral
&amp;lt;TextElement object at 0x19a71b70[0x19a6d480]&amp;gt;

&amp;gt;&amp;gt;&amp;gt; print textoGeral.text
Condição: Sizigia

&amp;gt;&amp;gt;&amp;gt; textoGeral.text
u'Condi\xe7\xe3o: Sizigia'
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But you are feeding it a byte string. We can see that in your code. (utf-8 is not unicode, it is a bunch of bytes that represent unicode). So somewhere in the arcpy.mapping code, your bytes are getting coerced into a unicode string.&amp;nbsp; For some reason, that coercion is failing to work correctly on your machine (but not mine and Jeffery's). It seems to me that if we eliminate the need for the coercion, then you might get happier results.&amp;nbsp; I suggest you feed the text element pure unicode:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
a = "Condição: ".decode('utf-8')
b = condicao.decode('utf-8')
txt = a + b
textoGeral.text = txt
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There may be something deeper going on, so this may not help.&amp;nbsp; But it's worth a shot.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:21:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-change-text-elemnts-doesn-t-word/m-p/62092#M4970</guid>
      <dc:creator>MikeHunter</dc:creator>
      <dc:date>2021-12-10T22:21:49Z</dc:date>
    </item>
  </channel>
</rss>

