sketchucation logo sketchucation
    • Login
    ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

    Deleting a layer

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 1.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kiesewetter
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

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

        TIG

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          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.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement