Re-iterative script to group objects

Started by ssun, August 18, 2011, 06:23:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ssun

Hi, guys and gals,

Apologies if this is a basic question.  I've cobbled together a script from a bunch of searches that will group the shapes on a page.  The page has a number of shapes such as Name1, Name2, Name3, etc, Duration1, Duration2, Duration3, etc., Resource1, Resource2, Resource3, etc.

The script enumerates the number of shapes on the page and divides by three.  It then loops through the shapes, grouping Name1, Duration1 and Resource1 together, Name2, Duration2 and Resource2 together, using the For Next variable to id the appropriate shapes.

The problem I'm having is that when the script is finished, all shapes are grouped into one big group. 

How do I tell it to choose a new group?

Here's the code.  My apologies and thanks if you recognize your code...

Public Sub GroupAll()
     'This routine will create a text file of the location and size of all 2-d shapes
     ' on the current page
    Dim shpObj     As Visio.Shape, celObj As Visio.Cell
    Dim ShpNo      As Integer, Tabchr     As String, localCent As Double
    Dim LocationX  As String, LocationY   As String
    Dim ShapeWidth As String, ShapeHeight As String
    Dim shp1 As Visio.Shape, shp2 As Visio.Shape, shp3 As Visio.Shape, shpGroup As Visio.Shape
Dim sel As Visio.Selection

Set sel = Visio.ActivePage.CreateSelection(visSelTypeEmpty)


     'Loop Shapes collection
    For ShpNo = 1 To Int(Visio.ActivePage.Shapes.count / 3)
Visio.ActiveWindow.DeselectAll

Set shp1 = Visio.ActivePage.Shapes("Name" & Str(ShpNo))
Set shp2 = Visio.ActivePage.Shapes("Duration" & Str(ShpNo))
Set shp3 = Visio.ActivePage.Shapes("Resource" & Str(ShpNo))

'// Select the  shapes:
Call sel.Select(shp1, Visio.VisSelectArgs.visSelect)
Call sel.Select(shp2, Visio.VisSelectArgs.visSelect)
Call sel.Select(shp3, Visio.VisSelectArgs.visSelect)

'// Group the selection:
Set shpGroup = sel.Group
shpGroup.Name = "Group" & Str(ShpNo)
         
    Next ShpNo

     
     'Clean Up
    Set celObj = Nothing
    Set shpObj = Nothing
End Sub

aledlund

Just a superficial reading of the 'script' that you've created, the selections that you're building inside your loop are being applied to a selection that is outside your group 'sel'. Since there is only one of those your output would appear to be acting normally.
al

ssun

Ah, so I should move the

Set sel = Visio.ActivePage.CreateSelection(visSelTypeEmpty)

line into the loop? Makes sense.

THanks!

ssun

That did the trick. Thanks, much!!

I probably should have tested and did one reply....

Spencer