Any way to access the current default font size?

Started by stugol, January 25, 2013, 02:16:51 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stugol

We have a bunch of shapes made and stored on a stencil. For example, when we made the shapes, the font size is set to 10pt. Later users might want to set their default font size to 8pt. But whenever you drop one of the shapes to your drawing, it will still be 10pt as it is created at 10pt. Is there a way to read the default font size, so that we may know the user prefers 8pt, and be able to programmatically set our shapes to 8pt? Thanks in advance.

Surrogate

#1
Are you want change all font size in same shapes dropped from some stencil ?

if "yes" look at my animation


stugol

Thanks surrogate for the very impressive animation. Unfortunately they are not from the same Master, if it is, then we could change the master on the document stencil and we would be done. We have a list of masters and we do not know which one the user will drop. When dropped, we have an event which we could add codes to change the font size, if only we could access what the current font size is set to. Thanks a million for your reply.

Hey Ken

Stugol:

   I ran into the same issue a while back, and I now use the solution on all my Visio drawings.  It involves three parts:

1. Create a user-defined variable on the document shape sheet, call it TheDoc!User.FontSize.  Using the Document Opened event, I create the cell if it doesn't already exist and set it to some default font size.  If you want to avoid VBA entirely, you can just create the cell manually.

2. Next, for each master on my stencil, I added the following to the EventDrop cell on its shapesheet: SETF(GetRef(Char.Size),"=TheDoc!User.FontSize").  So on drop, the shape automatically points to, and takes on, whatever default font size you chose for your document. 

3. Finally, to make it easy for the users to change the font size, I put a "hot" shape on my change log page that's dynamically connected to TheDoc!User.FontSize such that whatever font size you choose for the hot shape is also placed in TheDoc!User.FontSize.  The way you do that is to add the following to the hot shape's TheText event: SETF(GetRef(TheDoc!User.FontSize),Char.Size).

   Bottom line: Every shape dropped uses the document default font size, and the user can change the default to suit themselves.

   You can also extend that, as I have done, to use the hot shape to set the font as well.  So the EventDrop cell looks like SETF(GetRef(Char.Size),"=TheDoc!User.FontSize")&SETF(GetRef(Char.Font),"=TheDoc!User.Font"), and the hot shape's TheText cell looks like SETF(GetRef(TheDoc!User.Font),Char.Font)&SETF(GetRef(TheDoc!User.FontSize),Char.Size). 

   If necessary, you could also GUARD the master shape's EventDrop formula such that it will always use the document default. 

   If you have no control over which masters that the users will be using, you can still employ the same solution, only using VBA and the ShapeAdded event to initialize the shapesheet cells.

   Hope this helps,

   - Ken
Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

Jumpy

You could react to the changing fontsize with the Dependson-function and Callthis-function.
The macro can now ask the user, if the new fontsize shall be the new fontsize for the whole document.
If so, you could create (If not already there) a user defined cell in shapesheet of the document and place the fontsize information there.
After that the code could eventually change the fontsize of the other shapes allready on the page to the new font size if the user so desires. For that loop through all the shapes and look if it's one of your shapes and change the font-size.

The macro that starts on EventDrop of a new shape can now look wheter the cell with the font-size information in the documents shapsheet exists and change the font-size of the newly droped shape accordingly.

-------

Warning: It is possible to format a character of the text of a shape individually, so there is possibly not only "one" font-size for a given shape. What would you do in such a situation?

stugol

Hey Ken,
That's a great solution, effectively replacing the font interface on the ribbon to a shape. I am not entirely sure I want to do that, but none the less, it got me thinking, and if I come up with anything better I shall share it here. Great work still. Sincere thanks.

Jumpy:
Good questions. Essentially I've made a bunch of master shapes with love. They get dropped on a drawing and a user is saying, hey I think the font is too small on your shapes, how do I set the default font, so that whenever I drop your shapes onto a drawing it gets set to my default, so I don't have to modify them all the time. My current solution is to tell the users to drop one, change the font to whatever they require, then drop it into their own custom stencil to make a custom shape on their own. So they use their custom shape with a font they are happy about and does not require changes every time it gets dropped.

It's not so much about changing fonts and colors for the entire document, but after talking to you good people, it looks like my current solution ain't that bad at all. Thanks so much, some times talking to my peers helps greatly. Thank you and I shall see if I can do any better.

Yacine

What you are looking for belongs to the document object of your file.
document.defaulttextstyle: http://msdn.microsoft.com/de-de/library/office/ff768308.aspx
Yacine

stugol

Thanks so much Yacine. For those who do not speak German, the English page is here: http://msdn.microsoft.com/en-us/library/office/ff768308.aspx

Unfortunately I have not been able to get the font size. What is returned by ActiveDocument.DefaultTextStyle is "Normal" just a style name. I therefore wrote the below:
Dim i As Integer
For i = 1 To ActiveDocument.Styles.Count
    Debug.Print ActiveDocument.Styles(i).CellsU("Char.Size").FormulaU
Next

And all it returns are still say "6pt" where I have already set the document font size to "10pt".

This is definitely the way to go but at the moment I have run out of ideas on how to access the default font size of "10pt". Anyone? Thanks in advance.

Yacine

Try:
Debug.Print ActiveDocument.GestureFormatSheet.CellsSRC(visSectionCharacter, 0, visCharacterSize).FormulaU
Yacine

stugol

TQ Yacine. Indeed GestureFormatSheet is the property sheet to get all these things. Thanks a million.

Yacine

It was actually easy. Just remember how easy it is to record a macro to get the code you need.
Cheers, Y.
Yacine

stugol

Yup, use that all the time, but forgot about it this time. Thanks again. Cheers.