Deleting a layer
-
Hallo!
I tried to delete a layer named "Balkenlayer" with the following code:
mod = Sketchup.active_model layer_array = mod.layers layer_array.each{|l| if l.name == "Balkenlayer" l.erase! puts "Balkenlayer deleted" end }
Why isn't it working?
Thanks for your time.
Tim -
There's no API method for Layer or Layers to delete a layer like you could do manually.
Don't think that because a layer is an 'entity' you can use something like entities.erase_entities(layer) - it will either not work or hang Sketchup...
Find my code solution here http://forums.sketchucation.com/viewtopic.php?p=166985#p166985
The script layer-delete.rb adds a new Method the Sketchup's Layer Class -
"layer.delete()" - it deletes that layer from the model and
entities that used it get the default layer instead...
However, if used as "layer.delete(true)" then that layer's geometry is deleted too.
The default layer cannot be deleted, BUT if you use 'true' anything 'on' it WILL be deleted - so use it sensibly !
-
The erase!() method is defined in class Sketchup::Drawingelement
Sketchup::Layer is a subclass of Sketchup::Entity, NOT a subclass of Sketchup::Drawingelement, so it does not inherit a erase!() method.
You will need to move all entities off of the layer, then use Layers.purge_unused()
BTW.. Layers is a C++ collection, not a Ruby Array.
Advertisement