Triggering change of FontSize

Started by qw12, March 02, 2010, 01:02:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

qw12

How can I trigger the change of the fontsize (Char.Size) ?

To explain why I ask this question:
My goal is to create a "scalable text shape".
First I would use the "standard" trick: Char.Size = 12pt * Height / 0.75 in
Then I would like to enter a new Fontsize manually, e.g. 12 pt.

However, when the user changes the font size, my formula is replaced by 12pt, and scalabilty is lost
So it would be nice if I could catch the "FontsizeChanegd", and put back my formula...

Paul Herber

You can protect the font size with Char.Size = GUARD(12pt * Height / 0.75)
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

qw12

Quote from: Paul Herber on March 02, 2010, 01:25:24 PM
You can protect the font size with Char.Size = GUARD(12pt * Height / 0.75)

No, I want to let the user change the size.
This means I need to catch the change, and  then re-enter a new forumula, based on the size that the user just set.

Jumpy


Visio Guy

Something like this:

User.myTrigger = DEPENDSON(Char.Size) + SETREF(GETREF(Char.Size), "new_formula")

You might get stuck in a loop though.

Jumpy's suggest for the SETATREF function might work better, but it is difficult to explain how to use it. I would look in the Visio developer help and play with some of the examples to try and get an understanding for the SETATREFEVAL, SETATREFEXPR and SETATREF functions.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

qw12

#5
I didn't find many examples, but...
Most of my attempts to use the setatref failed with circular reference problems.

I also tried this:
width=SETATREF(Prop.testSize)     -> this cannot be overriden by the user (but PropTestSize changes when Width is changed)

Char.size=SETATREF(Prop.testSize)   -> this can be overriden by the user

Somehow, char.size seems to be very special.

Is there a pointer to a good / simple example of the setatref ? Preferably with Char.Size involved...:)


vojo

ok...for an whole new track

1. take your shape
2. draw a box sitting ontop of you shape
3. group them
4. remove the box
5. now go into your shape (contained in the over all group...only member left) and do something like this
        user.char = <overall group>.char * scale factor you want to use.
        char = guard(user.char)

So now when you change font size of the over all group, that char size is processed for the over all group
But since no actual text in over all group...nothing shows
However, since your shape takes that char size....scales it....applies it to your shape and all subshapes in your shape...visible chars scale

I do this for shading of 3D objects.

Jumpy

Or try this one:

=SETATREFEXPR(12 pt)*Height/0.75 in

The SETATREFEXPR() captures user input in the bracets and leaves the formula intact.

But be warned. When Charsize is changed to for example 14 pt. the formula is evaluated and the displayed charzise ("the value") "jumps" to the calculated value. So the user may be wondering: "He I changed it to 14 pt, why is it 22 pt instead???".

---
What you really want to do (I think) is, that when the user changes the charsize, that that shall be the new base for evaluations and that the charsize really shall be 14 pt. for the current height. However that is much more difficult and I have no idea as how to acomplish that.

qw12

Quote from: vojo on March 03, 2010, 05:37:11 PM
ok...for an whole new track

1. take your shape
2. draw a box sitting ontop of you shape
3. group them
4. remove the box
5. now go into your shape (contained in the over all group...only member left) and do something like this
        user.char = <overall group>.char * scale factor you want to use.
        char = guard(user.char)

So now when you change font size of the over all group, that char size is processed for the over all group
But since no actual text in over all group...nothing shows
However, since your shape takes that char size....scales it....applies it to your shape and all subshapes in your shape...visible chars scale

I do this for shading of 3D objects.

This seems to be the right track! I'll try it out.

qw12

Quote from: Jumpy on March 04, 2010, 07:59:36 AM
Or try this one:

=SETATREFEXPR(12 pt)*Height/0.75 in

The SETATREFEXPR() captures user input in the bracets and leaves the formula intact.

