Layer0 questions
-
- Is Layer0 always the first layer,
e.g. Sketchup.active_model.layers[0].name
- Is the name of the default layer always "Layer0" - even in foreign versions?
I guess this could and would change with templates.
-
Does anyone use a template where Layer0 has a different name?
-
It looks like you cannot change the name of Layer 0
Sketchup.active_model.layers[0].name = "Test"
does not change the name.
(It does for Layer1) -
-
Is Layer0 always the first layer,
Layer0 is always listed in the Layer-Browser first even when they are ordered 'alphabetically' or 'reversed' - since it is preexisting logically it ought to be the first in model.layers
e.g. Sketchup.active_model.layers[0].name -
Is the name of the default layer always "Layer0" - even in foreign versions?
I guess this could and would change with templates.
**Layer0** is the EN name for **layer==nil**. It has other names in different locales. To find its name set **model.active_layer=nil** and then use **model.active_layer.name**. You can't rename it in a 'template' - it is just based on locale naming for **layer==nil**. You can use the fact that the default-layer is 'nil' and get it's name without knowing the locale or anything else... just set a temp-variable to remember the current **tlay=model.active_layer**, change to 'nil' [**model.active_layer=nil**], then get the **deflayname=active_layer.name** [>>> "Layer0" e.g. depending on the locale], then just reset **model.active_layer=tlay**
-
Does anyone use a template where Layer0 has a different name?
You can't rename Layer0 in a 'template' - it is just based on locale naming for **layer==nil**. Every non-EN locale user will have their own name for the default-layer...
-
It looks like you cannot change the name of Layer0
OR its equivalent name in other locales
Sketchup.active_model.layers[0].name = "Test"
does not change the name.
(It does for Layer1)
Correct. Sketchup spots if the layer is 'nil' and assigns the locale's 'default-layer' name to it - in the case of EN-US it's 'Layer0' - it is immutable...
-
-
Wonderful answer TIG.
I was about to use this set of code to skip the default layer:
model.layers.each do |layer| # do not process Layer0 next if layer.name == "Layer0" ...
However I had better find a different way to skip the first layer,
However in searching for Layer0 in my Ruby code I see a number of other items which sound like they may not work.
# remember layer name unless it is a pass through if (entity.layer.name != "Layer0") eparms2.parent_layer = entity.layer.name end#if or model.active_layer = model.layers["Layer0"]
The second one can easily be replaced with:
model.active_layer = nil
But the first one seems more troublesome.
This seems a bit cumbersome:
tlay = model.active_layer model.active_layer = nil deflayname = active_layer.name model.active_layer = tlay if (entity.layer.name != "Layer0") eparms2.parent_layer = entity.layer.name end#if
Do you have a suggestion for seeing if an entity is in the 'nil' layer.
-
Which layer does model.add("Layer0") return in a foreign language version?
(A new layer or the nil layer?)I presume the foreign language versions cannot create new layers called Layer0, because that would get confusing if I tried to use the model in English.
Can someone tell me what Layer0 is called in some other language where it is different, so I can see what happens if I try to create a new layer with that name.
-
layer=model.add("Layer0")
does return a reference to a layer in any locale - including EN.
It is the same layer asmodel.active_layer=nil
Setting the active layer to nil and getting its name is the foolproof way of finding the default-layer's name in that locale.
If you are sure that layers[0] is always the default layer then using that should work too.
Then to process all layers except the default-layer you can use
model.layers.to_a[1..-1].each{|layer|###do process###}
as it misses off the first one...
Advertisement