Locking layers
-
Dear All,
Is there a way to lock layers (like in AutoCAD) so that 'empty' layers cannot be purged?
Kind regards,
Bob -
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...
-
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.
-
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...
-
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
-
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,
Thanks! Sometimes, the solution is staring one in the face.
Have a productive day!
Regards,
Bob -
Bob, that's some extensive layering!
-
Dear Gaieus,
Yes, but it does allow me to look at some of the construction in detail.
Regards,
Bob -
Of course the advantage of my 'Purge' as opposed to the 'Model Info' one is that you can select NOT to purge the layers...
Advertisement