ResizeMode

Started by elistein200, April 03, 2012, 10:15:27 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

elistein200

Hi Guys



The following code creates 4 shapes, then select them an group them.

In order to resize the group I need to change the "c" to 2.

This is no problem, when it is done for only one shape.

When it's for a group ir must be done after the select and before the group.

My problem is the code marked with XXXXXX

Private Sub CommandButton1_Click()

 
    Dim vsoShapes(1 To 4) As Visio.Shape
    Dim MyCounter As Integer

 
    For MyCounter = 1 To 4
        Set vsoShapes(MyCounter) = ActivePage.DrawRectangle(MyCounter, MyCounter + 1, MyCounter + 1, MyCounter)
    Next MyCounter
    ActiveWindow.DeselectAll

     Dim vsoSelection As Visio.Selection
     Set vsoSelection = ActiveWindow.Selection

     For MyCounter = 1 To 4
        vsoSelection.Select vsoShapes(MyCounter), visSelect
    Next MyCounter
   
    Dim vsoPage As Visio.Page
    Dim vsoShape As Visio.Shape
    Dim vsoCell As Visio.Cell
    Dim vsoSelect As Visio.Shape
   
     Set vsoPage = ActivePage

       

Set vsoCell = XXXXXXXX.CellsU("ResizeMode")
vsoCell.Formula = 2
   
 
    Dim vsoGroup As Visio.Shape
    Set vsoGroup = vsoSelection.Group
   
End Sub




JohnGoldsmith

ResizeMode only appears to be considered prior to a shape being added to a group so you just need to set this cell before hand.  You've already got a couple of loops so why not just add the cell setting statement in there.  For example:

For MyCounter = 1 To 4
    vsoShapes(MyCounter).CellsU("ResizeMode").Formula = 2
    vsoSelection.Select vsoShapes(MyCounter), visSelect
Next MyCounter


Two other observations:

1) unless you have other requirements, you shouldn't need two loops - you can use the first one to drop (draw) the shapes, set the ResizeMode cell and create your selection.  Have a look at this post I wrote the other day, which deals with the selection issue prior to grouping.

http://visualsignals.typepad.co.uk/vislog/2012/03/building-visio-shapes-with-code.html

2) do you need to set the ResizeMode cell at all?  Setting it to '2' ensures that the child shapes scale with the parent and this is actually the default behaviour.

Anyway, I hope that helps, but let me know if I've not understood the problem correctly.

Best regards

John

PS for anyone who interested here's the docs for the ResizeMode cell: http://msdn.microsoft.com/en-us/library/ff766230.aspx
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

elistein200

Dear Mr Goldsmith

Thank you for your fast and comprehensive reply. Ofcourse the 2 loops were for test purposes only.

This code is just a Case Study for a code which involves up to 30 different shapes which I need to

shrink or enlarge as a block, that's why I need to group them.

Now my code looks like this:

Private Sub CommandButton1_Click()

 
    Dim vsoShapes(1 To 4) As Visio.Shape
    Dim vsoSelection As Visio.Selection
    Dim MyCounter As Integer
    Dim vsoGroup As Visio.Shape
 
    Set vsoSelection = ActiveWindow.Selection
 
    For MyCounter = 1 To 4
           Set vsoShapes(MyCounter) = ActivePage.DrawRectangle(MyCounter, MyCounter + 1, MyCounter + 1, MyCounter)
           vsoShapes(MyCounter).CellsU("ResizeMode").Formula = 2
           vsoSelection.Select vsoShapes(MyCounter), visSelect
    Next MyCounter
   
    Set vsoGroup = vsoSelection.Group
   
End Sub

Unfortunately,  before I add the last (bold) line the ResizeMode changed to 2 as desired but aftert he group
it  changed to 0 again.

Now I need to study carefully your  post regarding the resizing issue, but as we are just a few days before the Jewish Passover I'll be very busy with the preparations, so immediately after the Seder I'll go into it.

Thank you very much and wishing you a Happy Holiday.

Eli Stein

elistein200

Hi Guys

Finaly resolved this problem. as Mr Goldsmith mentioned there is no need for ResizeMode.

The code is:

Set vsoSelection = ActiveWindow.Selection

For x = 1 To 4

  Set vsoShapes(x) = ActivePage.DrawLine(Bx(x), By(x), Ex(x), Ey(x))
  vsoSelection.Select vsoShapes(x), visSelect

Next x
   
        Set vsoGroup = vsoSelection.Group
       
        vsoGroup = vsoGroup.CellsU("Height").ResultIU
        OrgHeight = vsoGroup
         
End Sub

The I used this line to enlarge by 10%

   vsoGroup.CellsU("Height") = OrgHeight * 1.1

Special thanks to Mr Goldsmith