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_book\9_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
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
    Dec 30 '11 at 0:02
  • Also, make sure that your Text Element has the name Title.
    – PolyGeo
    Feb 27 '12 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 code
    – Czed
    Feb 19 '13 at 15:51

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.