rhyton.color

Module for color operations.

class Color[source]

Bases: object

Class for basic color operations.

static HEXtoRGB(hexColor)[source]

Converts a hex color string to rgb.

Parameters

hexColor (sting) – The hex color

Returns

The rgb color

Return type

tuple

static HSVtoRGB(hsv)[source]

Convert a color from hsv to rgb.

Parameters

hsv (tuple) – A color in hsv format.

Returns

A color in rgb format

Return type

tuple

static RGBtoHEX(rgb)[source]

Convert an RGB color to HEX.

Parameters

rgb (tuple) – The RGB color.

Returns

The HEX color

Return type

str

class ColorRange(count, min=0, max=100)[source]

Bases: object

Class for working with color ranges.

__init__(count, min=0, max=100)[source]

Inits a new ColorRange instance.

Accepted values:

0 <= min < 100
1 < max <= 100
count < max - min
getHSV()[source]

Gets a list of colors in hsv format.

Returns

A list of hsv colors

Return type

list

class ColorScheme[source]

Bases: object

Class for handling relationships between labels and colors.

__init__()[source]

Inits a new ColorScheme instance.

static apply(guids, schemeName)[source]

Applies a rhyton color scheme to given objects. Updates the color scheme with new keys and colors.

Parameters
  • guids (str) – A list of Rhino objects ids

  • schemeName (string) – The name of the color scheme

Returns

Same return as rhyton.document.ElementUserText.getValues() but with key “color” added.

Return type

dict

static applyGradient(guids, schemeName, gradient)[source]

Applies a rhyton color gradient to given objects.

Parameters
  • guids (str) – A list of guids.

  • schemeName (str) – The name of the color scheme.

  • gradient (list) – Two RGB colors: [start, end]

delete(schemeName)[source]

Deletes a color scheme from the rhyton DocumenConfigStorage.

Parameters

scheme (dict) – A color scheme

static fromJSON(path)[source]

Reads a color scheme from json.

Parameters

path (string) – The json file

Returns

The color scheme

Return type

dict

generate(keys, excludeColors=None, gradient=False)[source]

Generates a new color scheme.

A color scheme has the following layout:

{
    <schemeName>: {"key1": <hexcolor>}
}
Parameters
  • schemeName (string) – The name of the color scheme

  • keys (string) – A set of keys

  • excludeColors (string, optional) – A list of colors to exclude

  • gradient (int, optional) – A tuple with start and end color

Returns

A color scheme

Return type

dict

getColors(count, excludeColors=[])[source]

Gets a given amount of colors.

Parameters
  • count (int) – The number of colors to get

  • excludeColors (string, optional) – List of colors to exclude. Defaults to None.

Returns

A list of colors

Return type

string

save(schemeName, keyValues)[source]

Saves a single color scheme to the rhyton DocumentConfigStorage.

Color schemes are stored as follows:

{
    <extensionName>.colorSchemes: {
        <schemeName1>: {"key1": "value1"},
        <schemeName2>: {"key1": "value1"}
    }
}
Parameters
  • schemeName (str) – The name of the color scheme

  • keyValues (dict) – The keys and colors associated with the name

static toJSON(data, path)[source]

Write color scheme to json

Parameters
  • data (dict) – The data to export

  • path (str) – The output file path.

Returns

The json filepath

Return type

string

update(schemeName, keys)[source]

Updates a given color scheme with new keys and default colors and saves the changes to the DocumentConfigStorage.

Parameters
  • scheme (dict) – The color scheme to update

  • keys (set) – The keys to add

Returns

The updated color scheme

Return type

dict

class Gradient[source]

Bases: object

Class for working with gradients.

classmethod betweenRgbColors(count, start, end)[source]

Create a range of colors by interpolating the individual r, g, b values.

Parameters
  • count (int) – The total amout of colors to return.

  • start (tuple) – The start color.

  • end (tuple) – The end color.