sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    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.
    • CadFatherC Offline
      CadFather
      last edited by

      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

        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
        • CadFatherC Offline
          CadFather
          last edited by

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

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

            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
            • CadFatherC Offline
              CadFather
              last edited by

              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
              • TIGT Offline
                TIG Moderator
                last edited by

                Yes everything.
                All entities in all entities-collections.

                TIG

                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