News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Counting shapes

Started by Jennifer, January 24, 2017, 06:56:09 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jennifer

I need to count the number of shapes on a page. The number will run into the hundreds or thousands. Searching for a solution turned up macros.

https://msdn.microsoft.com/en-us/library/office/ff767099.aspx
http://visguy.com/vgforum/index.php?topic=2330.0
http://stackoverflow.com/questions/31402578/vba-counting-shapes-in-visio

Is this the only/best way to do this? I'm not opposed to using a macro, but I'd prefer a non-macro solution so I don't have to hassle with all the macro-enabled security stuff.




Using Visio 2019, part of Office 365 on Windows 10

Jennifer

Nevermind, I found a way. If I can assign them to a layer, the layer will count them for me.

Sorry for the trouble.  :P
Using Visio 2019, part of Office 365 on Windows 10

wapperdude

That's a good, not so obvious method.  You could add a macro and grab the layer count value if you want to use it.   ;D:o>:(

Wapperdude
Visio 2019 Pro

Jennifer

The layer solution is good in several ways. In addition to being simple and not requiring a macro, I can get a quick as easy summary of the counts in all of the layers with a single click. (I have the layer icons on the Quick Access Toolbar.)

My current need involves a grid that can get as large as 100x100. The fill in each individual cell is set to one of several colors. I need to get a count of the number of cells of each color. The colors are in patches. So I can define a layer for each color and set them all to "not visible". Then using the lasso tool, which I just learned how to use on another thread, I can grab a patch near the edge of the grid. As I assign those cells to their layer, they disappear from view and I can then grab the next outermost patch. I was able to get an accurate count in just a few minutes.

Sometimes actually work well!  :)  :D  ;D  8)
Using Visio 2019, part of Office 365 on Windows 10

Mouthpear

Quote from: wapperdude on January 24, 2017, 04:49:13 PM
That's a good, not so obvious method.  You could add a macro and grab the layer count value if you want to use it.   ;D:o>:(

Wapperdude

What code would you suggest to count all the objects(shapes and connectors) in a layer(variable)?

Yacine

I'm sure Wapperdude meant his comment as joke, but Jennifer's method adds a higher level of flexibility by providing to the possibility to count sets of shapes, instead of their totality.
So why not follow her path.

The way to go is to create first an appropriate  selection, then get its shapes number by the "count" property.
https://learn.microsoft.com/en-us/office/vba/api/visio.page.createselection
Yacine

hidden layer

Hi,
let the layer count their shapes is very simple and comfortable. I'm sure that wasn't a joke at all.
Sometimes I use the color of some shapes to assign them to layers "automatically".
In shapesheet's cell 'Layer Membership' you can insert a formula with if-statements that looks into shapesheet's cell 'Fill Foreground' which contains the RGB-value. Take RED() as variant and layers will be assigned and will be counted.

(!) Make sure that the RED-value is always different ;) what I use with 'last used colors' in color-palette.

hl

Surrogate

@hl, this trick (shapes count) works in case if page dont contain group shapes!

wapperdude

#8
There is another mechanism to count shapes, accurately, without using a macro.  Again, this approach only displays the count, as does the layers approach.  This oft overlooked method is the Legend shape.  See attached.  Note the count differences with the Layer report.

For a quite thorough discussion of the Legend shape and how to use it, see Visio Guy's post: 
http://www.visguy.com/2006/11/20/legend-shapes/

Note, I created a layer for just the Legend shape so that its visibility can toggled on/off.  Functionally, this is not needed.
Visio 2019 Pro

Thomas Winkel

Nice one, never heard about legend shapes before.

Another option are shape reports:

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 334 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1234KB.
Tokens: post-login.
Cache hits: 13: 0.00128s for 26,766 bytes (show)
Cache misses: 2: (show)
Queries used: 16.

[Show Queries]