Author Topic: Count Number of Selected Shapes in the ShapeSheet  (Read 17459 times)

0 Members and 1 Guest are viewing this topic.

RhesusMinus

  • Full Member
  • ***
  • Posts: 101
Count Number of Selected Shapes in the ShapeSheet
« on: December 13, 2010, 07:52:48 AM »
Hi.

Is it possible, in the shape sheet, to count the number of selected shapes?
I have an action that should be visible only if just 1 shape is selected.

THL
« Last Edit: December 14, 2010, 04:08:07 AM by Visio Guy »

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Count Number of Selected Shapes in the ShapeSheet
« Reply #1 on: December 13, 2010, 10:22:42 AM »
Don't think so. You would have to use VBA and events to push the number of selected shapes to the shapesheet of that shape. Much work for that.

It would be more easy, to ignore the action in the VBA-Code, if there's more than one shape selected, although it would be nicer and more professional, if the action wouldn't be visible in that case, but difficult to accomplish, I think.

Don't even know, if there is a "Shape selected" event on page or doc level?
« Last Edit: December 14, 2010, 04:08:19 AM by Visio Guy »

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: Count Number of Selected Shapes in the ShapeSheet
« Reply #2 on: December 13, 2010, 10:56:20 AM »
« Last Edit: December 14, 2010, 04:08:26 AM by Visio Guy »

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Count Number of Selected Shapes in the ShapeSheet
« Reply #3 on: December 13, 2010, 04:33:29 PM »
OK. It's good to know your object model, like Rhesus said in the other thread.
In that case, this will work:

Code
Dim WithEvents win As Visio.Window

Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
  Set win = Application.ActiveWindow
End Sub

Sub StartManually()
  Set win = Application.ActiveWindow
End Sub

Private Sub win_SelectionChanged(ByVal Window As IVWindow)
  If win.Selection.Count <> 1 Then
    MsgBox "not 1 selected"
    'Or Yourshapes.Action.Visible = false
  Else
    MsgBox "only 1 selected"
    'Or Yourshapes.Action.Visible = true
  End If
End Sub


Less work than I thought.
« Last Edit: December 14, 2010, 04:08:35 AM by Visio Guy »

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1737
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Count Number of Selected Shapes in the ShapeSheet
« Reply #4 on: December 13, 2010, 06:02:05 PM »
You can't get selection info in the ShapeSheet because the ShapeSheet is behind a shape, and hence behind the "model", where a window is a "view" into the model.

In Visio, you can have several windows for the same page. A shape might be selected in one of them, but not in the others. If your shape could react to being selected, it would end up turning on visibility in the other windows anyway...or maybe the universe might just implode instead.

Anyway, maybe this helps to understand why Visio doesn't offer the capability.
« Last Edit: December 14, 2010, 04:08:42 AM by Visio Guy »
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

aledlund

  • Hero Member
  • *****
  • Posts: 1412
Re: Count Number of Selected Shapes in the ShapeSheet
« Reply #5 on: December 13, 2010, 06:34:02 PM »
mobius strip application model
 ;D
al
« Last Edit: December 14, 2010, 04:08:50 AM by Visio Guy »

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1737
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Count Number of Selected Shapes in the ShapeSheet
« Reply #6 on: December 13, 2010, 07:06:58 PM »
...running on the Palindrome OS.
« Last Edit: December 14, 2010, 04:09:00 AM by Visio Guy »
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Count Number of Selected Shapes in the ShapeSheet
« Reply #7 on: December 14, 2010, 02:39:32 AM »
Thats could be a feat for quantum computing, so it ever comes.
In quantum land a shape could be selected and not selected, could be visible and not visible all at the same time.
It could be in different windows with different probabilities.
Or it is in all the windows at once, as long as you don't look at them.
Think of the possibilities: You could draw a shape, while in another window it's already drawn. Funtastic.

--------------

Back to my code above. It only works, when you use only one drawing window and the code monitors that.
I don't know, if it is possible to detect, if the active window changes and then to test if it is an drawing window and to than reference that window to the withevents variable.
« Last Edit: December 14, 2010, 04:09:45 AM by Visio Guy »

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1737
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Count Number of Selected Shapes in the ShapeSheet
« Reply #8 on: December 14, 2010, 04:07:38 AM »
Hey, it's bad enough that when I'm on the ICE, all my shapes shrink and turn a little bit blue!
« Last Edit: December 14, 2010, 04:09:21 AM by Visio Guy »
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1737
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Count Number of Selected Shapes in the ShapeSheet
« Reply #9 on: December 14, 2010, 04:28:40 AM »
Below is a modified version of Jumpys code that tracks when the active window changes. The code now detects changes to the selection in any active window. So you can have multiple windows open and it still works.

Code
Dim WithEvents m_win As Visio.Window
Dim WithEvents m_app As Visio.Application

Sub StartManually()
  m_setEventObjects
End Sub
Private Sub Document_RunModeEntered(ByVal Doc As IVDocument)
  '// Toggle the run-mode triangle off, then on to set up events.
  m_setEventObjects
End Sub
Private Sub Document_DocumentOpened(ByVal Doc As IVDocument)
  m_setEventObjects
End Sub

Private Sub m_setEventObjects()
  '// Set the application:
  Set m_app = Visio.Application
  '// Set the event-tracking window object:
  Set m_win = Visio.Application.ActiveWindow
End Sub

Private Sub m_app_WindowActivated(ByVal Window As IVWindow)

  '// When a new window is activated, we reset m_win to
  '// that window...if it is a drawing window that can
  '// have selected shapes. Otherwise, we set it to nothing.
 
  If Window.Type = Visio.VisWinTypes.visDrawing Then
    Set m_win = Window
  Else
    '// ShapeSheet or stencil window or other non-drawing window:
    Set m_win = Nothing
  End If
 
End Sub

Private Sub m_win_SelectionChanged(ByVal win As IVWindow)

  MsgBox win.Selection.Count & " selected shapes!"

End Sub

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Count Number of Selected Shapes in the ShapeSheet
« Reply #10 on: December 14, 2010, 06:56:43 AM »
Nice to see, that I had the right idea and that I'm not such a big "Diletant" as I thought.

Where "Diletant" means sth. like nonproffesional looser and has nothing to do with the effects of nearly the same name, that Chris obviously expirienced in our german lightspeed train that is so fast, that you normaly spend more time at the station waiting for it, than actually travelling with it.
It's generally a marvelous multifunctional train, that in winter can be used as refrigerator and in summer is used as sauna by poor Finns, who can't afford one of their own.
« Last Edit: December 14, 2010, 07:02:36 AM by Jumpy »