It gave me a “headache” for a few hours wondering what the heck is going on… I thought I’d tell you so that it would be easier for you later.
So the issue is if I wanted to rename all layers (allow me to use the API terms) I was lazy enough to not exclude the “Layer0” because this cannot be renamed anyway.
Oh yes, as assumed the “Layer0” wasn’t renamed but then the start_operation-commit_operation
also wasn’t take effect. What? Why?
Perhaps renaming layers not recorded like the page (Scene) operation?.. this is against what I learned till now.
I thought - beside many other things - I’d create a cpoint
, to see if that would fix the creation of the undo stack. Nope! Even the cpoint
wasn’t created! So something in my code “backwardly” prevent to create dwge?
Checked in SU2017, 2020, 2021… all behave same, syntax okay…
As I shot the point of “joke” already above: the solution/conclusion is:
Do not try to rename “Layer0”!
The original code is without the commented line, un-comment it, then you get the code running as it should.
Both version are in the animation.
Happy Weekend!
def rename(backup_names = {})
model = Sketchup.active_model
layers = model.layers
model.start_operation("Rename Tags", true)
cp = model.entities.add_cpoint(ORIGIN)
layers.each{|layer|
# next if layer.name == "Layer0"
backup_names[layer.entityID] = layer.name
layer.name += "_-#{layer.entityID}"
}
model.commit_operation
backup_names
end
rename
PS. You can give same name of existing page for a new page (scene) using Ruby API. Be careful! I told you!