I need to update a text element in a group of MXDs that I manage. That element, however, is locked in the layout using the lock function from the Production Cartography tool. Using python, is there a way to unlock this text element? In testing, I've found that once it is unlocked I'm able to access the element's content and update it.

Here's the basic code snippet that I'm using:

mxd = arcpy.mapping.MapDocument(md)
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
    if elm.name == "CompantyTxt":
        elm.text = "New Text to Replace the Old Text"

I can run this code with the desired text element getting updated if the element is not locked. With it locked, however I get the following runtime error:

"File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects_base.py", line 87, in _set return setattr(self._arc_object, attr_name, cval(val)) RuntimeError: TextElementObject: Error in setting text"

  • Please include a snippet of code that you've tried – Midavalo Sep 22 '16 at 18:52
  • Why is it locked? Cant you just unlock manually before the script? – ziggy Sep 22 '16 at 19:44
  • We lock it to keep it from getting shifted/moved inadvertently. We have about 900 of these maps though so I was looking to automate it. – Bernie Sep 22 '16 at 19:55
  • @Bernie do you need them to be re-locked after the script? – Midavalo Sep 22 '16 at 23:03
  • @ Midavalo Preferably. Especially if I can find a way to automate this. – Bernie Sep 23 '16 at 0:41

Your Answer

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

Browse other questions tagged or ask your own question.