sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Material Library Creation Question

    Scheduled Pinned Locked Moved SketchUp Components, Materials & Styles
    sketchup
    6 Posts 3 Posters 958 Views 3 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.
    • Dave RD Offline
      Dave R
      last edited by

      I'm just wondering if there is a quick and easy way to read a list of color names and their RGB values and create a library. There's at least 120 colors I'd like to have in a library and I'd rather not have to enter each one by hand.

      Etaoin Shrdlu

      %

      (THERE'S NO PLACE LIKE)

      G28 X0.0 Y0.0 Z0.0

      M30

      %

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        It's fairly easy, can you send the file?

        Hi

        1 Reply Last reply Reply Quote 0
        • Dave RD Offline
          Dave R
          last edited by

          Hi Jim,

          File has been sent.

          Thank you.

          Etaoin Shrdlu

          %

          (THERE'S NO PLACE LIKE)

          G28 X0.0 Y0.0 Z0.0

          M30

          %

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            Here's a quick run-down of how. I'm sure there are better ways, this is the first way that worked. And since it worked, I don't have a need to make it better...

            The text file, in this case looks like this (altough Dave's actually was slightly simpler.)

            
            1  Almond  #EFDECD  (239, 222, 205)  1998   
            2  Antique Brass  #CD9575  (205, 149, 117)  1998   
            3  Apricot  #FDD9B5  (253, 217, 181)  1949   
            4  Aquamarine  #78DBE2  (120, 219, 226)  1958   
            
            

            And here's the Ruby code to read and parse the color file (which I called c.txt so that I would never remember what it was for.)

            
            # I'm working in the tmp folder under the Plugins folder
            pf = Sketchup.find_support_file "Plugins"
            tf = pf + "/tmp" # a tmp folder 
            
            # Open and read the file into an Array, using a newline as element separator.
            # Then, iterate over each element in the array, passing each array element in turn to the variable 'line'
            # All code between the do..end loop is executed for each line.
            IO.readlines(tf+"/c.txt").each do |line|
              # Here I use a regular expression to find text between the first space (\s) and the # symbol.
              # Then, chop off the # and strip any whitespace before and after the string.
              name = line[ /\s+(.*?)#/ ].chop.strip
            
              # Another regex
              # Find the text between ( and ), and store it in the 'color' variable.
              color = line[ /\(.*\)/ ]
            
              # substitute the ( ) and with nothing (remove them from string.)
              # This should really be done with a more correct regex in the previous step.
              color.gsub!(/[)(]/, '')
            
              # split the sdtring on the ',' and store the split values in r, g, and b variables.
              # split returns an array. Ruby allows multiple assignment for arrays; a, b, c = [1, 2, 3]
              r, g, b = color.split(',')
              
              # Add the material to SketchUp
              m = Sketchup.active_model.materials.add(name)
              # Set the materials color. to_i converts the string to an integer.
              m.color = [r.to_i, g.to_i, b.to_i]
            end
            
            

            Hi

            1 Reply Last reply Reply Quote 0
            • 2 Offline
              21D
              last edited by

              @dave r said:

              I'm just wondering if there is a quick and easy way to read a list of color names and their RGB values and create a library. There's at least 120 colors I'd like to have in a library and I'd rather not have to enter each one by hand.

              Hi dave, do you mind sharing that library of named colors?? 😄

              "I prefer drawing to talking. Drawing is faster, and leaves less room for lies."
              Le Corbusier

              1 Reply Last reply Reply Quote 0
              • Dave RD Offline
                Dave R
                last edited by

                I wouldn't mind at all but it turned out I didn't need to make it because Jim already did. You can find it at the link to his blog. I was interested in the Crayola crayon colors which he did a few weeks ago.

                It just goes to show there's nothing new under the sun. 😄

                Etaoin Shrdlu

                %

                (THERE'S NO PLACE LIKE)

                G28 X0.0 Y0.0 Z0.0

                M30

                %

                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