timbmg
timbmg

Reputation: 3328

Get layer of connector

Can I get the name of the layer a connector is assigned to in vba?

I am doing this with shapes like this

ActivePage.Shapes(1).layer(1)

And now I am looking for something similar but for connectors.

Upvotes: 0

Views: 540

Answers (1)

JohnGoldsmith
JohnGoldsmith

Reputation: 2698

I'm not completely clear on your issue, but there's nothing special about connectors - they're still just shapes. So if you know the index of your target shape and layer, then you can use your code above.

Shapes in Visio can also belong to multiple layers (layers don't work in the same way as, say, Photoshop), so you might want to get the layer count first and then run through each one. For example:

Sub CheckLayers()
    Dim shp As Visio.Shape
    Dim i As Integer
    For Each shp In ActivePage.Shapes
        Debug.Print shp.NameU
        For i = 1 To shp.LayerCount
            Debug.Print "  " & shp.Layer(i).Name
        Next i
        Debug.Print ""
    Next shp
End Sub

Also, depending on what you're trying to do, you might want to take advantage of the Page.CreateSelection method to return a selection based on shapes on a particular layer. Here's a very slightly modified version from the Visio SDK:

Public Sub CreateSelection_Layer_Example()

 Dim vsoLayer As Visio.Layer
 Dim vsoSelection As Visio.Selection

 Set vsoLayer = ActivePage.Layers.ItemU("Connector")
 Set vsoSelection = ActivePage.CreateSelection(visSelTypeByLayer, visSelModeSkipSuper, vsoLayer)

 'Note that you don't have to pass the selection object to
 'the ActiveWindow Selection property - you can just work
 'with it directly if you want to
 Application.ActiveWindow.Selection = vsoSelection

End Sub

If you're using the Dynamic Connector, this gets automatically assigned to a layer called 'Connector'.

Upvotes: 2

Related Questions