Weird behavior attempting to create visio selection if shape is part of a group

Started by JM, April 10, 2018, 06:46:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wapperdude

QuoteNot to belabor the point, but I think I am not exactly clear in why I was trying to add the shapes to a Selection object and then (all at once) set the active selection to that selection object.

Because that's what you said you needed...
QuoteWhat I am trying to do (50k view):
I have a macro to take a shape (either from a right-click action menu, or from a double-click event) and create a selection (visio.selection) of the shape and all shapes it is connected to.

Belaboring is Ok.  Makes sure we're on the same page.  So, now my turn  ;)...
You start the process by selecting a shape.  Then you search thru the shapes on the page to see who's connected to it.  Presumably these are 1-D shapes, connectors or lines.  The method of searching is the connections method.  When a valid shape is discovered, you then select it.  (At this point, you have a choice:  add the shape to an array, add the shape to selection group, or wait until the end and update the selection group.  If you using an array to store the shapes, you don't need to do anything with the selections.) My understanding from the above, the connected shapes were being selected and this "group" was stored in the his Selection variable...possibly to make list or whatever.  Obviously, an array containing said shapes would also suffice. 

Hope this clarifies things.

BTW, as you undoubtedly have discovered, the connection info is in the 1D shapes, not the 2D shapes.

Wapperdude

Visio 2019 Pro

JM

Yes.. you are right..  I guess I was biased by my original thought process.. I still puzzle about why it my ActiveWindow.Selection = vsoSelection worked previously then..


wapperdude

Went back and tried the line:

ActiveWindow.Selection = vsoSelection

It does indeed work...in V2007.  But seems redundant, unless at some point the shapes are de-selected, and then need to be re-selected.

Here's my test code:

Sub shpSel()
    Dim vsoSelection As Selection
    Dim vsoShp As Shape
    Dim i As Integer
    Dim shpCnt As Integer
           
    ActiveWindow.DeselectAll                'Remove all existing selections.
    shpCnt = ActivePage.Shapes.Count
    For i = 1 To shpCnt Step 2
        Set vsoShp = ActivePage.Shapes.ItemU(i)
'Add fill color within the loop:
        vsoShp.CellsU("FillForegnd").FormulaU = "RGB(255, 255, 0)"
       
'Create a Selection collection:
        ActiveWindow.Select vsoShp, visSelect   'Adds shape to existing selection population
'        Set vsoSelection = ActiveWindow.Selection  'Build/set vsoSelecton as loop progresses
    Next
    Set vsoSelection = ActiveWindow.Selection   'Set vsoSelection after loop complete
   
    ActiveWindow.DeselectAll        'Pause this step, to 1st see existing selection
   
    ActiveWindow.Selection = vsoSelection   'This works.  The vsoSelection is restored.
       
'    For Each vsoShp In vsoSelection
'        ActiveWindow.Select vsoShp, visSelect
'        vsoShp.CellsU("LineWeight").FormulaU = "2 pt"
'    Next
         
''Alternative shape fill coloring:
'    For Each vsoShp In vsoSelection
'        vsoShp.CellsU("FillForegnd").FormulaU = "RGB(255, 255, 0)"
'    Next
       
End Sub


Wapperdude
Visio 2019 Pro