But be warned. When Charsize is changed to for example 14 pt. the formula is evaluated and the displayed charzise ("the value") "jumps" to the calculated value. So the user may be wondering: "He I changed it to 14 pt, why is it 22 pt instead???".

When I enter a new charsize, the formula is repalced by the new size, e.g. 14pt

Jumpy

#10
Quote from: qw12 on March 04, 2010, 08:28:58 AM
When I enter a new charsize, the formula is repalced by the new size, e.g. 14pt

Exactly not. If you enter in the ShapeSheet:

Cahr.Size:   =SETATREFEXPR(12 pt)*Height/0.75 in

and then manually change CharSize (for example to 18 pt) in UI, look at ShapeSheet again. The formula then will be:

=SETATREFEXPR(18 pt)*Height/0.75 in

That's the reason for the SETATREFEXPR() funciton: Capture userinput and  leave formula like it is.

I tried it out and it worked.

qw12

Quote from: Jumpy on March 04, 2010, 09:40:33 AM
Quote from: qw12 on March 04, 2010, 08:28:58 AM
When I enter a new charsize, the formula is repalced by the new size, e.g. 14pt

Exactly not. If you enter in the ShapeSheet:

Cahr.Size:   =SETATREFEXPR(12 pt)*Height/0.75 in

and then manually change CharSize (for example to 18 pt) in UI, look at ShapeSheet again. The formula then will be:

=SETATREFEXPR(18 pt)*Height/0.75 in

That's the reason for the SETATREFEXPR() funciton: Capture userinput and  leave formula like it is.

I tried it out and it worked.

hmm...I tried it out once again.... And with me it does not work.
Probably I'm doing something wrong? I have Visio 2003 Professional.

Jumpy

Ok, I use Visio 2007 Professional and there could be a difference.
But I always thouhgt the family of SETATREF-functions was introduced ot Visio with Version 2003, so I don't see why it won't work.

Try the attached drawing.

qw12

Quote from: Jumpy on March 04, 2010, 12:27:14 PM
Ok, I use Visio 2007 Professional and there could be a difference.
But I always thouhgt the family of SETATREF-functions was introduced ot Visio with Version 2003, so I don't see why it won't work.

Try the attached drawing.
Thanks for the drawing, but problem still active....However, I'll see if I can do the test on a Visio 2007. Perhaps I'm misunderstanding you....


Jumpy

That leaves brutal VBA force.
Create a user cell with:
=DEPENDSON(Char.Size)+CALLTHIS("CharSizeUpdate1")
in it. Eventually change the 1 to 2 if you want to use the optional code.

Store one of the following VBA-Codes in a VBA-modul:
Sub CharSizeUpdate1(ByVal shp As Visio.Shape)
'If a user changes char.size to i.e. 14 pt, this function
'will write the function 14pt*Height/0.75 in to the char.size cell.

Dim str_Fo As String

str_Fo = shp.Cells("Char.Size").FormulaU

If InStr(1, str_Fo, "in") > 0 Then Exit Sub 'This stops a loop

str_Fo = str_Fo & "*Height/0.75 in"
shp.Cells("Char.Size").FormulaU = str_Fo

End Sub


Sub CharSizeUpdate2(ByVal shp As Visio.Shape)
'If a user changes char.size to i.e. 14 pt, this function
'calculates a base value x, and
'will write the function x pt*Height/0.75 in to the char.size cell,
'so that it evaluates to 14 pt actual charsize.

Dim str_Fo, str_Sh As String, dou_Val As Double

str_Fo = shp.Cells("Char.Size").FormulaU

If InStr(1, str_Fo, "in") > 0 Then Exit Sub 'This stops a loop

str_Sh = Left(str_Fo, Len(str_Fo) - 3)


dou_Val = CDbl(str_Sh) * 0.75 / shp.Cells("Height").Result("in")


str_Fo = CStr(dou_Val) & " pt*Height/0.75 in"
str_Fo = Replace(str_Fo, ",", ".")

shp.Cells("Char.Size").FormulaU = str_Fo


End Sub


I hope this will help.