0

I cannot get the information of the method SpartialNeighbors out of a "Package (expanded)" shape.

Normally I use this code:

 Dim s As Shape, vsoShapeOnPage As Shape
 Dim vsoReturnedSelection As Visio.Selection  

 's contains the current shape
 Set vsoReturnedSelection = s.SpatialNeighbors(visSpatialContain, 0, visSpatialIncludeContainerShapes)
        If vsoReturnedSelection.Count = 0 Then
            'No Shapes contained
        Else
            For Each vsoShapeOnPage In vsoReturnedSelection
               'Code
            Next
        End If

And this works perfectly fine for shapes like in the default UML stencil (nameU = "Overview")

I know I could group the shapes, but it increases the effort.

Another point, when I analyse other shapes I see with "MemberOfContainers" that the shape is contained in "Package (expanded)". So it must be possible to get the information from the other way around without going through all shapes.

Here you can see the "Package" and shapes of "interface" Extract of the diagram

Philipp Mochine
  • 4,351
  • 10
  • 36
  • 68

1 Answers1

1

If a shape is a container, it's ContainerProperties property will be populated (ie not null). You can then interogate that to retrieve an array of member shape IDs.

The following is a slightly adapted version of some sample code found in the SDK download - based on a document looking like this:

Visio Container Shapes

You can get hold of the member shapes like this:

Sub CheckMyPackageContainer()
    'Assumes container is selected shape in active drawing window
    Call ReportContainerShape(ActiveWindow.Selection.PrimaryItem)
End Sub


Sub ReportContainerShape(ByRef contShp As Visio.Shape)
    If Not contShp Is Nothing Then
        Dim containerProps As ContainerProperties
        Set containerProps = contShp.ContainerProperties
        If Not containerProps Is Nothing Then
            Dim lngContainerMembers() As Long
            lngContainerMembers = containerProps.GetMemberShapes(Visio.VisContainerFlags.visContainerFlagsDefault)

            Dim hostingPage As Visio.Page
            Set hostingPage = contShp.ContainingPage
            For Each varMember In lngContainerMembers
                Dim shpItem As Visio.Shape
                Set shpItem = hostingPage.Shapes.ItemFromID(varMember)
                Debug.Print shpItem.NameU, "Text = " & shpItem.Text
            Next
        End If
    End If
End Sub

This will result in the following output (noting that 'InterfaceThree' is not included):

Interface     Text = InterfaceOne
Interface.30  Text = InterfaceTwo
JohnGoldsmith
  • 2,638
  • 14
  • 26