leportella

Arcpy.mapping change text elemnts doesn't word with unicode

Discussion created by leportella on Apr 25, 2013
Latest reply on May 2, 2013 by mahunter243
Hello,

I am having a problem for days and I just can't figure it out. I have this code:

cenario = "1"
num = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[6]
num.text = "CENÁRIO " + cenario

cond = "Sizigia"    
textoGeral = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[9]
textoGeral.text =  "Condição" + cond


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).

[ATTACH=CONFIG]23773[/ATTACH]


As you can see, the "CENÁRIO" WORKED just fine...

I looked some topics here on the forum and tryied everything.  In the begining of my code I have the

#!/usr/bin/python
# coding: utf-8


I also have tryed put an "u" before the text like:

textoGeral.text =  u"Condição" + cond


Can some tell me what is happening?

The full script I take the cond information from a txt file. The full code is:

#!/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):
    vez = data[i].split('\t')
    cenario = vez[0]
    navio = vez[1]
    tipo = vez[2]
    rebocador = vez[3]
    condicao = vez[4]
    vento = vez [5]
    trackplot = vez[6]
    
    
#Changing layout elements...
    numero_projeto = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[4]
    numero_projeto.text = numProjeto

    num = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[6]
    num.text = "CENÁRIO " + cenario

    titulo_final = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[7]
    titulo_final.text = titulo
    
    textoGeral = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[9]
    textoGeral.text =  "Condição" + condicao

    # textoGeral = MP.ListLayoutElements(mxd, "TEXT_ELEMENT")[9]
    # textoGeral.text = "Condição: " + condicao

#Exportando pra PDF
    print "Exportando mapa do cenario " + cenario

    MP.ExportToPNG(mxd, projeto + "TUF_Cenario_" + cenario + ".png")
    print "PNG Exportado"

    MP.ExportToPDF(mxd, projeto + "TUF_Cenario_" + cenario + ".pdf")
    print "PDF Exportado"

#Salvando copia do MXD
    mxd.saveACopy(projeto + "TUF_Cenario" + cenario + ".mxd")
    print "Cenario " + cenario + " Finalizado"

print "Esta rotina demorou " + str(datetime.now()-startTime) + " horas"


Thank you

Attachments

Outcomes