Select to view content in your preferred language

Text position within "rectangle text" field

596
3
11-03-2011 03:50 AM
VeraDiaz-Köhli
Deactivated User
Hello all

I have a text-field in a layout, that I have to populate with data from a database. As this data consists of one up to four lines of text, I'm using a rectangle-text-field. The text-position within the field should always be in the lower left corner, that is, if there's only one line of text, the empty space in the text-field should be above the line of text.
I can set the anchor point of the textfield, but I don't see any way of setting the textposition within the textfield.

Any ideas? Thanks in advance.
Vera
Tags (2)
0 Kudos
3 Replies
JeffBarrette
Esri Regular Contributor
I can't figure out how to do this in the UI and I'm certain you can't do it with Python using  rectangle text elements.  Height and position values involve the rectangle, not the text.

BUT ...

You could author 2 objects: a text element and a rectangle element.  Set both of their anchor positions to be lower left. You also need to set the vertical and horizontal positioning to be bottom and left, respectively. To do this, go to properties of text element, select text tab -->change symbol --> edit symbol.  Make sure the text now aligns nicely with the lower left corner of the rectangle.

Pull the text information from a field, evaluate the height of the text and set the heigth of the rectangle element accordingly.

For example.

mxd = arcpy.mapping.MapDocument("current")
lyr = arcpy.mapping.ListLayers(mxd)[0]
rect = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT", "rect")[0]
txt = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "txt")[0]
cur = arcpy.SearchCursor(lyr)
row = cur.next()
txt.text = row.getValue("filedName")
rect.elementHeight = txt.elementHeight + 0.1
arcpy.RefreshActiveView()


Why do it in the UI, when you can do it with ArcPy.
Jeff
0 Kudos
VeraDiaz-Köhli
Deactivated User
Jeff,

Thanks for the answer and the sample code.

It doesn't work like that though..


txt.text = row.getValue("filedName")
rect.elementHeight = txt.elementHeight + 0.1



If the text consists of more than one line, "txt.elementHeight" is still just one line high and thus in the rectangle text field all the text is written on the same line.

I solved my problem though by checking my text, if it contains "\n"-characters and if it does, I write it in an rectangle text field, otherwise in a simple text field.

Vera
0 Kudos
JeffBarrette
Esri Regular Contributor
I guess it depends on how the new lines are entered.  I had used shift-enter when entering multiple lines rather than \n.  My multi line text was showing the appropriate height.

I'm glad you got it to work.

Jeff
0 Kudos