Sort the "Assign to Layer" list

Started by kevsor1, February 26, 2013, 06:10:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kevsor1

Hi Experts,

I've got a very complex visio with lots of layers and VBA code that manipulates when certain layers are shown. 

The problem is that as I continue adding objects and layers to my diagrams, when I want to assign layers to a new object, it's becoming very time-consuming to find the right layer in the "Assign to Layer..." dialogue box because they're not sorted in any intelligible manner (I think it uses creation order, which is a mess in my case).   :( 

Is there a way to alphabetize the list of layers in the "Assign to Layer..." dialogue box (without deleting the layers and adding them in alphabetical order)?

Thanks,
Kevin

Compy

Quote from: kevsor1 on February 26, 2013, 06:10:04 PM
Hi Experts,

I've got a very complex visio with lots of layers and VBA code that manipulates when certain layers are shown. 

The problem is that as I continue adding objects and layers to my diagrams, when I want to assign layers to a new object, it's becoming very time-consuming to find the right layer in the "Assign to Layer..." dialogue box because they're not sorted in any intelligible manner (I think it uses creation order, which is a mess in my case).   :( 

Is there a way to alphabetize the list of layers in the "Assign to Layer..." dialogue box (without deleting the layers and adding them in alphabetical order)?

Thanks,
Kevin
Given the date and lack of an answer to this question do I assume that its not possible?

Paul Herber

The layer index property is read-only so that suggests it's not possible to re-order them.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Yacine

You can write your own VBA form in which you can populate a sorted listbox with the layers of the page.
Yacine

Mouthpear

Quote from: Yacine on May 05, 2022, 06:09:02 AM
You can write your own VBA form in which you can populate a sorted listbox with the layers of the page.

How would you write that code? Example?

wapperdude

Ohhhh. 🤔😥

That seems like a lot of work...
  1) setting up the form to have all the correct columns
  2) Adding Check boxes for each line item
  3) enabling individual check box selection / deselection, plus select / deselect all
  4) allowing code to build / populate the list (each time code is run ???) for the active page, and then bring up the list
  5) easy part is making the form non-modal

Granted, writing code only needs to be done once.  But not a trivial task.
Visio 2019 Pro

Nikolay

#6
BTW, there is already a good tool by David Parker / bVisual:
https://bvisual.net/products/layermanager/

Paul Herber

I had better withdraw my offer then.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Nikolay

I have also built one a while ago, but it turned to be of little use to me (basically was to test my printer test the sciter library;D
https://github.com/nbelyh/LayerHelper

wapperdude

The development by David Parker looks to be outstanding.  Not cheap, but looks to be well conceived and implemented.  He's elevated the whole Visio layers scheme to a new level.
Visio 2019 Pro

Mouthpear

Quote from: Nikolay on May 06, 2022, 04:23:40 PM
BTW, there is already a good tool by David Parker / bVisual:
https://bvisual.net/products/layermanager/

Looks like all those buttons for layers in his add-in take up too much space. More important, this does not even do the one thing the OP is looking for. HOW TO REORDER THE LAYERS so that they are in alphabetical order.

Compy

Thanks to all who have contributed.
I have tried the bvisual tool and cannot see a sort for the list in here. Please correct me if I am wrong.
I am not a VBA programmer, so the VBA option for me becomes even more involved than suggested.  - Point 0 added to the list, Learn VBA. Although this may be interesting it is not really the objective!
Paul, what was or is the offer you have withdrawn?
Thanks

wapperdude

Actually, when you bring up the layers dialog box, if you click the "NAME" header, it will sort the list
Visio 2019 Pro

wapperdude

Some observations that are rarely mentioned wrt layers:
1) The order that the layers are presented in the Assign to Layers list is the order found in the Layers Section of the page shapesheet.  So, if there's a VBA (or whatever snake oil you prefer), that does alphbetizing, this is where it would need to happen.

2)  Layers do not have a hierarchical structure.  That is, you cannot great a group dediccated to, say, plumbing or electrical.  While I haven't explored it, David Parkers development may do that.  That could simplify layer selection on a functional basis.

3) A quasi-ordering can be acchived via a more rigorous/elaborate layer naming convention.  To wit, electrical switches might be:
  > Elec.sw.spst
  > Elec.sw.dpdt
  > Elect.sw.mon.no  (electrical, switches, momentary, normally open)

From what I can tell, such indulged names are permissible.
Visio 2019 Pro

wapperdude

#14
After realizing that the alphabetizing of the Assign to Layers was merely a matter of re-ordering the rows in the Layers section of the Page shapesheet, I reworked an online piece of code to solve the problem at hand.

@Paul Herber:  code ready for your Utilities  ;)
Here's the code:

Sub Bubble_SortArray()
'Alphabetize order of layers
'An approach that eliminates need to open Page shapesheet

    Dim tmpStr As String
    Dim pgLyrs As Visio.Layers
    Dim arrLyrs() As Variant
    Dim RCnt As Long
    Dim i As Long
   
    Dim vShp As Visio.Shape
    Dim vShps As Visio.Shapes
    Dim actPg As Visio.Page
   
'Initializations
    Set actPg = ActivePage
    Set vShps = actPg.Shapes
    Set vShp = vShps("ThePage")
   
    Set pgLyrs = actPg.Layers
    RCnt = pgLyrs.Count
    ReDim arrLyrs(RCnt - 1)
    i = LBound(arrLyrs)
   
'Fetch all the layer names & store in array
    For Each pgLyr In pgLyrs
        arrLyrs(i) = pgLyr.Name
        i = i + 1
    Next

'Alphabetize Sheet Names in Array List
    For i = LBound(arrLyrs) To UBound(arrLyrs)
        For j = i To UBound(arrLyrs)
            If UCase(arrLyrs(j)) < UCase(arrLyrs(i)) Then
                tmpStr = arrLyrs(i)
                arrLyrs(i) = arrLyrs(j)
                arrLyrs(j) = tmpStr
            End If
        Next j
    Next i
   
'Transfer corrected sequence to the page shapesheet
    For i = LBound(arrLyrs) To UBound(arrLyrs)
        vShp.CellsSRC(visSectionLayer, i, visLayerName).FormulaU = Chr(34) + arrLyrs(i) + Chr(34)
    Next
   
End Sub
Visio 2019 Pro