Sort layers names by n-th character

Wojty1
Advocate
Advocate

Sort layers names by n-th character

Wojty1
Advocate
Advocate

Hi everyone,

 

I wonder if it is possible to sort layers (within a properties or group filter) by n-th character of the layer name.

The problem is that we use coded layers like VV-XXX-A...

Let's assume the few following layer names:

 

VV-WWW-Apple

VV-WWW-Banana

VV-XXX-Automobile

VV-XXX-Coupe

VV-YYY-British

VV-YYY-Canadian

VV-ZZZ-Ant

VV-ZZZ-Chicken

 

What I would like to have is a list of layers ordered by the third character group separated by a dash.

In this case starting with the 8th character so the layer list would look like this:

 

VV-WWW-Ant

VV-XXX-Apple

VV-ZZZ-Automobile

VV-WWW-Banana

VV-YYY-British

VV-XXX-Canadian

VV-YYY-Chicken

VV-ZZZ-Coupe

 

As you can see the A, B and C letters are sorted.

I doubt that this is possible, but maybe someone has an idea or workaround.

The goal is to find the needed layer faster instead of searching it in the list.

The codes we use are fixed, but until I have them all memorized it'll take time.

 

Any help appreciated.


Windows 10 Pro 64-bit | Civil 3D 2024 / Revit 2024 (64-bit EN)
ASUS Maximus Hero VIII / Intel QuadCore Core i7-7700K / EIZO FlexScan EV2411W 24" + EV2416W 24" / 64 GB Corsair Vengeance LPX (4x 16 GB) Dual-Channel DDR4 / 12 GB ASUS GeForce RTX 3060 OC V2

Windows 10 Pro 64-bit | All Autodesk Products 2023 + 2024
HP ZBook Fury G10 / Intel Core i7-13850HX / 3x Lenovo 24" / 128 GB RAM / nVidia RTX Ada 3500
0 Likes
Reply
Accepted solutions (1)
459 Views
4 Replies
Replies (4)

jreidKVSUZ
Advocate
Advocate

I will give it a try. Make your layers like File Explorer does when we get Received Files. I put the type of files received and the date at the end of the folder. But I put a 01-, 02- in front so I know what order they came in no matter how fast or slow I want to search, the files or folders are in the order they were received by the -01, -02 vs the date.


01-VV-WWW-Ant
02-VV-XXX-Apple
03-VV-ZZZ-Automobile
04-VV-WWW-Banana
05-VV-YYY-British
06-VV-XXX-Canadian
07-VV-YYY-Chicken
08-VV-ZZZ-Coupe


Doing it this way you may be able to remove the VV-'s. Also, when you tell someone, you could say use Layers 3 & 7 vs Layer 3 Automobile and Layer 7 Chicken for whatever you’re doing. Our work folders all have a numbering system just like this and when telling someone to go to whatever folder we say 06, then 02, then 05, that is the files to work on. We never call out the folder’s total name, just the number the folder starts with.


Hope this helps.
JRR!

 

0 Likes

Kent1Cooper
Consultant
Consultant

I don't know of a way to have them sorted like that within the Layer Manager, if that's what you mean.  But depending on what you want to do with them, something may be possible.  For example, if you want it in order to set one current, I think I can imagine a way that would show them as command options are shown, in a prompt in which you can pick one.  [What I have in mind could be overwhelmed by large quantities of long Layer names, but I'd have to experiment.]  Would something like that serve your purpose?

 

EDIT:  Not there yet, but this is the concept to choose a Layer name from a list sorted in the way you describe.  It should [if the problem can be pinned down] result in a Layer name in the 'layname' variable, to be used as desired [e.g. in a Layer command to set it current or apply any other option to it, or in (setvar 'clayer layname) etc.]:

 

(setq
  laylist
  '(
    "VV-WWW-Apple"
    "VV-WWW-Banana"
    "VV-XXX-Automobile"
    "VV-XXX-Coupe"
    "VV-YYY-British"
    "VV-YYY-Canadian"
    "VV-ZZZ-Ant"
    "VV-ZZZ-Chicken"
  )
  sortedlist
  (vl-sort laylist
    '(lambda (a b)
      (<
        (substr a (+ (vl-string-position 45 a 1 T) 2))
        (substr b (+ (vl-string-position 45 b 1 T) 2))
      )
    )
  )
)
(initget (vl-string-right-trim " " (strcase (apply 'strcat (mapcar '(lambda (x) (strcat x " ")) sortedlist)))))
(setq layname
  (getkword
    (strcat
      "\nSelect Layer Name ["
      (vl-string-right-trim "/" (strcase (apply 'strcat (mapcar '(lambda (x) (strcat x "/")) sortedlist))))
      "]: "
    )
  )
)

 

What I can't figure out is why it gives an "Invalid option keyword." error when I pick one in the prompt, either at the command line or up in the drawing area if Dynamic Input is on, or when I type in a complete Layer name.  It seems to be constructing the (initget) keywords string correctly, and the prompt shows the options just as one would expect [in both places if Dynamic Input is on], and I confirmed that hyphens are allowed in keywords, so I'm not sure what the problem is -- suggestions welcome.  It may not be necessary to force them to all-capitals -- I tried that because I got the same error message without doing it, in case capitalization or lack thereof was part of the problem [I wouldn't think it should be required].

 

In any case, it includes a way to sort your Layer names in the way you describe, in alphabetical order of what follows the last hyphen, in setting the 'sortedlist' variable, if that can be of use to you in some other approach.

Kent Cooper, AIA
0 Likes

ВeekeeCZ
Consultant
Consultant
Accepted solution

You could try using the command line to quickly search for a layer by searching any middle key.

Preferably, adjust the setting and see if it works for you.

 

eekeeCZ_1-1726497381949.png

 

 

Wojty1
Advocate
Advocate

@ВeekeeCZ Wow, I never used the command line for searching, although I have all objects checked in "Input Search Options"

Once again, learned something new. Many thanks for that!

 

@jreidKVSUZ @Kent1Cooper thanks to you too for your efforts.


Windows 10 Pro 64-bit | Civil 3D 2024 / Revit 2024 (64-bit EN)
ASUS Maximus Hero VIII / Intel QuadCore Core i7-7700K / EIZO FlexScan EV2411W 24" + EV2416W 24" / 64 GB Corsair Vengeance LPX (4x 16 GB) Dual-Channel DDR4 / 12 GB ASUS GeForce RTX 3060 OC V2

Windows 10 Pro 64-bit | All Autodesk Products 2023 + 2024
HP ZBook Fury G10 / Intel Core i7-13850HX / 3x Lenovo 24" / 128 GB RAM / nVidia RTX Ada 3500
0 Likes