What is the most elegant/fastest way to get all Masters used in a page

Started by Visisthebest, January 29, 2022, 11:20:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Paul Herber

Of course, I have such a feature in my Visio Utilities!
https://www.paulherber.co.uk/visio-utilities/
ribbon
SuperUtils -> Page -> Count Shapes on Page
or
SuperUtils -> Document -> Count Shapes in Document

Time to count ~ 10000 shapes - about 0.5s
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Yacine

@Paul, does your routine loop over the shapes or does it use another clever way?
Yacine

Paul Herber

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

wapperdude

For those unfamiliar with the legendary Legend shape, see attached.

Initially, a shape may be "registered" by merely dragging it onto the Legend, and agree to "terms".  Then move it off the Legend.  Subsequently, duplication will increment the count, deleting will reeduce the count.  If the shape is completely deleted, it is de-registered and removed from the Legend.  Perhaps not the handiest "tool" in the ol' shed.
Visio 2019 Pro

Surrogate

Quote from: Surrogate on January 29, 2022, 02:08:45 PMfastest way without code.
Not totally without code, but without iteration all shapes at page!
This code iterate Legend shape's sub-shapes at active page and create its output.
Sub ttt()
Dim lgnd As Shape, SUBSH_COUNT As Integer, n2 As Integer, n3 As Integer
Set lgnd = ActivePage.Shapes("LEGEND")
SUBSH_COUNT = (lgnd.Shapes.Count - 4) / 3
For i = 1 To SUBSH_COUNT
n3 = 3 * i ' Inner shape number from 3rd column
n2 = 3 * i - 1 ' Inner shape number from 2nd column
Debug.Print lgnd.Shapes(n3).Text, lgnd.Shapes(n2).Text
Next
End Sub

QuoteRectangle     1
Square        1
Circle        3
Diamond       1
Drop          7
Chevron       1
Master.17     5
Pentagon      1
Cube          1

Croc

I tried creating a list of masters on pages using Power Query. At first glance it works fine.
Excel gets this list from the Visio package file.
I am not an expert in Power Query, so the solution may seem ridiculous. Made it just for testing.
I am attaching the file with queries.
The name of the Visio file must be set on the Path sheet.
See the result after the refresh on the MastersOnPages sheet.


Yacine

@Croc, awesome!
Not that much for this particular task, but doing "surgery" on an office file with powerquery opens a whole world of possibilities.
Yacine

wapperdude

Oh no! :P. Now I have to discover Power Query.  :o. Help!  Boat is taking on water.   ;)
Visio 2019 Pro

Croc

Yes, it's a good tool. But unfortunately, in addition to knowledge of Visio, it also requires knowledge of the relationships between elements in the Visio package file. And these relationships may not be very simple.
In particular, for the list of masters, it was necessary to form requests to three different files, and then merge the results together.
By the way, a special utility can be useful for studying the components of a Visio drawing in package format. (At the end of the article https://visioport.ru/blog/index.php/32-visio-package-helper there is a link to its installer).

wapperdude

Package format... feels like Quantum Mechanics.  I'm more of a Classical based guy.  Long live Sir Isaac Newton!  Where'd that apple get off to?
Visio 2019 Pro

Visisthebest

Thanks everyone for all the ideas, probably will brute-force loop through all the shapes on a page as an initial solution then see if there are some simpler optimizations possible.

The legend shape is a fascinating option, and very useful by itself.

I am still grappling with the behavior of Master shapes a bit, I understand they are timestamped in the stencil. If I don't change a master, and the same stencil is used, will there never appear a second master of the same shape in the document stencil or are there some exceptions to this? If I can count on there only being one Master of a shape given these conditions (same stencil of the same date, Master never changed) that would be very useful to know as well.
Visio 2021 Professional

Paul Herber

No timestamping (as far as I know), and Visio will always use the copy of the master if it is available. But, if there is any change made to the master, then adding a new instance from the stencil will create a new master, not use the modified one.
So, if you drop 3 Rectangle shapes from the Basic Shapes stencil on to the page, there will be one Master called Rectangle in the masters collection. If you now edit that master in any way then it is not the same shape that you originally dropped on the page. If you now drop a new Rectangle from the Basic Shapes stencil then it will create a new master called Rectangle.1 or similar.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Visisthebest

Thank you Paul good to know, that is the behavior I expected.

For updating shapes (with other formulas in some cells), I am still considering whether to update the document stencil master or just change the shapes themselves. (Sometimes that means about 500 shape updates, but this doesn't happen regularly).

I wonder how much performance gain updating via the Master provides (so the shapes are updated via the master the inherit) when 500 shapes are updated (typically an update is to about 10 simple formulas per shape, and I bundle the updates cross the interop in one SetFormulas per shape).

The file being a bit larger is not really a concern but performance is if it is a big difference.

https://docs.microsoft.com/en-us/office/vba/api/visio.shape.setformulas
Visio 2021 Professional