My favorites | English | Sign in

Faster apps faster - GWT 2.0 with Speed Tracer New!

Google SketchUp Ruby API

Color

class

Parent: Object

Introduction

SketchUp 6.0+

The Color class is used to create and manipulate colors within SketchUp models.

For methods that accept a Color object, such as the face.material method, you can pass in an actual Color object, or an object that can be converted to a Color. For example:

     face.material = Sketchup::Color.new(255, 0, 0)
     face.material = 255 
     face.material = 0xff
     face.material = "red" 
     face.material = "#ff0000"
     face.material = [1.0, 0.0, 0.0]
     face.material = [255, 0, 0]

SketchUp ships with several built in colors in the Materials Browser. These colors are listed in the following table.

NameRGB ValuesSwatch
AliceBlue240,248,255  
AntiqueWhite250,235,215  
Aqua0,255,255  
Aquamarine127,255,212  
Azure240,255,255  
Beige245,245,220  
Bisque255,228,196  
Black0,0,0  
BlanchedAlmond255,235,205  
Blue0,0,255  
BlueViolet138,43,226  
Brown165,42,42  
BurlyWood222,184,135  
CadetBlue95,158,160  
Chartreuse127,255,0  
Chocolate210,105,30  
Coral255,127,80  
CornflowerBlue100,149,237  
Cornsilk255,248,220  
Crimson220,20,60  
Cyan0,255,255  
DarkBlue0,0,139  
DarkCyan0,139,139  
DarkGoldenrod184,134,11  
DarkGray169,169,169  
DarkGreen0,100,0  
DarkKhaki189,183,107  
DarkMagenta139,0,139  
DarkOliveGreen85,107,47  
DarkOrange255,140,0  
DarkOrchid153,50,204  
DarkRed139,0,0  
DarkSalmon233,150,122  
DarkSeaGreen143,188,143  
DarkSlateBlue72,61,139  
DarkSlateGray47,79,79  
DarkTurquoise0,206,209  
DarkViolet148,0,211  
DeepPink255,20,147  
DeepSkyBlue0,191,255  
DimGray105,105,105  
DodgerBlue30,144,255  
FireBrick178,34,34  
FloralWhite255,250,240  
ForestGreen34,139,34  
Fuchsia255,0,255  
Gainsboro220,220,220,  
GhostWhite248,248,255  
Gold255,215,0  
Goldenrod218,165,32  
Gray128,128,128  
Green0,128,0  
GreenYellow173,255,47  
Honeydew240,255,240  
HotPink255,105,180  
IndianRed205,92,92  
Indigo75,0,130  
Ivory255,255,240  
Khaki240,230,140  
Lavender230,230,250  
LavenderBlush255,240,245  
LawnGreen124,252,0  
LemonChiffon255,250,205  
LightBlue173,216,230  
LightCoral240,128,128  
LightCyan224,255,255  
LightGoldenrodYellow250,250,210  
LightGreen144,238,144  
LightGrey211,211,211  
LightPink255,182,193  
LightSalmon255,160,122  
LightSeaGreen32,178,170  
LightSkyBlue135,206,250  
LightSlateGray119,136,153  
LightSteelBlue176,196,222  
LightYellow255,255,224  
Lime0,255,0  
LimeGreen50,205,50  
Linen250,240,230  
Magenta255,0,255  
Maroon128,0,0  
MediumAquamarine102,205,170  
MediumBlue0,0,205  
MediumOrchid186,85,211  
MediumPurple147,112,219  
MediumSeaGreen60,179,113  
MediumSlateBlue123,104,238  
MediumSpringGreen0,250,154  
MediumTurquoise72,209,204  
MediumVioletRed199,21,133  
MidnightBlue25,25,112  
MintCream245,255,250  
MistyRose255,228,225  
Moccasin255,228,181  
NavajoWhite255,222,173  
Navy0,0,128  
OldLace253,245,230  
Olive128,128,0  
OliveDrab107,142,35  
Orange255,165,0  
OrangeRed255,69,0  
Orchid218,112,214  
PaleGoldenrod238,232,170  
PaleGreen152,251,152  
PaleTurquoise175,238,238  
PaleVioletRed219,112,147  
PapayaWhip255,239,213  
PeachPuff255,218,185  
Peru205,133,63  
Pink255,192,203  
Plum221,160,221  
PowderBlue176,224,230  
Purple128,0,128  
Red255,0,0  
RosyBrown188,143,143  
RoyalBlue65,105,225  
SaddleBrown139,69,19  
Salmon250,128,114  
SandyBrown244,164,96  
SeaGreen46,139,87  
Seashell255,245,238  
Sienna160,82,45  
Silver192,192,192  
SkyBlue135,206,235  
SlateBlue106,90,205  
SlateGray112,128,144  
Snow255,250,250  
SpringGreen0,255,127  
SteelBlue70,130,180  
Tan210,180,140  
Teal0,128,128  
Thistle216,191,216  
Tomato255,99,71  
Turquoise64,224,208  
Violet238,130,238  
Wheat245,222,179  
White255,255,255  
WhiteSmoke245,245,245  
Yellow255,255,0  
YellowGreen154,205,50  

