I've been able to add a dynamic text element (with an element name of 'TestName') that reflects a layer name and that changes for each corresponding exported layer to a GIF. I am now trying to add a second text element (with an element name of 'TestName2') for a map title but am running into issues. Below is the code I am working with. CMD prompt produces this error:
C:\UserS\JameS>export5.py
[<map layer u’Div1_Irrig_1987_2’>, <map layer u’Div1_Irrig_1987_2’>, <map layer
u’Div1_Irrig_1956_0’>, <map layer u’citylyr’>, <map layer u’boundlyr’>]
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.2\Scripts\TestScripts\export5.py”, line 42, in <module>
elm.text : ""
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\7base.py", line 89, in _set
return setattr(self._arc_object, attr_name, cval(val))
RuntimeError: TextElementObject: Error in setting text
C:\Users\James>
for lyr in lyrlist:
lyr.visible = False
#if lyr.name in layers and lyr.name <> layer:
# lyr.visible = False
if lyr.name == "citylyr":
lyr.visible = True
if lyr.name == "boundlyr":
lyr.visible = True
if lyr.name == name:
lyr.visible = True
layerOn = lyr.name
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.name == 'TestName':
elm.text = lyr.name
if elm.name == 'TestName2':
elm.text = 'Example Map Title Name'
else:
elm.text = ""
if layerOn:
arcpy.mapping.ExportToGIF(mxd,r"{}\{}.gif".format(GIFPath,layerOn))
