Visio Guy

Visio Discussions => Shapes & Templates => Topic started by: Jennifer on January 24, 2017, 06:56:09 AM

Title: Counting shapes
Post by: Jennifer on January 24, 2017, 06:56:09 AM
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.




Title: Re: Counting shapes
Post by: Jennifer on January 24, 2017, 07:13:22 AM
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
Title: Re: Counting shapes
Post by: 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
Title: Re: Counting shapes
Post by: Jennifer on January 24, 2017, 06:03:27 PM
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)
Title: Re: Counting shapes
Post by: Mouthpear on September 18, 2022, 12:38:02 AM
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)?
Title: Re: Counting shapes
Post by: Yacine on September 18, 2022, 10:24:16 AM
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
Title: Re: Counting shapes
Post by: hidden layer on September 20, 2022, 07:35:15 AM
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
Title: Re: Counting shapes
Post by: Surrogate on September 20, 2022, 08:16:29 AM
@hl, this trick (shapes count) works in case if page dont contain group shapes!
Title: Re: Counting shapes
Post by: wapperdude on September 21, 2022, 10:54:15 PM
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/ (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.
Title: Re: Counting shapes
Post by: Thomas Winkel on September 22, 2022, 09:02:41 AM
Nice one, never heard about legend shapes before.

Another option are shape reports: