Author Topic: Counting shapes  (Read 5850 times)

0 Members and 1 Guest are viewing this topic.

Jennifer

  • Hero Member
  • *****
  • Posts: 517
Counting shapes
« on: January 24, 2017, 01: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.




Using Visio 2019, part of Office 365 on Windows 10

Jennifer

  • Hero Member
  • *****
  • Posts: 517
Re: Counting shapes
« Reply #1 on: January 24, 2017, 02: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
Using Visio 2019, part of Office 365 on Windows 10

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4449
  • Ideas Visio-lized into solutions
Re: Counting shapes
« Reply #2 on: January 24, 2017, 11:49:13 AM »
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

  • Hero Member
  • *****
  • Posts: 517
Re: Counting shapes
« Reply #3 on: January 24, 2017, 01: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)
Using Visio 2019, part of Office 365 on Windows 10

Mouthpear

  • Jr. Member
  • **
  • Posts: 13
Re: Counting shapes
« Reply #4 on: September 17, 2022, 07:38:02 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

  • Hero Member
  • *****
  • Posts: 2991
Re: Counting shapes
« Reply #5 on: September 18, 2022, 05: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
Yacine

hidden layer

  • Full Member
  • ***
  • Posts: 88
Re: Counting shapes
« Reply #6 on: September 20, 2022, 02: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

Surrogate

  • Hero Member
  • *****
  • Posts: 1630
    • ShapeSheet™ Knowledge Base
Re: Counting shapes
« Reply #7 on: September 20, 2022, 03:16:29 AM »
@hl, this trick (shapes count) works in case if page dont contain group shapes!

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4449
  • Ideas Visio-lized into solutions
Re: Counting shapes
« Reply #8 on: September 21, 2022, 05: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/

Note, I created a layer for just the Legend shape so that its visibility can toggled on/off.  Functionally, this is not needed.
« Last Edit: September 21, 2022, 06:07:33 PM by wapperdude »
Visio 2019 Pro

Thomas Winkel

  • Full Member
  • ***
  • Posts: 239
Re: Counting shapes
« Reply #9 on: September 22, 2022, 04:02:41 AM »
Nice one, never heard about legend shapes before.

Another option are shape reports: