2016-12-27 5 views
-1

レポートを印刷するためのmxdファイルがあります。マップとテキスト要素がありますが、テキスト要素の値を変更しようとしていますが、できません。それ。Esri Arcmapでテキスト要素の値を変更する際の問題

import arcpy 
import os 
import datetime 

def Actualiza_Texto(nombre, valor): 
    elementos = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT") 
    for elem in elementos: 
     if elem.name == nombre: 
     if type(valor) == str: 
      elem.text = unicode(valor, "utf-8", errors="ignore") 
     else: 
      elem.text = unicode(valor) 

Web_Map_as_JSON = arcpy.GetParameterAsText(0) 
tRazonSocial = arcpy.GetParameterAsText(1) 

ahora = datetime.datetime.now() 
output = 'Calculo_{}_{}_{}_{}_{}_{}.{}'.format(ahora.year,ahora.month,ahora.day, ahora.hour,ahora.minute,ahora.second, "PDF") 
templateMxd = os.path.join('c:/', "Carta_Vertical_1.mxd") 
result = arcpy.mapping.ConvertWebMapToMapDocument(Web_Map_as_JSON, templateMxd) 
mxd = result.mapDocument 

Actualiza_Texto('tRazonSocial', tRazonSocial) 
arcpy.AddMessage(tRazonSocial) 
Output_File = os.path.join(arcpy.env.scratchFolder, output) 
Actualiza_Texto('tDocumento', Output_File) 
arcpy.mapping.ExportToPDF(mxd, Output_File) 
arcpy.AddMessage("Se entrega el resultado como parametro {}".format(Output_File)) 
arcpy.SetParameterAsText(2, Output_File) 

filePath = mxd.filePath 
del mxd, result 
os.remove(filePath) 
arcpy.AddMessage("***FIN***") 

すべてのパラメータは正常に到着しますが、テキスト要素の値は変更されません。

+0

テキスト要素の名前が正しく指定されていることを確認しましたか? – Erica

+0

はい、私は持っており、解決策も見つけました。 –

+0

ソリューション 場合elem.name ==ノンブル: へ 変更した場合はelem.text ==ノンブル: そしてそれはすべての罰金を働いています。 –

答えて

0

私は解決策を見つけました。私はforブロックの "text"属性で "name"属性を変更しなければなりませんでした。

関連する問題