Adding layers to extension
-
I've been considering adding the option to specify layers within my plugin (ie. framing, sheathing, blocking etc...)
I'm still trying to understand SketchUp's concept of layers though. Should each line be drawn on the custom layer or is it enough to create the group or component on the custom layer and the underlying geometry remains on layer0?
-
Always assign the 'raw' geometry - faces and edges - to Layer0 [that's what they get if you do nothing !].
Then assign other layers to their containers - groups or component-instances...A simple way to get a reference to a layer is:
my_layer = Sketchup.active_model.layers.add("my_layer_name")
If a layer of that name does not exist, then it's created, and also a reference to it is returned.
Alternatively, if a layer of that name already exists, then it returns a reference to it. -
Is it better to change the active layer to the custom layer and then create the group or component or first create the group/component and then assign it to the custom layer?
-
Never change the current layer in code.
It's unnecessary - and will lead to issues if you forget to reset it afterwards.
It's much easier to make the geometry already inside a newcontainer.entities
context [it'll all be assigned Layer0 [nil] as it's created]
Then just assign thatcontainer.layer=my_layer
as desired...
Much easier and foolproof... -
If you choose to change the active layer - make sure you set it back the way you found it.
model = Sketchup.active_model
layers = model.layers
original_layer = model.active_layerbegin
your_layer = layers.add("your_layer_name")
model.active_layer = your_layerdo whatever you need to
ensure
model.active_layer = original_layer
end -
Thank-you for all of the advice, this will save me from making a bunch of beginner mistakes with regards to layers.
I've had a number of requests for layers so I'm beginning to explore it a little more seriously.
I will make the custom layers user definable (name and rename the layers). Are there any more gotchas I should be aware of with layers?
The default layer names will be something like:
ROOF_TRUSS
ROOF_FRAMING
ROOF_SHEATHING
ROOF_TRIMFLOOR_TRUSS
FLOOR_FRAMING
FLOOR_SHEATHING -
I'd suggest not yelling your Layer names...
e.g.
Roof_Truss
Roof_Framing
Roof_Sheathing
Roof_TrimFloor_Truss
Floor_Framing
Floor_Sheathingto me it's polite and looks more professional...
john
-
As an very active user of layers could you please precede your layers with your/your plugin name this way they will remain unique, calling them common names like 'Roof' or 'Truss' is just asking them to be mixed in with existing layers.
If you did the same with any component and material names your plugin(s) creates it would be very helpful too. -
You could add a sketchup menu option something like "Medeek Truss - Edit Config"
Then throw up a simple Sketchup API inputbox where you set each of your granular layers
The prompts could be:Roof Truss:
Roof Framing:
Roof Sheathing:etc.
If the input box is empty then use Layer0
You can also provide logical defaults like "Roof Framing"
Users like Paul can add "Medeek Roof Framing"
Users who like underscores "Roof_Framing"
Users who want upper case "ROOF_FRAMING"
User who speak a different language can call it what ever they wantAlso if a user wants Roof Framing and Roof Sheathing to appear on the same layer - then all they need to do is use the same layer name for both!!
With a bit of effor - you can almost satisfy everyone.
-
@medeek said:
Are there any more gotchas I should be aware of with layers?
Yes, SketchUp layers are not really layers at all. They do not "own" geometric collections of entities (like they do in most CAD applications.) In SketchUp, layers are display behavior property sheets, that can be shared with multiple entities.
So in SketchUp, each object descended from
Sketchup::Drawingelement
has alayer
property that can be assigned to point at one of these property sheets (that were misnamed "layers" by the developers.)So, in reality you assign a SketchUp object to "use" a layer, not put an object upon a layer.
@paul russam said:
... could you please precede your layers with your/your plugin name this way they will remain unique, ... If you did the same with any component and material names your plugin(s) creates it would be very helpful too.
This also applies to Attribute Dictionary names. They should be prefixed with the name of your author name and extension name in some way, so there will not be any clashing of dictionary names. (For example, we all cannot have dictionaries named "Properties".) Something like "Medeek_TrussMaker_TrussProperties" or whatever.
Advertisement