Problem with the Ruby case statement [Solved]

I got wrong syntax with the .case ruby method
" unexpected tCONSTANT, expecting keyword_when When “IfcWall” then “C-Murs”

This is my code
model.definitions.each{|d|
next if d.image?
d.instances.each{|i|
layer_name = case i.name[0…6]
When “IfcWall” then “C-Murs”
when “IfcDoor” then “C-Men interieure”
else “layer 0”
end
new_layer = layers.add layer_name
i.layer = new_layer

				}
			}

I don’t understand how it must works…

You have an upper case W in When. when is a keyword and must be all lowercase.

Arg you 're right, that was so simple…

Also “layer 0” needs to be “Layer0” (no space)

Thanks

Still not the good way :frowning:
“# NameError: undefined local variable or method `layers’ for VicoIFC:Module”
I’m not good with this case method

In your code, you would use this line:

new_layer = model.layers.add(layer_name)

The error is saying layers is not a variable or a method. model.layers is a method which returns the Layers collection of the model, but only because in your code model is a reference to Sketchup.active_model

You can in all cases get a model’s Layers by using Sketchup.active_model.layers

Ok I just find I forgot to put the “layers = model.layers” in may code

model = Sketchup.active_model
layers = model.layers
model.start_operation(“IFC to Layer”)
model.definitions.each{|d|
next if d.image?
d.instances.each{|i|
layer_name = case i.name[0…6]
when ‘IfcWall’ then ‘C-Murs’
when ‘IfcDoor’ then ‘C-Men interieure’
else ‘layer0’
end
new_layer = layers.add layer_name
i.layer = new_layer

				}
			}

Thanks for the quick answers

No problem. This is for the IFC to Layers extension?

Yes I try to improve it (it’s to long for big model)