Author Topic: Sort the "Assign to Layer" list  (Read 3032 times)

0 Members and 1 Guest are viewing this topic.

kevsor1

  • Newbie
  • *
  • Posts: 2
Sort the "Assign to Layer" list
« on: February 26, 2013, 01: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

Compy

  • Newbie
  • *
  • Posts: 2
Re: Sort the "Assign to Layer" list
« Reply #1 on: May 04, 2022, 12:46:22 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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3281
    • Paul Herber's website
Re: Sort the "Assign to Layer" list
« Reply #2 on: May 04, 2022, 03:45:09 PM »
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 and applications for Visio -

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

Yacine

  • Hero Member
  • *****
  • Posts: 2953
Re: Sort the "Assign to Layer" list
« Reply #3 on: May 05, 2022, 01:09:02 AM »
You can write your own VBA form in which you can populate a sorted listbox with the layers of the page.
Yacine

Mouthpear

  • Jr. Member
  • **
  • Posts: 11
Re: Sort the "Assign to Layer" list
« Reply #4 on: May 06, 2022, 06:44:29 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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
Re: Sort the "Assign to Layer" list
« Reply #5 on: May 06, 2022, 09:03:10 AM »
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

  • Hero Member
  • *****
  • Posts: 1095
    • UnmanagedVisio
Re: Sort the "Assign to Layer" list
« Reply #6 on: May 06, 2022, 11:23:40 AM »
BTW, there is already a good tool by David Parker / bVisual:
https://bvisual.net/products/layermanager/
« Last Edit: May 06, 2022, 11:32:09 AM by Nikolay »

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3281
    • Paul Herber's website
Re: Sort the "Assign to Layer" list
« Reply #7 on: May 06, 2022, 11:28:39 AM »
I had better withdraw my offer then.
Electronic and Electrical engineering, business and software stencils and applications for Visio -

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

Nikolay

  • Hero Member
  • *****
  • Posts: 1095
    • UnmanagedVisio
Re: Sort the "Assign to Layer" list
« Reply #8 on: May 06, 2022, 11:32:21 AM »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
Re: Sort the "Assign to Layer" list
« Reply #9 on: May 06, 2022, 01:50:42 PM »
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

  • Jr. Member
  • **
  • Posts: 11
Re: Sort the "Assign to Layer" list
« Reply #10 on: May 06, 2022, 07:13:35 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

  • Newbie
  • *
  • Posts: 2
Re: Sort the "Assign to Layer" list
« Reply #11 on: May 07, 2022, 03:10:41 AM »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
Re: Sort the "Assign to Layer" list
« Reply #12 on: May 08, 2022, 01:51:23 PM »
Actually, when you bring up the layers dialog box, if you click the "NAME" header, it will sort the list
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
Re: Sort the "Assign to Layer" list
« Reply #13 on: May 08, 2022, 05:59:19 PM »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
Re: Sort the "Assign to Layer" list
« Reply #14 on: May 08, 2022, 08:47:01 PM »
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:
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
« Last Edit: May 10, 2022, 10:56:58 AM by wapperdude »
Visio 2019 Pro