Is it possible to Edit Standard Annotation with python

1310
7
08-09-2013 09:54 AM
AnthonyTimpson2
Occasional Contributor
I have created standard annotations which are simply text on the map and i need to edit the text contained within.

I though that these text annotations would be stored as text elements in the MXD, however it appears that they are not.

Is there any way to edit these annotations with python?
Tags (2)
0 Kudos
7 Replies
MattSayler
Occasional Contributor II
Looking like a 'no' to me. I added an element name to a piece of annotation, but I still wasn't able to access it. I tried adding a normal text element into the map and wasn't able to access that either, so at least part of it might be that they're embedded in the dataframe space instead of the layout space.
0 Kudos
AnthonyTimpson2
Occasional Contributor
Looking like a 'no' to me. I added an element name to a piece of annotation, but I still wasn't able to access it. I tried adding a normal text element into the map and wasn't able to access that either, so at least part of it might be that they're embedded in the dataframe space instead of the layout space.



that's exactly what I tried doing. Very disappointing, now I need to sort out how to make text elements on the fly and populate them with the data from several fields. ArcObjects it is then.. pain in my ass, oh well..

Thank you for confirming my frustrations.

Cheers!
0 Kudos
LaurenYee
Occasional Contributor
If you store your annotations in a geodatabase, you can access the attribute table and make edits from there or within an edit session.
0 Kudos
MattSayler
Occasional Contributor II
that's exactly what I tried doing. Very disappointing, now I need to sort out how to make text elements on the fly and populate them with the data from several fields. ArcObjects it is then.. pain in my ass, oh well..

Thank you for confirming my frustrations.

Cheers!


Is there a reason you can't make it an annotation feature class? Like yeel said, that would allow you to edit, make new ones, etc.
0 Kudos
JasonTaylor
New Contributor
I'm having the same question today. I love the idea of find/replace for text elements in an MXD, but it appears that those annotations that are apart of a dataframe annotation group are not exposed to python.

Can anyone at ESRI confirm this? I have about a 100 "4"s that need to be "7"s right now...

I think we would like something like...

for elm in arcpy.mapping.ListDataframeElements(mxd, "TEXT_ELEMENT"):
 if "Y4" in elm.text:
  print elm.text
0 Kudos
LaurenYee
Occasional Contributor
I'm having the same question today. I love the idea of find/replace for text elements in an MXD, but it appears that those annotations that are apart of a dataframe annotation group are not exposed to python.

Can anyone at ESRI confirm this? I have about a 100 "4"s that need to be "7"s right now...

I think we would like something like...

for elm in arcpy.mapping.ListDataframeElements(mxd, "TEXT_ELEMENT"):
 if "Y4" in elm.text:
  print elm.text


Taylor, just to clarify, your annotation is stored in the map - not in a separate geodatabase that is accessible via the TOC with an attribute table?

If you're working with Text Elements in your map, you can highlight all of them and then right click and select "Convert to Graphics" this will convert all text elements to annotation. In order to do this, first you need to create an annotation feature class in arcCatalogue. And then point your newly created annotation to the "blank" annotation you just created. This should then allow you to edit the attribute table and use the find and replace command!

Hope this helps!
0 Kudos
JasonTaylor
New Contributor
Yes Yeel, I took your hint from the above message and tried to find and replace with the field calculator. One problem with this method is that the field calculator doesn't handle carriage returns, so I had to use the updateCursor method in the Python console. This post was a big help --> Post <--

Essentially, you can only edit multi-line annotations programatically using a Python console. Even though it's pretty straight forward I'm sharing the meat of the code here in case anyone else comes across this post with the same intentions I had:

import arcpy
rows = arcpy.UpdateCursor(targetLayer)
trm = textToRemove
trp = textToReplace
for row in rows:
 if row.TextString is not None:
  if "tr" in row.TextString:
   row.setValue('TextString',row.TextString.replace(trm, trp))
   rows.updateRow(row)
del row, rows
0 Kudos