Ways to check shape visibility?

M

Mac

What's the best (fastest, simplest) way to get visible shapes currently on
page? I have groups of shapes which are in different layers and only some of
them are switched visible at once. As ActivePage gives me all the shapes that
are there (but I don't care about those that I cannot see at the moment),
what I do is - get all those shapes (which are groups), check each group's
Shapes collection and for each shape from the collection check it's Layer. If
it's visible I add that shape to a visibile-shapes collection. You see, this
is nightmare! There must be a simpler way to determine what's visible on a
page!
 
M

Mac

The point is - does ActiveWindow.SelectAll select only 'visible' objects? If
not, if it returns 'invisible' objects as well, 'then it won't help me much.
Is there a way to simply get what's visible only, without having to drill
down to the layer properties?
 
D

David Parker

Hmmm .. if a grouped shape has the group layer invisible, but sub-shapes are
on a visible layer, then you can see them, but they won't be selected.

Truth is, Visio layers provide great flexibility, and complexity.
 
D

David Parker

This macro will print out the shapes without layers, shapes on visible
layers, and the visble shapes in groups on invisible layers.
You decide if it helps!

Public Sub CountVisibleShapes()
Dim lyr As Visio.Layer
Dim lyrSub As Visio.Layer
Dim sel As Visio.Selection
Dim selSub As Visio.Selection
Dim shp As Visio.Shape
Dim shpSub As Visio.Shape

Debug.Print "Shapes without layers"
For Each shp In Visio.ActivePage.Shapes
If shp.LayerCount = 0 Then
Debug.Print , , shp.Name
End If
Next

Debug.Print "Shapes on visible layers"
For Each lyr In Visio.ActivePage.Layers
If lyr.CellsC(Visio.visLayerVisible) <> 0 Then
'Look for shapes on page visible layers
Set sel = Visio.ActivePage.CreateSelection(visSelTypeByLayer,
Visio.VisSelectMode.visSelModeSkipSuper, lyr)
If sel.Count > 0 Then
Debug.Print , lyr.Name, sel.Count
For Each shp In sel
Debug.Print , , shp.Name
Next
End If
End If
Next lyr

Debug.Print "Visible Shapes in group shapes on invisible layers"
For Each lyr In Visio.ActivePage.Layers
If lyr.CellsC(Visio.visLayerVisible) = 0 Then
'Check shapes on hidden layers
Set sel = Visio.ActivePage.CreateSelection(visSelTypeByLayer,
Visio.VisSelectMode.visSelModeSkipSuper, lyr)
For Each shp In sel
For Each lyrSub In Visio.ActivePage.Layers
'Look for shapes on group shape visible layers
If lyrSub.CellsC(Visio.visLayerVisible) <> 0 Then
Set selSub = shp.CreateSelection(visSelTypeByLayer,
Visio.VisSelectMode.visSelModeSkipSuper, lyrSub)
If selSub.Count > 0 Then
Debug.Print , lyrSub.Name, selSub.Count
For Each shpSub In selSub
Debug.Print , , shpSub.Name
Next
End If
End If
Next lyrSub
Next
End If
Next lyr
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top