Create new layer with an RGB colour
-
Hi,
I was wandering if it is possible to write a script to generate a set of layers with specific RGB colours. Google developers provides code for creating a new layer with a certain name:
model = Sketchup.active_model layers = model.layers new_layer = layers.add "test layer"
However I can't figure out the colour aspect. Looking at similar scripts it appears people have had to use a work around passing the layers through a DXF file. Surely it can't be that complicated?
Any help would be greatly appreciated.
Ross
-
Unfortunately the Ruby API doesn't expose access to a layer's colour. Either getter or setter.
-
Think TIG might have worked around it by generating a DWG or DXF with a colour layer which SketchUp will make use of when importing...
-
That's right.
A very clunky fix...
Mylayer.color=
method [Pro only] writes an 'empty' temporary DXF file defining the layer with a color set and imports it...
It shouldn't need to be so complicated !
See http://forums.sketchucation.com/viewtopic.php?p=177016#p177016
Importing a SKP with a set of layers that you have previously manually set names/colors/materials for, each assigned to a a cpoint inside a group [so the layers come in, but which you erase after they are imported] is a neater workaround. It won't overwrite existing layers mind... -
If you are starting with a fresh new model.. ie,
Sketchup.active_model.modified? == false && Sketchup.active_model.title.empty? == true && Sketchup.active_model.path.empty? == true
.. then you could open a new file from a template, that had the layers already set up.Otherwise...
... you can create a component definition, that has nothing but cpoints on your preset layers (names and colors and visibility,) and then save the component to your local component library.Then anytime you wish to use those layers, either manually open the component library and click on that component (you do not actually need to insert it into the model.)
Here's a little SKP that has EIA colors assigned to Layer1 thru Layer9. (These are the colors you see on resistors or capacitors, that indicate their value. Sometimes also used by rainbow ribbon cables, to indicate pin number.)
EIA_Color_Layers.skp
Or.. via Ruby, you can load that component (say from a plugin sub-folder.)module Author module CustomLayers class << self def add_landscape_layers() plugs = Sketchup.find_support_file("Plugins") path = File.join(plugs,"Author/CustomLayers/LandscapeLayers.skp") mdl = Sketchup.active_model() defnset = mdl.definitions() landscape_layers_defn = defnset.load( path ) trans = Geom;;Transformation.new() # default identity transform inst = mdl.entities.add_instance(landscape_layers_defn,trans) inst.erase! end # def add_landscape_layers() end # proxy class end # submodule end # Author's toplevel module
One drawback is that the color for the default layer ("Layer0",) must be set in the template files.
Advertisement