Author Topic: Address all connectors and bring them to the foreground  (Read 109 times)

0 Members and 1 Guest are viewing this topic.

elamigo

  • Newbie
  • *
  • Posts: 2
Address all connectors and bring them to the foreground
« on: April 06, 2020, 09:01:52 AM »
Hello, everyone,

I am looking for a macro with which I can get all connectors directly into the foreground. Online I found the following code, but it did not help:

   
Code
Sub SendConnectorsToBack_ByLayer()
     
        // Get the active page:
        Dim pg As Visio.Page
        Set pg = Visio.ActivePage
     
        // Get the connectors layer:
        // Note, ItemU should work for non-English Visio
        Dim lyr As Visio.Layer
        Set lyr = pg.Layers.ItemU("Connector")
     
        // Get a selection of connectors, by layer:
        Dim sel As Visio.Selection
        Set sel = pg.CreateSelection( _
        visSelTypeByLayer, visSelModeSkipSub, lyr)
     
        // Send the selection to back:
        If (sel.Count > 0) Then
            Call sel.SendToBack
        End If
End Sub


Trying to select over all connectors and then bring them to the foreground and record them does not help:


   
Code
Sub Macro8()

        'Enable diagram services
        Dim DiagramServices As Integer
        DiagramServices = ActiveDocument.DiagramServicesEnabled
        ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

        ActiveWindow.DeselectAll
        ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(614), visSelect
        ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(615), visSelect
        Application.ActiveWindow.Selection.BringToFront

        'Restore diagram services
        ActiveDocument.DiagramServicesEnabled = DiagramServices
End Sub


With this version the problem remains that the individual shapes are addressed via ItemID. Unfortunately this changes frequently

cheers ty
« Last Edit: April 06, 2020, 09:27:25 AM by elamigo »

OldSchool1948

  • Jr. Member
  • **
  • Posts: 60
Re: Address all connectors and bring them to the foreground
« Reply #1 on: May 15, 2020, 06:41:40 PM »
I haven't tested this, but try something like this:
Code
Sub BringConnectorsToFront_ByLayer()
     
    '// Get the active page:
    Dim vsoPage As Visio.Page
    Set vsoPage = Visio.ActivePage
   
    '// Get the connectors layer:
    '// Note, ItemU should work for non-English Visio
    Dim vsoLayer As Visio.Layer
    Set vsoLayer = vsoPage.Layers.ItemU("Connector")
   
    '// Get a selection of connectors, by layer:
    Dim vsoSelection As Visio.Selection
    Set vsoSelection = vsoPage.CreateSelection( _
            visSelTypeByLayer, visSelModeSkipSub, vsoLayer)
   
    Dim i As Integer
    For i = 1 To vsoSelection.Count
   
        Dim vsoShape As Visio.Shape
        Set vsoShape = vsoSelection(i)
       
        Call vsoShape.bringToFront
   
    Next i
   
End Sub

This code assumes your connector's use Visio's default "Connector" layer


wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3746
  • Ideas Visio-lized into solutions
Re: Address all connectors and bring them to the foreground
« Reply #2 on: May 23, 2020, 05:40:15 PM »
Using the macro recorder and stripping out the non-essential lines:
Code
Sub Macro1()
    Dim vsoSelection1 As Visio.Selection
    Dim shp As Visio.Shape
   
    Set vsoSelection1 = ActiveWindow.Page.CreateSelection(visSelTypeByLayer, visSelModeSkipSuper, "Connector")
    ActiveWindow.Selection = vsoSelection1
   
    ActiveWindow.Selection.BringToFront
   
    For Each shp In vsoSelection1                                      'Do whatever you need within the For ... Next block.  Example colors lines blue and makes them thicker.
        shp.CellsU("LineColor").FormulaU = "RGB(0,0,255)"
        shp.CellsU("LineWeight").FormulaU = "3 pt"
    Next
End Sub

Visio 2019 Pro