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.

Visisthebest

In a multi-page document where different (versions of) stencils are used on different pages, I would like to filter out just the set of Masters that are used on a single page.

Because the Page doesn't have a Masters collection itself:
https://docs.microsoft.com/en-us/office/vba/api/visio.page

and pages may contain 1000-2000 shapes, probably going through all the shapes to find all the masters is not very efficient.

What is the most elegant way to quickly retrieve all the Masters used on a single page? Thank you for sharing your insights!
Visio 2021 Professional

Yacine

Interesting question, I would have looped.
up to 2000 iterations should be fast enough for regular checks, only when it comes to repeating the operation over an over, a more efficient solution would make sense.
Looking forward to what this thread comes up.
Yacine

Visisthebest

Yacine yes, because a user can drop another shape with another master on the page at any time, I simply have to recheck as the set of Masters on that page may have changed since last time. So that can become quite CPU-intensive, especially in an add-in that has to go 2000 times across the COM interop (which is slooooooooow).

Visio 2021 Professional

Surrogate

Not elegant, but fastest way without code.
Quote from: David J Parker in article More secrets of the Visio Legend shapewas going to do a full post on the special Legend shape in Visio that can automatically count instances of masters on a page, then I found that my good friend Chris Roth, aka VisGuy, had done one some years ago ( see visguy.com/.../legend-shapes).

Visisthebest

Very interesting possibility Surrogate thank you, to check out how they Legend shape does this, in Chris' article he mentions:

- The Legend shape helper add-on

Is there a special add-on running in the background for this? (Ideally this is just using the shapesheet no code, which would be even better just didn't realize it was possible!)
Visio 2021 Professional

wapperdude

The looping process might be improved in a couple ways...
1) create an index, aka, a list of known masters for each page.
2) use an event that triggers when a shape is dropped.  Compare to existing list of known masters for page in question.

Note, it's been awhile (years), but this might be what legend shape does.  The legend is an actual shape and requires being added to each page.  Do you need some sort of reprort?  I'd presume so.  Not sure if Legend, as exists, accommodates that.  Just don't recall at the moment.
Visio 2019 Pro

Yacine

Quote from: Visisthebest on January 29, 2022, 02:04:59 PM
... especially in an add-in that has to go 2000 times across the COM interop (which is slooooooooow).

my very first thoughts on this:
Check the bottle neck and transpose the heavy lifting operations to visio. several thousand loops are not a deal nowadays. Having different applications deal with individual checks may however take muuuuch longer.
Invistigate the possibilities of (1) "call MacroName" and (2) of "getresults"
Yacine

Yacine

@ Wayne,
I did also play with the idea, since Visio is already doing this with other "entities" like Connections (where it doesn't check for whether shapes are connected, but stores the data in a separate object, namely "connections").
The difficulty resides in catching "every" so little event that may happen to the collection - creation, editing, replacement, deletion, ... whatever!
     .... probably feasible, but definitely tedious!


PS: also, where to store the result? In the document's shapesheet? maybe.
Yacine

Paul Herber

The Legend shape, not easy to find, does activate an addon, called "lgnd", you can find the activation in the Legend shape's Event Drop cell:
=RUNADDONWARGS("lgnd","/cmd=cmd1")
Electronic and Electrical engineering, business and software stencils for Visio -

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

Visisthebest

Thank you Yacine and Paul, yes maybe some highly optimized code. Good to know the legend uses an addon!
Visio 2021 Professional

wapperdude

@Yacine, et all,
"Tedius":  isn't that what code is for???   :o;D.

Yeah, catching right event might be a challenge.  Perhaps, the Indexing also includes some sort of master count per page.   Then, when doc closes, an update is performed.  Perhaps this is only time, rather than the immediate, event propelled technique???  Perhaps the events merely identifies a page to be re-indexed? His might minimize the amount of looping.

Also, what if a shape has no "master", then what?

WRT to storage...
1) Could be Doc shapesheet.
2) could be each page shapesheet. This might accommodate, restricted looping.  That is, if there's a " page changed" event, then that page is updated???
3) external, as a backup???, to database type thing?

Visio 2019 Pro

Paul Herber

The Legend shape only counts certain types of shape, I'm not at all sure what the criterion is. Sorry, let me re-phrase that - I have absolutely no idea what the criterion is.

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

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

Paul Herber

Correction to the above - the Legend shape only counts shapes which contain the cell User.visLegendShape when the shape is dropped on the page or the shape is duplicated.
Grouping and ungrouping can confuse it though.
Electronic and Electrical engineering, business and software stencils for Visio -

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

wapperdude

Ah!  What about CONTAINERS!?!

Each page could have one, full page encompassing container.  There are some shape sheet container related functions.  Well, OK, only half serious about this.
Visio 2019 Pro

Yacine

To consider upcoming solutions one might set up a reasonable big document to compare the times.
Say 10k shapes? More? A mix of simple and master related shapes.
Check the enclosed file.
Yacine