• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Delete all layers via ruby

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 3 Posters 578 Views 3 Watching
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.
  • C Offline
    CadFather
    last edited by 1 Mar 2015, 22:04

    does anyone know if this is possible: delete ALL existing model layers and put all geometry on layer 0?

    i looked around in the forum and in the api, but only found a way to remove a layer by name or index (only for 2015).

    i'm trying to integrate it in a batch process

    1 Reply Last reply Reply Quote 0
    • S Offline
      slbaumgartner
      last edited by 2 Mar 2015, 00:46

      Probably the easiest way would be to iterate through all the geometry in the model and assign layer0 to everything, then invoke Sketchup.active_model.layers.purge_unused.

      1 Reply Last reply Reply Quote 0
      • C Offline
        CadFather
        last edited by 2 Mar 2015, 00:56

        yes, i did that, it worked until i got stuck trying to dig through groups and components...

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 2 Mar 2015, 12:01

          m=Sketchup.active_model; m.start_operation('!'); m.entities.each{|e|e.layer=nil}; m.definitions.each{|d|d.entities.each{|e|e.layer=nil}}; m.layers.purge_unused; m.commit_operation
          

          Reassigns everything [including things inside defiintions etc] to use 'Layer0', then purges all unused layers [i.e. all layers except 'Layer0']. It is one step undo-able.

          TIG

          1 Reply Last reply Reply Quote 0
          • C Offline
            CadFather
            last edited by 2 Mar 2015, 12:17

            Thanks TIG, you are the best! 😄 👍

            so you are mining for entities (including groups i presume), AND component definitions...

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 2 Mar 2015, 14:09

              Yes everything.
              All entities in all entities-collections.

              TIG

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

              Advertisement