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

    Locking layers

    Scheduled Pinned Locked Moved SketchUp Discussions
    sketchup
    10 Posts 4 Posters 1.5k Views 4 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.
    • W Offline
      watkins
      last edited by

      Dear All,

      Is there a way to lock layers (like in AutoCAD) so that 'empty' layers cannot be purged?

      Kind regards,
      Bob

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

        No, layers can't be 'locked' - but you can lock groups/instances.
        So you could stop a layer being purged by making a tiny group containing no geometry [perhaps a piece of text says ' ' with no leader etc sized/scaled to be very small] and then putting it onto that layer in question and then locking the group.
        You won't be able to delete this locked group or change its layer, so the required layer will be effectively 'locked' and never purged. Trying to delete the layer will warn you it's not empty...
        πŸ€“

        TIG

        1 Reply Last reply Reply Quote 0
        • Jean LemireJ Offline
          Jean Lemire
          last edited by

          Ho Bob, hi folks.

          I don't think that layers can be locked.

          Don't forget that layers in SketchUp (SU) are not like layers in CAD softwares. They do not isolate geometries. They only control the visibility of objects.

          To prevent an empty layer from getting purged, you can assign to it a minimalist locked group. Lock the group after assigning it to the layer. Then the layer cannot be purged accidentaly. If you try to delete it, SU will tell you that the layer contains locked entities and will ask you what you want to do: 1 - Move the content to the default layer, 2 - Move the content to the current layer or 3 - Delete the content.

          This gives you one warning and should avoid accidental deletion of the layer. If you click, for example, "Delete content", the layer will be deleted and the content, since it is grouped, will be moved to the default layer.

          A minimalist group can contain a very short edge or a centerpoint or whatever suits you. You can also hide it. For example, a centerpoint on the axes origin is easy to place, to spot and to hide/unhide, lock/unlock or whatever.

          Just ideas.

          Jean (Johnny) Lemire from Repentigny, Quebec, Canada.

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

            You could set up a sneaky observer script along these lines...

            require 'sketchup.rb'
            ###
            def addBobsLayers()
              layers=Sketchup.active_model.layers
              layers.add("XXXX")
              layers.add("YYYY")
              layers.add("ZZZZ")
            end#if
            addBobsLayers()
            ### ensure ALL required layers are there at startup, making them as needed.
            ### make Bob's LayersObserver...
            class BobsLayersObserver < Sketchup;;LayersObserver
              def onLayerRemoved(layers, layer)
                addBobsLayers()
              end
              def onLayerAdded(layers, layer)
                addBobsLayers()
              end
              def onLayerChanged(layers, layer)
                addBobsLayers()
              end
              def onRemovedAllLayers(layers)
                addBobsLayers()
              end
            end
            ### Attach the new LayersObserver...
            def addBobsLayersObserver()
              $bobsLayersObserver = Sketchup.active_model.layers.add_observer(BobsLayersObserver.new) if not $bobsLayersObserver
              Sketchup.active_model.layers.remove_observer($bobsLayersObserver)
              Sketchup.active_model.layers.add_observer($bobsLayersObserver)
            end#def
            addBobsLayersObserver()
            ##########################################################
            ### we also need an AppObserver for when changing SKPs or closing SUp
            class BobsLayersAppObserver < Sketchup;;AppObserver
              def onNewModel(model)  ### from menu or app
                addBobsLayers()
                addBobsLayersObserver()
                addBobsLayersAppObserver()
              end
              def onOpenModel(model) ### from menu
                addBobsLayers()
                addBobsLayersObserver()
                addBobsLayersAppObserver()
              end
              def onQuit()
                Sketchup.active_model.layers.remove_observer($bobsLayersObserver)
                Sketchup.remove_observer($bobsLayersAppObserver )
              end
            end
            # Attach the AppObserver to the App observer at kick-off
            def addBobsLayersAppObserver ()
              $bobsLayersAppObserver = BobsLayersAppObserver.new if not $bobsLayersAppObserver
              Sketchup.remove_observer($bobsLayersAppObserver )
              Sketchup.add_observer($bobsLayersAppObserver )
            end#def
            addBobsLayersAppObserver()
            ###
            

            This way whenever the SKP's layers are changed the code adds back the listed layers - and if they exists it doesn't matter...
            This doesn't stop you erasing a layer [you are warned if it has entities] or purging it if it's empty, BUT the listed layers are instantly remade with the same name; if a SKP you open doesn't have these layers they are auto-added when it opens anyway...
            Copy the code into a file called 'BobsLayersObserver.rb' in the Plugins folder. Adjust the layer names in 'addBobsLayers' layers.add("????") as you want... πŸ€“

            This is probably too full on, but it shows the power of observers...

            TIG

            1 Reply Last reply Reply Quote 0
            • W Offline
              watkins
              last edited by

              Dear All,

              Thank you very much for all your suggestions. I see that both TIG and Jean use the same technique.

              TIG, thank you for the code snippet. I will give it a go tomorrow.

              The reason I wanted to lock layers is because I'm working on a detailed house model, and I want to use a predefined layer set, such as that shown in the attached printscreen image.

              At the moment I am being careful to use TIG's PurgeAll, which offers choices via a dialogue box. It would be nice if there was an icon to launch this plugin. This would save me having to scroll down the plugin list to find PurgeAll (I can hear TIG saying, "lazy bugger"). I have been in the habit of using a script called purge.rb which uses the attached icon (script and icon attached; no details of author or source). Now I have to be more careful, hence the original enquiry

              Kind


              purge.rb


              purge_16.gif


              Screenshot.JPG

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

                As my Purge... tool is in the main menu why not assign a shortcut-key to it ? e.g. Alt+P ?
                No need for toolbar clutter... πŸ˜„

                TIG

                1 Reply Last reply Reply Quote 0
                • W Offline
                  watkins
                  last edited by

                  TIG,

                  Thanks! Sometimes, the solution is staring one in the face.

                  Have a productive day!

                  Regards,
                  Bob

                  1 Reply Last reply Reply Quote 0
                  • GaieusG Offline
                    Gaieus
                    last edited by

                    Bob, that's some extensive layering! 😲

                    Gai...

                    1 Reply Last reply Reply Quote 0
                    • W Offline
                      watkins
                      last edited by

                      Dear Gaieus,

                      Yes, but it does allow me to look at some of the construction in detail.

                      Regards,
                      Bob

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

                        Of course the advantage of my 'Purge' as opposed to the 'Model Info' one is that you can select NOT to purge the layers...

                        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