sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Create new layer with an RGB colour

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 255 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.
    • R Offline
      rossthompson
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Unfortunately the Ruby API doesn't expose access to a layer's colour. Either getter or setter.

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          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...

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

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

            That's right.
            A very clunky fix...
            My layer.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...

            TIG

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              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.

              I'm not here much anymore.

              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