I am trying to generate a map book with the following code that I downloaded but I keep getting an errror:
*File "Y:\Planning\GIS Planning Analyst\projects\county_map_book9円_GenerateMapBook.py", line 18, in <"module> titleText.text = title File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects_base.py", line 77, in _set return setattr(self._arc_object, attr_name, ao) RuntimeError: TextElementObject: Error in setting text*
#Read values from input dialog
title = arcpy.GetParameterAsText(0)
organization = arcpy.GetParameterAsText(1)
arcpy.AddMessage(" Updating Title Page ...")
titleMXD = arcpy.mapping.MapDocument("path\county_map_book\MapBook_TitlePage.mxd")
titleText = arcpy.mapping.ListLayoutElements(titleMXD, "TEXT_ELEMENT", "Title")[0]
titleText.text = title
arcpy.mapping.ExportToPDF(titleMXD,"path\county_map_book\Output1円_TitlePage.pdf")
del titleMXD
-
The error might be in grabbing the parameter. Try replacing the text element using a string you know to be valid, like this: titleText.text = "test string"dmahr– dmahr2011年12月30日 00:02:44 +00:00Commented Dec 30, 2011 at 0:02
-
Also, make sure that your Text Element has the name Title.PolyGeo– PolyGeo ♦2012年02月27日 07:06:25 +00:00Commented Feb 27, 2012 at 7:06
-
To elaborate on @PolyGeo - under the properties of the text element (right-click access), there is an option under the "size and position" tab to give it an "element name" This should match your codeCzed– Czed2013年02月19日 15:51:39 +00:00Commented Feb 19, 2013 at 15:51
1 Answer 1
I noticed that setting empty string to element text will give an error:
RuntimeError: TextElementObject: Error in setting text
So I used one space instead of empty string and that worked fine. In your code add this before setting text:
if title == '':
title = ' '
Weird behaviour of Python geoprocessing.