Select to view content in your preferred language

Issue with elementHeight/elementWidth scaling text element

825
6
Jump to solution
10-29-2012 12:46 PM
MattSayler__Work_
Deactivated User
I'm working with a text element in a data driven page-enabled layout. I want to change the height of the element based on the number of lines of text. However, when I use the elementHeight property to do this it doesn't just change the height, it scales the element's width as well (and likewise elementWidth scales the height). The "Preserve Aspect Ratio" option is ghosted, so that setting is apparently locked in on text elements.

Anyone having this same issue? Know any work arounds?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MattSayler__Work_
Deactivated User
Bug Report has been generated by Support:
[#NIM086226  Width and height of rectangle text cannot be adjusted independently in arcpy.]

View solution in original post

0 Kudos
6 Replies
MattSayler__Work_
Deactivated User
I believe that is what I'm using. I picked "Rectangle Text" from the Drawing toolbar. I tried placing a brand new one, and the Preserve Aspect Ratio was ghosted from the start (although it appears to be unchecked).
0 Kudos
JeffBarrette
Esri Regular Contributor
If the objective is to fit variable length text into a limited area on a page layout and reduce the size of the text when necessary, it can be done using Python but requires some coding gymnastics. 

Here is a snippet of code that reads a string from a field and via the textwrap module, it breaks the code up into an appropriate number of lines.

def cloneText(txtElement, x, y, string):
    condoText_clone = txtElement.clone()
    condoText_clone.elementPositionX = x
    condoText_clone.elementPositionY = y
    condoText_clone.text = string

desc = row.getValue("LegalDesc")
wrapLines = textwrap.wrap(desc, 50)
for line in wrapLines:
    cloneText(legalDesc, x, y, line)
    y = y - legalDesc.elementHeight - y3


Where this can get more involved is if you want to test multiple variables ahead of time (e.g., total width vs total height) to optimize the text within the designated area.  It can be an iterative process to modify the fontsize and retest for fitting strategies.

Jeff
0 Kudos
MattSayler__Work_
Deactivated User
If the objective is to fit variable length text into a limited area on a page layout and reduce the size of the text when necessary, it can be done using Python but requires some coding gymnastics. 

Here is a snippet of code that reads a string from a field and via the textwrap module, it breaks the code up into an appropriate number of lines.

def cloneText(txtElement, x, y, string):
    condoText_clone = txtElement.clone()
    condoText_clone.elementPositionX = x
    condoText_clone.elementPositionY = y
    condoText_clone.text = string

desc = row.getValue("LegalDesc")
wrapLines = textwrap.wrap(desc, 50)
for line in wrapLines:
    cloneText(legalDesc, x, y, line)
    y = y - legalDesc.elementHeight - y3


Where this can get more involved is if you want to test multiple variables ahead of time (e.g., total width vs total height) to optimize the text within the designated area.  It can be an iterative process to modify the fontsize and retest for fitting strategies.

Jeff


I'm only changing the height of the element and the contents, no text format changes.

The only work around I can think of would be to create separate elements for each situation (thankfully few in this case), but that is not a very elegant solution and may not be a viable option in future cases.
0 Kudos
MattSayler__Work_
Deactivated User
Ok, I think what I'm going to do is switch to a basic text element and add a mask to the text in place of having a border and background. It will scale with the number of lines of text that way at least.

However, there's even some room for a little improvement with that kind of element too, as it seems to scale from the upper left corner and not the anchor point. Resetting the placement is simple enough though, so I think it will still be the easiest compromise to implement.

Is Esri Support the best way to report these kinds of 'bugs'?
0 Kudos
MattSayler__Work_
Deactivated User
Bug Report has been generated by Support:
[#NIM086226  Width and height of rectangle text cannot be adjusted independently in arcpy.]
0 Kudos
JeffBarrette
Esri Regular Contributor
FYI - the issue appears to be addressed in 10.1 SP1.  The issue would still need to be addressed in 10.0 if there is another planned service pack.

Jeff
0 Kudos