Layers Order
-
Beware that non-EN SUppers might not call layer=nil 'Layer0', so we need to trap for that too...
We sort the layer_names alphabetically and add them onto an array starting with the default_layer_name or whatever it's called ?layer_names=[] model.layers.each{|layer| layer_names<<layer.name } layer_names=layer_names-[default_layer_name] ### it will always start with the 'default_layer-name' ### - even if it's not 'Layer0' - so... default_layer_name=layer_names[0] layer_names=layer_names-[default_layer_name] layer_names.sort! layer_names=[default_layer_name]+layer_names ### now have aAyer0 [or whatever] and the rest in alphabetical order... ### ### to add layer_names to dialog... dialog_layers=layer_names.join("|") ### ### to find layer picked by name if layer_name=default_layer_name layer_to_use=nil else layer_to_use=nil model.layers.each{|layer| if layer.name==layer_name layer_to_use=layer break ### we got it end#if } end#if ### etc etc
-
Sorting will fail for any user that uses non-English characters (outside the ASCII range) as they will be multi-byte characters.
-
@tig said:
We sort the layer_names alphabetically and add them onto an array starting with the default_layer_name
Your post and code are most helpful, but ...
I'm looking at a little test model. It's layers, per the layer window, are:
Layer0
stairs
ground_floor
roof
basement
second_floor
garageMy mother was a librarian. She taught me about sorting. "basement", "garage", ...
It's layers, per the Ruby Console, are:
Layer0
basement
ground_floor
garage
second_floor
stairs
roofIt's layers, per Entity Info dropdown are:
Layer0
(others, in alpha order)In my testing, I've become convinced that the Ruby Console array is ordered in the sequence the layers were entered.
For the rest, I'm sure I don't know. I just tested File/New, (in Layers window click "+" and press Enter), 4 times. This is what the Layers window says:
Layer0
Layer4
Layer2
Layer3
Layer1(Repeat above test. Order is now 0, 4, 1, 3, 2).
-
Layers reported in model.layers are in the order they are made - that's why the default_layer is always first - it's in the model already !
In the layer-browser they are listed default_layer first, them the rest in alphabetical order.
My method sorts the list to be like that - irrespective of the actual name of the default_layer - assuming no accented characters in the names !
If you want to order the list and know what the layers are called why not just make the layer_list like that by hard coding it ? Otherwise you need a complex look-up list to ensure that whatever layers there are are ordered as you want - e.g. by 'level'... Layers no in your system will be ordered tot he end... Of course calling them Level0, Level1, Level2 would do this too without the pain !
Confused about the list ordering ???
-
@tig said:
In the layer-browser they are listed default_layer first, them the rest in alphabetical order.
Either we're not communicating or maybe my SU is broke. By "layer-browser" do you mean the window named "Layers"? The list in my Layers window is definitely not alphabetical.
-
-
Ruby Array:
I am finding that the ruby array is in the order the array was created. Is that agreed? -
Layer Toolbar:
This appears to always be in alphabetical order, with the Layer 0 always first. -
Layer Browser/Inspector/Dialog:
This can be sorted by layer name, color, on/off. So there is no single right way that it is ordered. And Sketchup appears to remember what method you were sorting by, from session to session. So if you ever hit sort by color, it will be on that next time you open SU.
Is that what others are seeing?
Chris
-
-
chris,
one more case in which the windows and mac versions differ. i do not see another way of sorting the layers than ascending/descending.
-
@chris fullmer said:
- Ruby Array:
I am finding that the ruby array is in the order the array was created. Is that agreed?
Chris
Yes same with scenes, components and so on
Chris
-
@tig said:
Can't you click on the column's top bar and sort by that e.g. click on Name, Visible, Color... The default layer Layer0 always stays at the top ahtever you click on but the other layers sort ascending/descending by either their name, visibility or color-value [rgb?]...
you can do it for Name and Visible, not for Color.
-
@edson said:
chris,
one more case in which the windows and mac versions differ. I do not see another way of sorting the layers than ascending/descending.Can't you click on the column's top bar and sort by that e.g. click on Name, Visible, Color... The default layer Layer0 always stays at the top whatever you click on but the other layers sort ascending/descending by either their name, visibility or color-value [rgb?]...
-
@chris fullmer said:
So if you ever hit sort by color, it will be on that next time you open SU.
Beautiful! No more confusion here, I was sorted by color (whatever that means). Now I'm sorted by name, as everyone has been saying.
Advertisement