Layer Name Sorting


#1

So if I have layers named by numbers they don’t sort in order, for instance Rhino sorts layers like this

E1
E10
E2
E20

instead of like this;

E1
E2
E10
E20

Anyway to have them sort numerically?


#2

I use 01 to 09 in these numerical situations and it has become a natural way to use 1 to 9, and a double 00 if the numbers in the hundreds.


(Margaret Becker) #3

This is a problem with computer sorting in general. Windows Explorer works the same way.


(Dale Fugier) #4

Its possible to modify the Layer dialog to sort naturally (or logically). I’d probably want to make it optional.

For example, run the attached script and you can see the difference.

Option Explicit

Call TestLayerNameSort()

Sub TestLayerNameSort()

	Dim arrNames, arrNormalSort, arrLogicalSort, strName
	arrNames = Rhino.LayerNames

	Rhino.ClearCommandHistory
	
	Call Rhino.Print("Layer names - no sort")
	For Each strName In arrNames
		Call Rhino.Print("  " & strName)
	Next
	
	Call Rhino.Print("--")
	
	Call Rhino.Print("Layer names - sort ascending")
	arrNormalSort = Rhino.SortStrings(arrNames, True, True, False)
	For Each strName In arrNormalSort
		Call Rhino.Print("  " & strName)
	Next
	
	Call Rhino.Print("--")
	
	Call Rhino.Print("Layer names - logical sort ascending")
	arrLogicalSort = Rhino.SortStrings(arrNames, True, True, True)
	For Each strName In arrLogicalSort
		Call Rhino.Print("  " & strName)
	Next
	
End Sub

#5

@dale Yes Logical sort does do what I am looking for, and I agree it might be nice to have the option. Although is there a time where you wouldn’t use logical sort.

@margaret Actually windows use to be that way but not anymore. I forgot when it changed but it’s been a while.

@BrianM Thanks.


(Dale Fugier) #6

http://support.microsoft.com/kb/319827


(Margaret Becker) #7

Ah. I have old habits and so I never noticed the change.


#8

Add another vote for this, I had to write a script today to modify layer names and add leading zeroes to get it to properly sort 160 numbered layers… In this case I didn’t really have the choice to plan this from the beginning, as the layer names were derived from the filenames of the 160 files I imported.

Thx, --Mitch