Selecting all shape instances from the same master

Started by Gustavo, May 08, 2018, 03:14:29 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Gustavo

Hi all. I'm trying to build a macro to select all shapes instances from the same master, adjusting some code from an old post, but I'm stuck with the sub:


Sub SelectInstancesFromMaster()                         'Select A Shape
Dim vsShp As Visio.Shape
Dim vsoInstSelection As Shape
Dim vsoShpSelection As Selection

For Each vsShp In ActivePage.Shapes                           ' iterate throught the shapes on active page.
            If vsShp.Master.Name = "Mastername" Then     ' check for desired master instance
                Set vsoInstSelection = vsShp
                ActivePage.Select vsoInstSelection, visSelect                   'Add to selection
            End If
      Next
End Sub


I got an error on the vsShp.Master... line. Can you give me an advice on this?  Best regards.

Surrogate

Hi, Gustavo!

Not all shapes based on master shapes! Shapes which was draw with drawing tools on ribbon such as lines, rectangles or rings have not masters.

Thomas Winkel

Hi,

we have something like this in our project:

Sub selectSameShapes()
    Dim shpMaster As Visio.Master
    Dim shp As Visio.Shape
    Dim sel As Visio.Selection
   
    If ActiveWindow.Selection.Count = 0 Then Exit Sub
   
    Set shpMaster = ActiveWindow.Selection.PrimaryItem.Master
    If shpMaster Is Nothing Then Exit Sub
   
    Set sel = Visio.ActivePage.CreateSelection(Visio.VisSelectionTypes.visSelTypeEmpty)
   
    For Each shp In ActivePage.Shapes
        If Not shp.Master Is Nothing Then
            If shp.Master = shpMaster Then
                sel.Select shp, Visio.VisSelectArgs.visSelect
            End If
        End If
    Next shp
   
    ActiveWindow.Selection = sel
End Sub


Hope that helps.
Thomas

vojo

why not play with the shape in the document stencil.  Any change there will affect all uses of that shape for this given instance.
e.g. if you have 100 of the same shape dropped over 10 pages in this particular drawing, update doc stencil master of this shape and all 100 instances get updated automatically.

Note, there is no way to change a stencil shape and have it propagate to all prior uses in drawings
Only future uses of the stencil shape will have the change.