I have a shape, with a user defined cell that contains a string. The shape is set to display this in its text field and the width of the shape is contolled using the TEXTWIDTH of the string. The first time the string in the user defined cell is changed, the width of the shape is not changed and the text displays vertically with the width remaining unchanged. Subsequent changes to the string cause the TEXTWIDTH to behave as expected.
This works fine with Visio 2003.
Any suggestions as I am replacing shapes via automation that have the text strings copied across. However, all the text widths are then wrong.
Does this happen with just shapes that you replace, or does it also happen with new, fresh placements as well?
Unless there're differences between your 2003 shapes and 2007 shapes, why replace them? ???
Happens with fresh placements.
As for replacing, my masters can change over time so I have a mechaism that replaces my shapes on the diagram copying across any data that I need to be kept.
I've not heard of any bugs regarding this. If I understand what you're doing, then in the shapesheet:
1> Text Transform section, TxtWidth cell, you have an entry that looks like: TEXTWIDTH(TheText)
2> Shape Transform section, Width cell, you could possibly have an entry like: IF(TxtWidth<1,1 in,TxtWidth).
These shapesheet functions should work for both V2003 and V2007. I'm not in front of V2007 at the moment.
I was actually using a user-defined cell, i.e. TEXTWIDTH(User.DisplayName). However, I have changed to use TEXTWIDTH(TheText) and this seems to work. Wondering if TheText is handled differently to other cell references.
So subject to further testing I will go with this as a fix.
insert field into the textbox. get user cell info with textbox behavior
TEXTWIDTH(User.DisplayName) won't work. Text has font size, bold, italic, and various runs with various formatting. I'm pretty sure TEXTWIDTH and TEXTHEIGHT are designed to work with TheText only, not with strings or string-references as arguments.
To add some background to VisioGuy's comments regarding the TextWidth, TheText "functionality" check out these links:
TextWidth: http://msdn.microsoft.com/en-us/library/ms425580.aspx
TheText: http://msdn.microsoft.com/en-us/library/aa221326(office.11).aspx
Designing Text Behavior: http://msdn.microsoft.com/en-us/library/aa200986(office.10).aspx
If you still have troubles, there's an alternative approach using the "len" function: http://msdn.microsoft.com/en-us/library/ms406722.aspx. See the attached example. Sorry, had to have some fun!!! ;D
In the TxtWidth cell, you could enter a formula similar to this: len(User.Whatever)*Char.Size/SF. SF is a scale factor to correct for the translation of Char.size from points to inches. User.Whatever is your user defined cell. The shape width should still remain based upon TxtWidth. BTW, it may be necessary to "guard" the formula in the Width cell, otherwise it may get clobbered.
HTH
Wapperdude
Thanks wapperdude and Visio Guy. I was coming to the conclusion that it maybe only worked with the text width as thats all any examples show, although this was fine with 2003. Seems a shame the documentation couldn't just simply state that. A sit happens in my case the text is in a sub-shape of its own so I have changed to use TEXTWIDTH(TheText).
works fine
1. shapesheet...create user cell....place text...exit shapesheet
2. double click shape...insert field....user.cell...enter
3. shapesheet...add text transform....txtwidth= textwidth(thetext, xx mm)...exit out
change msg, font size, etc....the width of the text is held to textwidth behavior.
Just did this...not sure why you think it does not work
If you are trying to scale the font....All the methods I have seen have nothing to do with textwidth or textheight. Usually it is done be comparing the size of the shape with the page.
Something like
user.fontscale = (shape!width / page!width) * <some scaling factor...trial and error>
font = user.fontscale
A couple of points of clarification:
I'm sure VisioGuy will correct me if I'm wrong, but, I believe what he's saying is that you can't literally put the user.cell reference directly in the TextWidth formula.
In my example, the point of the "len" approach is that the function returns the number of characters in the string, hence, the reference link I provided. Because it is a character based result, to get the actual length, it is necessary to multiply by the character size...and the unfortunate scale factor. The Visio example, just scaled the font size because that was easier than entering more, or less, text. The effect was (is) the same, the shape resizes based upon the actual length of the string. However, I don't think using the "len" approach is a necessary route to take. The "TextWidth(TheText)" ought to work just fine.
Using the Insert > Field that Vojo suggests, and, is how I inserted the user.cell text into the shape textbox, seems to put it in as a string. At least, that's how "TheText" interprets it.
I hope that helps clarify things.
Wapperdude
perhaps I am missing something...but this is what I believe you are after
(inspect shape sheet to see the user cell and the textwidth in the txtwidth cell)
OK. So lunch was boring...
The example is now modified such that it uses Shape Data to easily enter the text, and, it uses TextWidth(TheText) rather than the "len" option. Note, the Shape Data was added via Insert > Fields technique.
Enjoy.
Wapperdude
Yes Visio Guy was correct, the TEXTWIDTH etc can only have 'TheText' and not a user defined cell (in Visio 2007). I have changed to use this and now all works fine.
... he tends to be. ;)