Insert Text ?

478
4
03-04-2012 08:04 AM
OlivierOlivier
New Contributor III
Hi,

I would like to insert text in my map using arcpy and python. Problem, I do not find how I could do the same as the arcmap function Insert/Text.

May someone explain me how ?

Thanks,

Olivier
Tags (2)
0 Kudos
4 Replies
markdenil
Occasional Contributor III
Arcpy cannot actually make a new map element, it can only manipulate elements already present.
One option, if you need to have a text element occasionally present and occasionally not, is to create the element and 'park' it off the page.
Your code can then puppet the element onstage (so to speak) when it is wanted, to show the text you want.
Puppeting is easiest by shifting the element position in one dimension, x or y; for instance, parking it 10 inches in the x to the right. When it is needed on the page, subtract ten inches from the x location (and set the text string too, if wanted).

This functionality is obviously very limited, but arcpy is deliberately limited. If you need the code to make new things, you need to call ArcObjects.
That is not impossible to do, but there is no toll-free number for such a call.
0 Kudos
OlivierOlivier
New Contributor III
Hi Mark,

Thanks for the trick. My problem is that I would need many text elements as the objective is to place several attributes describing cables along each of them. Those cables come from a selection done thru a Python script after user selection, each selection generates a new resulting layer.

Of course, I could use labels, which are suited for that, but I have to do some treatments to build the labels and the label/expression is rather complicated. As I'm creating the cables's layers dynamically, I searched if I were able to load the lxp file from my Python script but it doesn't seem possible either (here is my other post).

So I'm a bit stuck, not being able to place my own labels, not being able to load lxp expression...

Olivier
0 Kudos
JeffBarrette
Esri Regular Contributor
Unforetunately, parking items off the page is really the only way to do it at 10.0. 

If your text elements are attribute values, then you may not need to park as many items as you think.  I do this all the time with tabular data.  I author one element for each column.  As I read the data table, I append each value to itself with a newline so the text grows vertically.  Set the anchor position to upper left.  Check out the following sample that does this:

http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=8C8E6EB6-1422-2418-A0B8-6AA61...

At 10.1, you will be able to clone existing text and graphic elements.  You author the parent text element with all the appropriate properties like size, color, boldness, etc then clone and move each new element into position.

Jeff
0 Kudos
OlivierOlivier
New Contributor III
Hi Jeffrey,

Ok, no as easy as I hoped, thanks for this nice example !

Olivier
0 Kudos