Extending the list of named colors in Sketchup:

I’ve been developing an extension to import SVG files in Sketchup; One of the final outstanding issues that I face relates to colors and materials. Sketchup has a number of ‘named’ colors that can be used for the definition of materials for faces (and edges). In a similar way, the SVG specification defines a series of named colors that can be used to define the fill and stroke properties in SVG.

Both lists with names describe 100% of the same set of colors, with identical names and RGB values. The only ‘difference’ is that the SVG list distinguishes ‘dual’ names for a number of grey/gray variants to accommodate both ways of spelling. The Sketchup named color list specifies only a single name for the same color. In addition, Sketchup is not 100% consistent w.r.t. the chosen spelling (i.e. a mixutre of ‘grey’ and ‘gray’).

As a result of this, there are more entries in the SVG list than in the Sketchup list, although the set of ‘physical’ colors is the same.

Unfortunately, importing a SVG ‘grey/gray’ color with the missing spelling variant in the Sketchup list generates an error in the Ruby script.
The ‘easiest’ way to ‘fix’ this inconsistency, would be to ‘extend’ the list of color names in Sketchup with the missing names. I’ve been playing around with a number of ‘trials and errors’, based on the Sketchup Ruby API documentation, but I can’t find out how to accomplish this.
Any help/suggestions are highly appreciated.

PS: I use Sketchup Make 2017 (might be relevant, e.g. in terms the versions of Ruby and/or the Sketchup API?)

This has been noted many years ago. It is not likely that it will be changed now (even if a change was requested in the past.) SketchUp has moved away from X11/W3C color names for materials. In all pre-2025 versions, SketchUp came “out-of-the-box” with a “Colors-Named” collection of pre-made Material objects with these names and again only used one name variant.

However, a issue was raised with regard to the “grey” vs “gray” , because the collection uses all “gray” with an “a”.

Also, the “Colors-Named” collection did not have the “Fuchsia” (for “Magenta”) and “Aqua” (for “Cyan”) duplicates, and was also missing: “DarkViolet”, “LawnGreen”, and “LightSkyBlue”.

In addition, the collection did add:

  • “Charcoal” ( #232323 [32,32,32] )
  • “GrassGreen” ( #3E5B05 [62,91,5] )

No this is not the “easiest” way.

First of all, it is a HUGE no-no to globally “brute-force” modify Ruby core, Ruby library, Ruby gem, or SketchUp API classes or modules in a shared environment. This could affect other authors extensions in ways your cannot imagine.

Secondly, in addition to the Sketchup::Color constructor, there are eleven other API color setter methods that accept SketchUp’s subset of the X11/W3C color names. (Granted if you are not using SketchUp or LayOut 2018 or higher, the color setter methods are reduced to three.)
I doubt if the C-side implementations of these setter methods call the Ruby-side Sketchup::Color constructor method. More likely they call a C-side function directly.

What I am getting at here is that it is unlikely that overriding the class ::new method on the Ruby-side will “correct” all these setter methods.


The easiest thing to do is write yourself a wrapper method that converts color names that SketchUp does not know into color names it does know before calling the Sketchup::Color constructor method.

  def get_safe_color(name)
    safe_name = case name
    when 'DarkGrey'
      'DarkGray'
    when 'DarkSlateGrey'
      'DarkSlateGray'
    when 'DimGrey'
      'DimGray'
    when 'Grey'
      'Gray'
    when 'LightGray'
      'LightGrey'
    when 'LightSlateGrey'
      'LightSlateGray'
    when 'SlateGrey'
      'SlateGray'
    else
      name
    end # case
    Sketchup::Color.new(safe_name)
  end

Now if you absolutely wished to use materials with names as they were spelled in the SVG file, then you can call the get_safe_color() method from another method:

  def make_svg_material(name, matls = Sketchup.active_model.materials)
    matl = matls.add(name)
    matl.color= get_safe_color(name)
    # set any other material properties here
    return matl
  end

Hello Dan,

Thanks a lot for your quick feedback.
I understand from your guidance that I will need to implement a ‘workaround’. I’m OK with that.

Just a small side-remark on you comment. For the list of ‘named Sketchup colors’, I took the Sketchup Ruby API documentation as reference (cf. Class: Sketchup::Color — SketchUp Ruby API Documentation.
In this list, the color names that are ‘missing’ according to your feedback (i.e. fuchsia, aqua, darkviolet, …), are nevertheless included. They are also properly processed via my SVG Importer (I did a quick test…). So, I have no problems with these names.
The ‘added colors’ (i.e. charcoal and grassgreen) are not in the list of the Sketchup API documentation. These colors are also not included in the SVG list, so, they also don’t create problems for my Importer (direction = from SVG to Sketchup).

I therefore assume that these colors are probably only available in the ‘collection’ of materials that is provided as part of the standard Sketchup installation files? I didn’t check this…

The only problem that I encounter are those ‘grey/gray’ duplicates (in SVG) for which there is not always an identical name in Sketchup. In the Sketchup list (based on the previously mentioned documentation), they mostly use the ‘gray’ name variant. However, there is one exception to this ‘rule’, i.e. for ‘lightgrey’, where the ‘grey’ spelling is applied…

All this doesn’t really look very ‘consistent’, and is also a bit ‘confusing’, but , based on your valuable feedback, I know now how to work around this issue.

Again, many thanks!!!

FTR: I did not say they were missing from that list that the Sketchup::Color class knows. I said they were missing from the “Colors-NamedMaterials collection.

I have (obviously) and thought I was quite clear in my previous post that yes these are extra colored materials (until the 2025 release when they were retired and replaced with a new collection having “nifty” names.)

Sorry, I may have plastered you with more information then you expected.

But the discussion on materials is necessary, because the Sketchup::Color class when used in a SketchUp model, is only a property of a Sketchup::Material, so you will need to add a material for each SVG color as you import and paint the geometry. See the snippet above.