Methods

Color.alphaSketchUp 6.0+

The alpha method is used to retrieve the opacity of the color. A value of 0 is transparent, 255 is opaque.

Returns:

alpha
the opacity of the color if successful
 color = Sketchup::Color.new "OldLace"
 alpha = color.alpha 

Color.alpha=SketchUp 6.0+

The alpha= method is used to set the opacity of the color. A value of 0 is transparent, 255 is opaque.

NOTE: Though documented historically in the Ruby API, this method has never been implemented.

Arguments:

alpha
The new opacity value.

Returns:

alpha
the newly set opacity value if successful
 # NOTE: Assigning an alpha does not actually work.
 color = Sketchup::Color.new "AliceBlue"
 alpha = color.alpha = 255 

Color.blendSketchUp 6.0+

The blend method is used to blend two colors.

The blended color will be the result of taking (1 - weight) * color1 + weight * color2. If weight = 0, you will get color2. If weight = 1 you will get color1.

Arguments:

color2
The second color to be blended (with this color).
weight
A Float between 0.0 and 1.0

Returns:

color3
the newly blended Color object if successful
 color1 = Sketchup::Color.new "OldLace"
 color2 = Sketchup::Color.new "AliceBlue"
 color3 = color1.blend color2, 0.5

Color.blueSketchUp 6.0+

The blue method is used to retrieve the blue value of a color. Colors are comprised of red, green, and blue values.

Value range is 0 to 255.

Returns:

blue
the blue value for the color if successful
 color = Sketchup::Color.new "AliceBlue"
 setting = color.blue 

Color.blue=SketchUp 6.0+

The blue= method is used to set the blue value of a color. Colors are comprised of red, green, and blue values.

Value range is 0 to 255.

Arguments:

blue
The blue value for the color.

Returns:

blue
the new blue value for the color if successful
 color = Sketchup::Color.new "AliceBlue"
 setting = color.blue = 200
 if (setting)
   UI.messagebox setting
 else
   UI.messagebox "Failure"
 end

Color.greenSketchUp 6.0+

The green method is used to retrieve the green value of a color. Colors are comprised of red, green, and blue values.

Value range is 0 to 255.

Returns:

green
the green value for the color if successful
 color = Sketchup::Color.new "AliceBlue"
 setting = color.green
 if (setting)
   UI.messagebox setting
 else
   UI.messagebox "Failure"
 end

Color.green=SketchUp 6.0+

The green= method is used to set the green component of a RGB Color.

Value range is 0 to 255.

Arguments:

green
The green value for the color.

Returns:

green
the new green value for the color if successful
 color = Sketchup::Color.new "AliceBlue"
 setting = color.green = 200
 if (setting)
   UI.messagebox setting
 else
   UI.messagebox "Failure"
 end

Color.namesSketchUp 6.0+

The names method is used to retrieve an array of all color names recognized by SketchUp.

In general, whenever a method wants a color, you can pass in a String with one of these names.

Returns:

names
an array of all SketchUp color names if successful
 array = Sketchup::Color.names

Color.newSketchUp 6.0+

The new method is used to create a new Color object.

Arguments:

red
A red value.
green
A green value.
blue
A blue value.
name
The name of a color that currently exists in SketchUp. See the table at the start of this class description for more information.

Returns:

color
a Color object if successful
 color = Sketchup::Color.new "OldLace" 

Color.redSketchUp 6.0+

The red method is used to retrieve the red component of a RGB Color.

Value range is 0 to 255.

Returns:

red
the red value for the color if successful
 color = Sketchup::Color.new "AliceBlue"
 setting = color.red
 if (setting)
   UI.messagebox setting
 else
   UI.messagebox "Failure"
 end

Color.red=SketchUp 6.0+

The red= method is used to set the red component of a RGB Color.

Value range is 0 to 255.

Arguments:

red
The red value for the color.

Returns:

red
the new red value for the color if successful
 color = Sketchup::Color.new "AliceBlue"
 setting = color.red=200 

Color.to_aSketchUp 6.0+

The to_a method is used to convert a Color object to an Array object. The returned array will contain 4 integer values (RGBA) between 0 and 255.

Returns:

array
an Array object if successful
 color = Sketchup::Color.new "AliceBlue"
 color_array = color.to_a
 if (color_array)
   UI.messagebox color_array.to_s
 else
   UI.messagebox "Failure"
 end

Color.to_iSketchUp 6.0+

The to_i method is used to convert a Color object to an 32 bit integer.

Returns:

integer
a 32 bit integer if successful
 color = Sketchup::Color.new "AliceBlue"
 integer = color.to_i 

Color.to_sSketchUp 6.0+

Returns a string representation of a Color object, in the form of "Color(255, 255, 255, 255)".

Returns:

string
a String name for the Color.
 color = Sketchup::Color.new "OldLace" 
 color.to_s