Code / Formula to represent a Group [resizing text]

Started by Brandy, May 30, 2010, 03:49:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jumpy

A little change in the start makro to change all shapes on all pages:


Sub Change_Formula(ByVal shp As Visio.Shape)
Dim douHeight As Double
Dim douCharSize As Double
Dim strFormula As String
Dim SubShape As Visio.Shape

'Change the selected shape
douHeight = shp.Cells("Height").Result("MM")
douCharSize = shp.Cells("Char.Size").Result("pt.")
strFormula = "Height/" & douHeight & " mm *" & douCharSize & " pt."

shp.Cells("Char.Size").Formula = strFormula

'Change Sub Shapes by calling this function again
For Each SubShape In shp.Shapes
Change_Formula SubShape
Next

End Sub

'--------------------------------------------------

Sub Start()
'As the name suggests, this Makro has to be started
Dim shp As Visio.Shape
Dim pg As Visio.Page

For Each pg In Application.ActiveDocument.Pages
For Each shp In pg.Shapes
  Change_Formula shp
Next
Next

End Sub

Brandy

Stencils = Shapes

My stencils represent a type of server, such as App Server, DB Server, and Web Server.  They have more than one shape within that group. 

I uploaded a sample on my first post.   See the attachment... it's just a sample..

if you can apply the code/formula to this drawing then you have accomplished what I'm looking for in Resizing Text. 

PS:  Do not "Ungroup" the drawing... Do not set individual codes/formulas for each shape within a group.  The formula must be applied to the Group.

Good Luck....

Again, thank you, thank you so much for taking time from your(you all) busy schedules to help me with my dilemma. 

Brandy

Brandy

@wapperdude, what did you do so I can repreat it on another drawing... I've been working ont he same drawing... I also tried it with one stencil/shape (Grouping) and it didn't work.

Brandy

Jumpy

Hi again,
if you copy my code in a new modul in the VBA Editor (not the ThisDocument Modul!!!) and then enable makros, you should be able to run the code.
Then in Extras-Makros you should find the Makro named Start and when you activate it, it should do as advertised:

It goes through all pages of your drawing.
Goes through all shapes (regardless if group or normal shape) and applies the formula.
If the shape is a group it further goes through all Subshapes of that group and applies the formula.
If the Subshape is a group, too, it furter... and so on.

I used it on your example file and it worked. look at the file I posted above. Hit Alt-F11 and you see in the VBA-Editor where I placed the Makro.

Jumpy

wapperdude

Hi Brandy --

What I did was take Jumpy's version of your original file.  I selected one of the subshapes in the group, opened the shapesheet and inspected the char.size cell.  It had the updated formula.  So, I reset it to default size of 18 pt, no formula.  Went thru all of the rest of the subshapes and did the same.  Then, I shrank the the group and verified that the text did not scale.  I saved this version.  Next, I ran Jumpy's code.  Again, selected the group, and shrank it.  Now the text scales with the group height.

Back to saved version.  Now I did copy paste of the group about a dozen times.  Had to increase the page size.  Added a couple of miscellaneous shapes.  Added some dynamic connectors.  Ran the macro.  All shapes had the char.size cell updated with the forumla, and all shapes exhibited text scaling.  I could not break the macro -- well, didn't try too hard.

Some definitions that need clarification:
 >>  shape = any figure --> square, triangle, line, etc.  Each has it's own shapesheet.  They can be either 1D or 2D.
 >>  Group = a collection of shapes on a drawing page.  It also has it's shapesheet.
 >>  Stencil = a special Visio page that has a collection of shapes, generally related to each thru some common theme, but not necessarily so.  These shapes are typically referred to as "Masters".

Hope this helps.

Wapperdude
Visio 2019 Pro

Brandy

Maybe it's me, it's not working....

See attachment... this is with the code that I ran.


wapperdude

Well, that's certainly a disappointing result.  Was this just a snapshot of the larger file?

Would it be possible to get a copy of what you've done so that we might be able to spot the problem?  Possibly, make a duplicate of the file, delete 90% of it, and then post the result.  I suspect there's some simple step that's missing, and the posts aren't catching it.

Wapperdude
Visio 2019 Pro

Brandy

Here you go... I know I'm doing something wrong.

It works for individual shapes, but not for groups.

Again, thank you so much

Brandy

wapperdude

Any chance of getting a Visio file?  Just a portion of the main file, but includes your efforts with macro.  In fact, a file that has the failed attempt would be good.

Wapperdude
Visio 2019 Pro

Brandy


Brandy

You will not believe this...  :D :D :D it worked on the Group-Resizing diagram I posted...

I need to delete everything I entered in the User-defined section of my original diagram and repeat the process....

I'm going to try it...


WOW!.... You(all) were so wonderful and patient with me and thank you from the bottom of my heart....

Brandy

Brandy

I created another diagram and use the VB Code and it didn't work for that one.

I dropped new shapes, grouped them and ran the code.

It didn't work for the new grouping....

Brandy

Yacine

Would ".forceformula" or ".forceformulau" instead of ".formula" help?
Yacine

Brandy

OK, I created another diagram. ???

Can someone try it on this one... I did and it doesn't work...

Any, any help is greatly appreciated.

Thanks

Brandy

Brandy

@Yacine

No, it didn't work with forceformulau

Thanks anyway

Brandy