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

    Remove layer

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 5 Posters 297 Views 5 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.
    • D Offline
      dacastror
      last edited by

      hi, I ask how I can remove a layer from ruby, I could not find a way to do this,
      thanks in advance

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

        @dacastror said:

        hi, I ask how I can remove a layer from ruby, I could not find a way to do this,
        thanks in advance
        First you must iterate all entities in the model ADD within all definitions entities, and change the layer if it matches...
        e.layer=nil if e.layer.name=="layer_to_go"
        OR us another layer...
        e.layer=layers.add('new_layer')
        Now you can do
        layers.purge_unused
        and the now unused layer is deleted...
        If you have an unused layer you'd like to retain you need to make some temporary entities using it, so that layer doesn't get purged.

        TIG

        1 Reply Last reply Reply Quote 0
        • jiminy-billy-bobJ Offline
          jiminy-billy-bob
          last edited by

          TIG is being modest, but he actually wrote a snippet for it : http://sketchucation.com/forums/viewtopic.php?t=20086

          But don't use it as is, you need to modify it to use the method in your own namespace.
          Here is how I did it (There may be some mistakes, I'm just starting ruby ! So check it, but it works fine for me) :

          ### LAYER DELETE METHOD ### ------------------------------------------------------
          	#Simple modification of TIG's snippet delete-layer.rb
          	#Basically, move or delete layer content, then creates an entry for every layer except one to delete, then purge layers, then delete entries
          	
          	def self.deleteLayer(layer, delete_geometry=false)
          		model=Sketchup.active_model
          		ents=model.entities; defs=model.definitions; layers=model.layers
          		model.start_operation ("Delete layer")
          		if delete_geometry
          			allents=[]
          			ents.each{|e|allents<<e if e.valid? and e.respond_to?(;layer)and e.layer==layer}
          			defs.each{|d|d.entities.each{|e|allents<<e if e.valid? and e.respond_to?(;layer)and e.layer==layer}}
          			allents.each{|e|e.erase! if e.valid?}
          		else ### move geom to Layer0 etc
          			ents.each{|e|e.layer=nil if e.respond_to?(;layer)and e.layer==layer}
          			defs.each{|d|d.entities.each{|e|e.layer=nil if e.respond_to?(;layer)and e.layer==layer}}
          		end#if
          		group=ents.add_group();gents=group.entities ### temporarily use other layers
          		temp=gents.add_group()
          		temp.layer=nil
          		(layers.to_a-[layer]).each{|layer|tc=temp.copy;tc.layer=layer}
          		model.active_layer=nil if model.active_layer==layer ### ensure layer is not current layer
          		layers.purge_unused ### purge layer from browser
          		group.erase! ### erase! the temporary layer user, use set as was.
          		model.commit_operation 
          	end#def
          

          Call it with something like self.deleteLayer(layers[layerName])

          25% off Skatter for SketchUcation Premium Members

          1 Reply Last reply Reply Quote 0
          • KrisidiousK Offline
            Krisidious
            last edited by

            I think a more popular command would be "Remove Lawyer"...

            By: Kristoff Rand
            Home DesignerUnique House Plans

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

              I did write a whole raft of 'missing' layer methods...
              I just thought I'd let you learn by doing... 😉

              TIG

              1 Reply Last reply Reply Quote 0
              • renderizaR Offline
                renderiza
                last edited by

                Here is another option but I don't know if its compatible with MAC OS

                Sketchup.send_action(21537) #Delete Layer

                [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                1 Reply Last reply Reply Quote 0
                • jiminy-billy-bobJ Offline
                  jiminy-billy-bob
                  last edited by

                  @tig said:

                  I did write a whole raft of 'missing' layer methods...
                  I just thought I'd let you learn by doing... 😉

                  I learn by looking at what you wrote !

                  25% off Skatter for SketchUcation Premium Members

                  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