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
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